我们遇到了类似的问题,解决方案分为两部分:
- 在 Fluent-bit 配置文件中添加 Kubernetes 过滤器
- 更正我们的 API/微服务的 json 日志记录
虽然您的问题看起来与 json 格式相关,特别是针对message
field (见下面第2点)
1. 在 Fluent-bit 配置文件中添加 Kubernetes 过滤器
## https://docs.fluentbit.io/manual/pipeline/filters
filters: |
[FILTER]
Name kubernetes
Match kube.*
Merge_Log On
Merge_Log_Key log_processed
Keep_Log Off
K8S-Logging.Parser On
K8S-Logging.Exclude On
现在,这会将 json 输出拆分为新字段:
-
log
=“{原始字典作为字符串}”
-
log_processed.level
=“信息”
-
log_processed.message
= etc.
2. 更正 API 中的 json 日志记录
它看起来像message
json 中的字段输出为String
, not a json
object.
即你有:
{
"level": "info",
"message": "\"{\"method:\" GET , \"url:\" / , \"status:\" 404 , \"responseTime:\" 0.545 ms , \"responseContentLength:\" 39}\"\n",
"timestamp": "2022-04-01T12:48:37.091Z"
}
但你可能想要这个:
{
"level": "info",
"message": {
"method": "GET",
"url": "/",
"status": "404",
"responseTime": "0.545 ms",
"responseContentLength": 39
},
"timestamp": "2022-04-01T12:48:37.091Z"
}
请注意,我在这里假设的数据类型只是为了演示该问题。
一些相关阅读/链接:
- https://docs. Fluentbit.io/manual/installation/kubernetes#log-files-overview https://docs.fluentbit.io/manual/installation/kubernetes#log-files-overview
- https://docs. Fluentbit.io/manual/concepts/data-pipeline/filter https://docs.fluentbit.io/manual/concepts/data-pipeline/filter
- Helm 图表配置 -https://github.com/ Fluent/helm-charts/blob/main/charts/ Fluent-bit/values.yaml https://github.com/fluent/helm-charts/blob/main/charts/fluent-bit/values.yaml