From f845ef113f7973e1491ed80100746741a10ae0fd Mon Sep 17 00:00:00 2001 From: berg <13611129507@163.com> Date: Fri, 21 Feb 2020 18:00:59 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=97=A5=E5=BF=97=E9=87=87=E9=9B=86?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=90=8C=E6=97=B6=E9=87=87=E9=9B=86?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=A4=9A=E7=A7=8D=E7=B1=BB=E5=9E=8B=E6=97=A5?= =?UTF-8?q?=E5=BF=97=20#372?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bcs-logbeat-sidecar/sidecar/controller.go | 51 +++++++++++-------- .../template/unifytlogc-template.conf | 32 +++++------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/bcs-services/bcs-logbeat-sidecar/sidecar/controller.go b/bcs-services/bcs-logbeat-sidecar/sidecar/controller.go index 0fd32213d5..aab10f8d76 100644 --- a/bcs-services/bcs-logbeat-sidecar/sidecar/controller.go +++ b/bcs-services/bcs-logbeat-sidecar/sidecar/controller.go @@ -30,18 +30,18 @@ import ( const ( //report data id - EnvLogInfoDataid = "io_tencent_bcs_app_dataid" + EnvLogInfoDataid = "io_tencent_bcs_app_dataid_v2" //if true, then stdout; else custom logs file - EnvLogInfoStdout = "io_tencent_bcs_app_stdout" + EnvLogInfoStdout = "io_tencent_bcs_app_stdout_v2" //if stdout=false, log file path - EnvLogInfoLogPath = "io_tencent_bcs_app_logpath" + EnvLogInfoLogPath = "io_tencent_bcs_app_logpath_v2" //clusterid - EnvLogInfoLogCluster = "io_tencent_bcs_app_cluster" + EnvLogInfoLogCluster = "io_tencent_bcs_app_cluster_v2" //namespace - EnvLogInfoLogNamepsace = "io_tencent_bcs_app_namespcae" + EnvLogInfoLogNamepsace = "io_tencent_bcs_app_namespcae_v2" //custom labels, log tags //example: kv1:val1,kv2:val2,kv3:val3... - EnvLogInfoLogLabel = "io_tencent_bcs_app_label" + EnvLogInfoLogLabel = "io_tencent_bcs_app_label_v2" //application or deployment't name EnvLogInfoLogServerName = "io_tencent_bcs_controller_name" //enum: Application、Deployment... @@ -232,8 +232,8 @@ func produceLogConfParameter(container *docker.Container) (*LogConfParameter, bo continue } - label := fmt.Sprintf(`, - "%s": "%s"`, kvs[0], kvs[1]) + label := fmt.Sprintf(` + %s: %s`, kvs[0], kvs[1]) para.CustemLabel += label } } @@ -246,19 +246,30 @@ func produceLogConfParameter(container *docker.Container) (*LogConfParameter, bo return nil, false } - //if nonstandard log - if !para.stdout { - if para.nonstandardLog == "" { - blog.Warnf("container %s don't contain %s env", EnvLogInfoLogPath) - return nil, false - } else { - para.LogFile = para.nonstandardLog + files := make([]string,0) + //if stdout container log + if para.stdout { + files = append(files, container.LogPath) + } + //if nonstandard Log + if para.nonstandardLog!="" { + array := strings.Split(para.nonstandardLog, ",") + for _,f :=range array { + files = append(files, fmt.Sprintf("/proc/%d/root%s",container.State.Pid,f)) } - //else standard log - } else { - para.LogFile = container.LogPath } - + //if len(files)==0, then invalid + if len(files)==0 { + blog.Warnf("container %s env(%s, %s) is invalid", + container.ID, EnvLogInfoStdout, EnvLogInfoLogPath) + return nil, false + } + para.LogFile += files[0] + for _,f :=range files[1:] { + filelog := fmt.Sprintf(` + %s`, f) + para.LogFile += filelog + } para.ContainerId = container.ID return para, true } @@ -274,7 +285,7 @@ func (s *SidecarController) produceContainerLogConf(c *docker.Container) { logConf := &ContainerLogConf{ containerId: c.ID, - confPath: fmt.Sprintf("%s/%s-%s.conf", s.conf.LogbeatDir, s.prefixFile, []byte(c.ID)[:12]), + confPath: fmt.Sprintf("%s/%s-%s.yaml", s.conf.LogbeatDir, s.prefixFile, []byte(c.ID)[:12]), } para, ok := produceLogConfParameter(c) if !ok { diff --git a/bcs-services/bcs-logbeat-sidecar/template/unifytlogc-template.conf b/bcs-services/bcs-logbeat-sidecar/template/unifytlogc-template.conf index 31afeb7094..8d65b4ccaa 100644 --- a/bcs-services/bcs-logbeat-sidecar/template/unifytlogc-template.conf +++ b/bcs-services/bcs-logbeat-sidecar/template/unifytlogc-template.conf @@ -1,20 +1,12 @@ -{ - "tlogcfg": [ - { - "file": "{{.LogFile}}", - "dataid": {{.DataId}}, - "private": [ - { - "container_id": "{{.ContainerId}}", - "io.tencent.bcs.cluster": "{{.ClusterId}}", - "io.tencent.bcs.namespace": "{{.Namespace}}", - "io.tencent.bcs.server_name": "{{.ServerName}}", - "io.tencent.bcs.type": "{{.ServerType}}"{{.CustemLabel}} - } - ], - "field_sep": "|", - "fileds": [], - "beJson": 1 - } - ] -} \ No newline at end of file +local: + - + dataid: {{.DataId}} + paths: + - {{.LogFile}} + to_json: true + ext_meta: + container_id: {{.ContainerId}} + io.tencent.bcs.cluster: {{.ClusterId}} + io.tencent.bcs.namespace: {{.Namespace}} + io.tencent.bcs.server_name: {{.ServerName}} + io.tencent.bcs.type: {{.ServerType}}{{.CustemLabel}} \ No newline at end of file