diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6dd014b --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +# Copyright (c) 2016-2021 Martin Donath + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +# ----------------------------------------------------------------------------- +# Node, TypeScript, Python +# ----------------------------------------------------------------------------- + +# Dependencies +/node_modules +/__pycache__ +/venv +/.venv + +# Build files +/build +/MANIFEST +/site + +# Distribution files +/dist +/mkdocs_material.egg-info + +# Caches and logs +*.cpuprofile +*.log +*.tsbuildinfo +.cache +.eslintcache + +# ----------------------------------------------------------------------------- +# General +# ----------------------------------------------------------------------------- + +# Never ignore .gitkeep files +!**/.gitkeep + +# Husky hooks +.husky/.gitignore +.husky/_ + +# macOS internals +.DS_Store + +# Temporary files +TODO +tmp + +# IDEs +.vscode +.idea diff --git a/docs/developer-guide/release.md b/docs/developer-guide/release.md new file mode 100644 index 0000000..a38d973 --- /dev/null +++ b/docs/developer-guide/release.md @@ -0,0 +1,83 @@ +# 版本和Release发布流程 + +## 版本发布涉及工程 +- Loggie 主工程 +- Loggie-installation 部署脚本工程 +- Loggie docs 文档项目(暂时为最新的版本文档,后续会支持多版本) + +## 代码分支策略 +- 版本参考[Semantic语义](https://semver.org/) +- 使用main主分支为开发分支,日常所有代码PR均合入main分支 +- 新版本使用release分支,格式为`release-vA.B`,例如`release-v1.1`,这里只使用版本前两位 +- 基于release分支打上tag表示具体版本,例如`v1.1.0` +- bugfix 除了肯定会合入main分支外,根据严重情况cherry-pick至具体的release分支,同时打上tag,需要升级最小版本,例如`v1.1.1` + +## 发布新版本步骤 + +#### 1. 创建新的release分支 + +确认版本需要的所有功能已经合入,main分支为最新提交: + +``` bash +git checkout main +git pull upstream main -r +``` + +基于main分支创建新的release分支,例如`release-v1.1`: +```bash +git checkout -b release-v${A.B} +``` + +#### 2. 填写CHANGELOG +基于该分支填写CHANGELOG,提交至工程中合入 + +```bash +git add . +git commit -m'Release: add v${A.B.C} changelog' +git push upstream release-v${A.B.C} +``` + +#### 3. release Loggie-installation +release Loggie-installationation部署脚本工程,和上述1,2步骤相同 + +请注意: + +- 请勿忘记修改Chart.yaml中的版本号 + +#### 4. 回归测试 +基于release分支进行回归测试。 +release分支push至Github后,会触发action进行镜像构建,使用该镜像进行回归测试。 +这里的测试会使用loggie-installationation部署脚本里相应的release分支,同时回归验证部署脚本正确性。 +如果测试发现Bug,提交PR合入release分支,重新进行回归。 + +#### 5. 打上版本tag + +测试通过后,基于该release分支打上相应的版本tag,比如`v1.1.0` +```bash +git pull upstream release-v${A.B.C} +git tag v${A.B.C} +git push v${A.B.C} +``` +注意Loggie工程和Loggie-installationation部署脚本均需要。 + +#### 6. 在Github上发布release + +- Loggie工程复制项目中的CHANGELOG即可 +- Loggie installation工程需要提供`loggie-linux-amd64`二进制和`loggie-v${A.B.C}.tgz` helm chart包。 + - 二进制需要找台linux amd64机器进行`make build` + - helm chart包需要基于对应版本的loggie installation项目,执行`helm package ./helm-chart`即可。 + +#### 7. 更新Loggie docs文档 + +- 更新Loggie docs文档,并提PR合入 +- 注意修改Loggie镜像和版本号等 + + +#### 8. 将release分支合入main +提PR将release分支合入main,可等稳定一段时间后再合入,注意Loggie工程和Loggie-installation部署脚本均需要。 + + +## 有BugFix时 + +- 如果是不重要的bug,基于main分支提交修改即可,可以不合入release分支 +- 如果为重要的bug,需要修复,确定需要修复的版本release分支(可为最近一个或者多个),除了提交至main分支外,还需要cherry-pick至指定release分支,同时打上tag,新增最小版本号,同时需要确认Loggie-installation和docs是否同步修改。 \ No newline at end of file diff --git a/docs/getting-started/install/kubernetes.md b/docs/getting-started/install/kubernetes.md index 078a718..a736635 100644 --- a/docs/getting-started/install/kubernetes.md +++ b/docs/getting-started/install/kubernetes.md @@ -10,7 +10,7 @@ ### 下载helm-chart包 ```bash -helm pull https://github.com/loggie-io/installation/releases/download/v1.1.0/loggie-v1.1.0.tgz && tar xvzf loggie-v1.1.0.tgz +helm pull https://github.com/loggie-io/installation/releases/download/v1.2.0/loggie-v1.2.0.tgz && tar xvzf loggie-v1.2.0.tgz ``` ### 修改配置 @@ -25,7 +25,7 @@ cd installation/helm-chart #### 镜像 ```yaml -image: hub.c.163.com/loggie/loggie:v1.1.0 +image: hub.c.163.com/loggie/loggie:v1.2.0 ``` loggie的镜像。 diff --git a/docs/getting-started/install/node.md b/docs/getting-started/install/node.md index 6a66e85..de57972 100644 --- a/docs/getting-started/install/node.md +++ b/docs/getting-started/install/node.md @@ -13,7 +13,7 @@ Loggie使用Golang编译成二进制,可根据自身需求对接各类部署 ## 下载二进制 ``` -mkdir /opt/loggie && curl https://github.com/loggie-io/installation/releases/download/v1.1.0/loggie-linux-amd64 -o /opt/loggie/loggie && chmod +x /opt/loggie/loggie +mkdir /opt/loggie && curl https://github.com/loggie-io/installation/releases/download/v1.2.0/loggie-linux-amd64 -o /opt/loggie/loggie && chmod +x /opt/loggie/loggie ``` ## 添加配置文件 diff --git a/docs/getting-started/quick-start/kubernetes.md b/docs/getting-started/quick-start/kubernetes.md index b82f31e..8135131 100644 --- a/docs/getting-started/quick-start/kubernetes.md +++ b/docs/getting-started/quick-start/kubernetes.md @@ -22,7 +22,7 @@ #### 下载chart再部署 ```bash -helm pull https://github.com/loggie-io/installation/releases/download/v1.1.0/loggie-v1.1.0.tgz && tar xvzf loggie-v1.1.0.tgz +helm pull https://github.com/loggie-io/installation/releases/download/v1.2.0/loggie-v1.2.0.tgz && tar xvzf loggie-v1.2.0.tgz ``` 尝试修改一下其中的values.yaml。 @@ -40,7 +40,7 @@ helm install loggie ./loggie -nloggie --create-namespace #### 直接部署: ```bash -helm install loggie -nloggie --create-namespace https://github.com/loggie-io/installation/releases/download/v1.1.0/loggie-v1.1.0.tgz +helm install loggie -nloggie --create-namespace https://github.com/loggie-io/installation/releases/download/v1.2.0/loggie-v1.2.0.tgz ``` @@ -107,6 +107,35 @@ spec: EOF ``` +可以看到,上面使用了sinkRef引用了刚才创建的`sink default CR`。当然,我们还可以直接在Logconfig中使用sink字段,示例如下: + +```yaml +cat << EOF | kubectl apply -f - +apiVersion: loggie.io/v1beta1 +kind: LogConfig +metadata: + name: nginx + namespace: default +spec: + selector: + type: pod + labelSelector: + app: nginx + pipeline: + sources: | + - type: file + name: mylog + paths: + - stdout + sink: | + type: dev + printEvents: true + codec: + type: json + pretty: true +EOF +``` + 创建完之后,我们可以使用`kubectl get lgc`查看到创建的CRD实例。 同时,我们还可以通过`kubectl describe lgc nginx`查看LogConfig的事件,以获取最新的状态。 diff --git a/docs/getting-started/quick-start/node.md b/docs/getting-started/quick-start/node.md index 9160d65..5be0147 100644 --- a/docs/getting-started/quick-start/node.md +++ b/docs/getting-started/quick-start/node.md @@ -5,7 +5,7 @@ ### 1. 下载可执行文件 请找一台Linux服务器节点,下载Loggie二进制可执行文件 ```shell -curl -LJ https://github.com/loggie-io/installation/releases/download/v1.1.0/loggie-linux-amd64 -o loggie +curl -LJ https://github.com/loggie-io/installation/releases/download/v1.2.0/loggie-linux-amd64 -o loggie ``` ### 2. 添加配置文件 diff --git a/docs/reference/discovery/kubernetes/logconfig.md b/docs/reference/discovery/kubernetes/logconfig.md index 1776dc2..7b9f499 100644 --- a/docs/reference/discovery/kubernetes/logconfig.md +++ b/docs/reference/discovery/kubernetes/logconfig.md @@ -107,9 +107,10 @@ namespace级别CRD,表示一个日志采集任务,用于采集Pod容器日 | containerName | string | 非必填 | | 表示指定采集的容器名称,建议在Pod里包含多个容器时填写 | | excludeContainerPatterns | string数组 | 非必填 | | 排除的容器名称,使用正则表达式形式 | | matchFields | | 非必填 | | 将Pod中的信息加入到Fields中 | -| matchFields.labelKey | string数组 | 非必填 | | 指定增加的Pod上的Label Key值,比如Pod上包含Label: `app: demo`,此处填写`labelKey: app`,此时会将Pod上的`app: demo` label增加到file source fields中,采集到的日志会被加上该label信息。适用于匹配的Pod的label存在不一致的场景。 | -| matchFields.annotationKey | string数组 | 非必填 | | 和上面labelKey类似,注入的为Pod Annoatation的值 | -| matchFields.env | string数组 | 非必填 | | 和上面labelKey类似,注入的为Pod Env环境变量的值 | +| matchFields.labelKey | string数组 | 非必填 | | 指定增加的Pod上的Label Key值,比如Pod上包含Label: `app: demo`,此处填写`labelKey: app`,此时会将Pod上的`app: demo` label增加到file source fields中,采集到的日志会被加上该label信息。适用于匹配的Pod的label存在不一致的场景。支持配置为"*"的方式获取所有的label | +| matchFields.annotationKey | string数组 | 非必填 | | 和上面labelKey类似,注入的为Pod Annoatation的值,支持配置为"*"的方式获取所有的annotation | +| matchFields.env | string数组 | 非必填 | | 和上面labelKey类似,注入的为Pod Env环境变量的值,支持配置为"*"的方式获取所有的env | + !!! example diff --git a/docs/reference/global/args.md b/docs/reference/global/args.md index bd39162..055dcb7 100644 --- a/docs/reference/global/args.md +++ b/docs/reference/global/args.md @@ -14,7 +14,7 @@ ## 日志参数: - `-log.level`: 日志级别,默认为info,可配置为debug、info、warn和error -- `-log.jsonFormat`: 是否将日志输出为json格式,默认为true +- `-log.jsonFormat`: 是否将日志输出为json格式,默认为false - `-log.enableStdout`: 是否输出标准输出日志,默认为true - `-log.enableFile`: 是否输出日志文件,默认为false,即不输出日志文件,默认打印到标准输出 - `-log.directory`: 日志文件的路径,默认为/var/log,当log.enableFile=true时生效 @@ -23,6 +23,7 @@ - `-log.maxBackups`: 日志轮转最多保留的文件个数,默认为3 - `-log.maxAge`: 日志轮转最大保留的天数,默认为7 - `-log.timeFormat`: 每行日志输出的时间格式,默认格式为`2006-01-02 15:04:05` +- `-log.noColor`: 输出是否有颜色美化,默认为false,即有颜色美化,对于从标准输出查看日志比较方便。如果输出到日志文件中,建议设置为true,避免引入额外的格式。 !!! info Loggie的日志轮转使用[lumberjack](`https://github.com/natefinch/lumberjack`)库 diff --git a/docs/reference/global/discovery.md b/docs/reference/global/discovery.md index 4dd7019..c3bf52c 100644 --- a/docs/reference/global/discovery.md +++ b/docs/reference/global/discovery.md @@ -8,12 +8,13 @@ enabled: true kubernetes: cluster: aggregator - fields: - container.name: containername - logConfig: logconfig - namespace: namespace - node.name: nodename - pod.name: podname + containerRuntime: containerd + k8sFields: + logconfig: "${_k8s.logconfig}" + namespace: "${_k8s.pod.namespace}" + nodename: "${_k8s.node.name}" + podname: "${_k8s.pod.name}" + containername: "${_k8s.pod.container.name}" ``` @@ -32,14 +33,21 @@ | kubeconfig | string | 非必填 | | 指定请求Kubernetes集群API的kubeconfig文件。通常在Loggie部署到Kubernetes集群中无需填写,此时为inCluster模式。如果Loggie部署在Kubernetes集群外(例如本地调试时),需要指定该kubeconfig文件。 | | master | string | 非必填 | | 指定请求Kubernetes集群API的master地址,inCluster模式一般无需填写 | | containerRuntime | string | 非必填 | docker | 容器运行时,可选`docker`和`containerd` | -| dockerDataRoot | string | 非必填 | /var/lib/docker | docker的rootfs路径 | +| rootFsCollectionEnabled | bool | 非必填 | false | 是否开启采集root filesystem里的日志,用于不挂载日志volume的场景 | +| parseStdout | bool | 非必填 | false | 是否开启自动提取容器标准输出原始内容 | | kubeletRootDir | string | 非必填 | /var/lib/kubelet | kubelet的root路径 | | podLogDirPrefix | string | 非必填 | /var/log/pods | kubernetes默认放置的pod标准输出路径 | -| fields | map | 非必填 | | 自动添加的元信息 | -| fields.node.name | string | 非必填 | node.name | 添加所在节点node name作为元信息,同时使用该值为key | -| fields.node.ip | string | 非必填 | node.ip | 添加所在节点node ip作为元信息,同时使用该值为key | -| fields.namespace | string | 非必填 | namespace | 添加namespace作为元信息,同时使用该值为key | -| fields.pod.name | string | 非必填 | pod.name | 添加pod name作为元信息,同时使用该值为key | -| fields.pod.ip | string | 非必填 | pod.ip | 添加pod ip作为元信息,同时使用该值为key | -| fields.container.name | string | 非必填 | container.name | 添加container name作为元信息,同时使用该值为key | -| fields.logConfig | string | 非必填 | logConfig | 添加logConfig name作为元信息,同时使用该值为key | \ No newline at end of file +| k8sFields | map | 非必填 | | 自动添加的kubernetes相关元信息,key即为添加的元信息key,value请使用${_k8s.XX}的方式指定 | + + +"${_k8s.XX}"的方式可填写以下参数: + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| ${_k8s.node.name} | string | 非必填 | node.name | 添加所在节点node name作为元信息 | +| ${_k8s.node.ip} | string | 非必填 | node.ip | 添加所在节点node ip作为元信息 | +| ${_k8s.pod.namespace} | string | 非必填 | namespace | 添加namespace作为元信息 | +| ${_k8s.logconfig}| string | 非必填 | logConfig | 添加logConfig name作为元信息 | +| ${_k8s.pod.name} | string | 非必填 | pod.name | 添加pod name作为元信息 | +| ${_k8s.pod.ip} | string | 非必填 | pod.ip | 添加pod ip作为元信息 | +| ${_k8s.pod.container.name} | string | 非必填 | container.name | 添加container name作为元信息 | \ No newline at end of file diff --git a/docs/reference/monitor/sys.md b/docs/reference/monitor/sys.md new file mode 100644 index 0000000..83b7891 --- /dev/null +++ b/docs/reference/monitor/sys.md @@ -0,0 +1,35 @@ +# sys listener + +Loggie本身的CPU和Memory指标 + +## 配置 +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| period | time.Duration | 非必填 | 10s | listener消费处理数据的时间间隔 | + + +## Metrics + +#### cpu_percent + +``` +# HELP loggie_sys_cpu_percent Loggie cpu percent +# TYPE loggie_sys_cpu_percent gauge +loggie_sys_cpu_percent 0.37 +``` + +* HELP: Loggie的cpu使用率 +* TYPE: gauge + + +#### mem_rss + +``` +# HELP loggie_sys_mem_rss Loggie memory rss bytes +# TYPE loggie_sys_mem_rss gauge +loggie_sys_mem_rss 2.5853952e+07 +``` + +* HELP: Loggie的内存占用字节数 +* TYPE: gauge + diff --git a/docs/reference/pipelines/interceptor/addk8smeta.md b/docs/reference/pipelines/interceptor/addk8smeta.md index 63f84f2..e8fc14c 100644 --- a/docs/reference/pipelines/interceptor/addk8smeta.md +++ b/docs/reference/pipelines/interceptor/addk8smeta.md @@ -1,12 +1,12 @@ # addK8sMeta -用于从event中的某些字段(比如日志文件的路径中),提取到: +用于从event中的某些字段(比如日志文件的路径中),获取到: - `pod.uid` - `namespace`与`pod.name` - `container.id` -以上3种任意其一,此时Loggie可索引到具体的Pod信息,并添加`${node.name}`、`${namespace}`、`${pod.uid}`、`${pod.name}`等元信息作加入到event中,用于后续的分析处理。 +以上3种任意其一的索引信息,此时Loggie可根据该索引查询到具体的Pod,并添加额外的kubernetes`${node.name}`、`${namespace}`、`${pod.uid}`、`${pod.name}`等元信息作加入到event中,用于后续的分析处理。 属于source interceptor。 !!! example @@ -21,12 +21,6 @@ podname: "${pod.name}" ``` -## patternFields - -| `字段` | `类型` | `是否必填` | `默认值` | `含义` | -| ---------- | ----------- | ----------- | --------- | -------- | -| patternFields | string | 非必填 | 默认会从event中获取系统字段里的filename | 用于提取的字段 | - ## pattern | `字段` | `类型` | `是否必填` | `默认值` | `含义` | @@ -43,6 +37,12 @@ 比如:`/var/log/${pod.uid}/${pod.name}/` +## patternFields + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| patternFields | string | 非必填 | 默认会从event中获取系统字段里的filename,此时需要使用file source | 从event中用于提取的pattern的字段 | + ## fieldsName | `字段` | `类型` | `是否必填` | `默认值` | `含义` | @@ -57,7 +57,10 @@ 目前支持添加的元信息字段有: +- `${cluster}`:集群信息,为系统配置中`discovery.kubernetes.cluster`字段。 - `${node.name}` - `${namespace}` +- `${workload.kind}`:Deployment/StatefulSet/DaemonSet/Job等 +- `${workload.name}`:工作负载的名称 - `${pod.uid}` - `${pod.name}` \ No newline at end of file diff --git a/docs/reference/pipelines/interceptor/normalize.md b/docs/reference/pipelines/interceptor/normalize.md index 4bec300..9c1e839 100644 --- a/docs/reference/pipelines/interceptor/normalize.md +++ b/docs/reference/pipelines/interceptor/normalize.md @@ -55,6 +55,7 @@ | ---------- | ----------- | ----------- | --------- | -------- | | regex.pattern | string | 必填 | 无 | 正则解析规则 | | regex.target | string | 非必填 | body | 正则解析的目标字段 | +| regex.ignoreError | bool | 非必填 | false | 是否忽略错误 | !!! example ```yaml @@ -88,6 +89,8 @@ | `字段` | `类型` | `是否必填` | `默认值` | `含义` | | ---------- | ----------- | ----------- | --------- | -------- | | jsonDecode.target | string | 非必填 | body | json decode的目标字段 | +| jsonDecode.ignoreError | bool | 非必填 | false | 是否忽略错误 | + !!! example ```yaml @@ -107,6 +110,7 @@ | split.separator | string | 必填 | 无 | 分隔符 | | split.max | int | 非必填 | -1 | 通过分割符分割后得到的最多的字段数 | | split.keys | string数组 | 必填 | 无 | 分割后字段对应的key | +| split.ignoreError | bool | 非必填 | false | 是否忽略错误 | !!! example === "base" diff --git a/docs/reference/pipelines/sink/overview.md b/docs/reference/pipelines/sink/overview.md index 3394dcf..0957364 100644 --- a/docs/reference/pipelines/sink/overview.md +++ b/docs/reference/pipelines/sink/overview.md @@ -26,7 +26,7 @@ | `字段` | `类型` | `是否必填` | `默认值` | `含义` | | ---------- | ----------- | ----------- | --------- | -------- | | codec | | 非必填 | | sink发送数据给下游时,数据使用的格式 | -| codec.type | string | 非必填 | json | 使用json格式发送 | +| codec.type | string | 非必填 | json | codec类型 | #### type: json diff --git a/docs/reference/pipelines/sink/sls.md b/docs/reference/pipelines/sink/sls.md new file mode 100644 index 0000000..fd9bd13 --- /dev/null +++ b/docs/reference/pipelines/sink/sls.md @@ -0,0 +1,61 @@ +# sls + +sls sink用于将日志发送至阿里云SLS存储。 + +!!! example + + ```yaml + sink: + type: sls + name: demo + endpoint: cn-hangzhou.log.aliyuncs.com + accessKeyId: ${id} + accessKeySecret: ${secret} + project: test + logstore: test1 + topic: myservice + ``` + +## endpoint + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| endpoint | string | 必填 | | sls存储的访问域名 | + +你可以在具体project页面的项目概览中查看到。 + +## accessKeyId + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| accessKeyId | string | 必填 | | 访问的accessKeyId,请查看阿里云账号的访问凭证管理 | + +建议使用阿里云的子账号,子账号需要有对应project、logstore的权限。 + +## accessKeySecret + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| accessKeySecret | string | 必填 | | 访问的accessKeySecret,请查看阿里云账号的访问凭证管理 | + +## project + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| project | string | 必填 | | SLS存储的project名称 | + +## logstore + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| logstore | string | 必填 | | SLS存储的logstore名称 | + +## topic + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| topic | string | 非必填 | | 日志主题(Topic)是日志服务的基础管理单元。您可在采集日志时指定Topic,用于区分日志 | + + + + diff --git a/docs/reference/pipelines/source/overview.md b/docs/reference/pipelines/source/overview.md index 3c2a14c..52fec4a 100644 --- a/docs/reference/pipelines/source/overview.md +++ b/docs/reference/pipelines/source/overview.md @@ -108,3 +108,77 @@ sources字段为数组,一个Pipeline中可填写多个source组件配置。 } } ``` + +### codec + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| codec | | 非必填 | | source接收到数据的时候用于解析预处理 | +| codec.type | string | 非必填 | 无 | | + +请注意:目前仅`file source`支持source codec。 + +#### type: json + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| codec.bodyFields | | 必填 | | 使用解析读取到的json数据中的该字段作为`body` | + +配置示例: +!!! example "type: json" + + ```yaml + sources: + - type: file + name: nginx + paths: + - /var/log/*.log + codec: + type: json + bodyFields: log + ``` + +如果采集到的日志为: +```json +{"log":"I0610 08:29:07.698664 Waiting for caches to sync\n", "stream":"stderr", "time:"2021-06-10T08:29:07.698731204Z"} +``` +则codec后得到的event为: +``` +body: "I0610 08:29:07.698664 Waiting for caches to sync" +``` + +请注意:目前非bodyFields的字段均会被丢弃。 + + +#### type: regex + +| `字段` | `类型` | `是否必填` | `默认值` | `含义` | +| ---------- | ----------- | ----------- | --------- | -------- | +| codec.pattern | | 必填 | | 正则表达式 | +| codec.bodyFields | | 必填 | | 使用正则提取到的该字段作为`body` | + +配置示例: +!!! example "type: regex" + + ```yaml + sources: + - type: file + name: nginx + paths: + - /var/log/*.log + codec: + type: regex + pattern: ^(?P