We have configured Fluent-bit to send the logs from our cluster directly to CloudWatch. We have enabled the Kube.netes filter in order to set our log_stream_name as $(kube.netes['container_name']).
However, the logs are terrible.
Each CloudWatch line looks like this:
2022-06-23T14:17:34.879+02:00 {"kubernetes":{"redacted_redacted":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25","redacted_image":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted:ve3b56a45","redacted_name":"redacted-redacted","docker_id":"b431f9788f46sd5f4ds65f4sd56f4sd65f4d336fff4ca8030a216ecb9e0a","host":"ip-0.0.0.0.region-#.compute.internal","namespace_name":"namespace","pod_id":"podpodpod-296c-podpod-8954-podpodpod","pod_name":"redacted-redacted-redacted-7dcbfd4969-mb5f5"},
2022-06-23T14:17:34.879+02:00 {"kubernetes":{"redacted_redacted":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25","redacted_image":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted:ve3b56a45","redacted_name":"redacted-redacted","docker_id":"b431f9788f46sd5f4ds65f4sd56f4sd65f4d336fff4ca8030a216ecb9e0a","host":"ip-0.0.0.0.region-#.compute.internal","namespace_name":"namespace","pod_id":"podpodpod-296c-podpod-8954-podpodpod","pod_name":"redacted-redacted-redacted-7dcbfd4969-mb5f5"},
2022-06-23T14:17:34.879+02:00 {"kubernetes":{"redacted_redacted":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25","redacted_image":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted:ve3b56a45","redacted_name":"redacted-redacted","docker_id":"b431f9788f46sd5f4ds65f4sd56f4sd65f4d336fff4ca8030a216ecb9e0a","host":"ip-0.0.0.0.region-#.compute.internal","namespace_name":"namespace","pod_id":"podpodpod-296c-podpod-8954-podpodpod","pod_name":"redacted-redacted-redacted-7dcbfd4969-mb5f5"},
2022-06-23T14:20:07.074+02:00 {"kubernetes":{"redacted_redacted":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25","redacted_image":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted:ve3b56a45","redacted_name":"redacted-redacted","docker_id":"b431f9788f46sd5f4ds65f4sd56f4sd65f4d336fff4ca8030a216ecb9e0a","host":"ip-0.0.0.0.region-#.compute.internal","namespace_name":"namespace","pod_id":"podpodpod-296c-podpod-8954-podpodpod","pod_name":"redacted-redacted-redacted-7dcbfd4969-mb5f5"},
Which makes the logs unusable unless expanded, and once expanded the logs look like this:
2022-06-23T14:21:34.207+02:00
{
"kubernetes": {
"container_hash": "145236632541.lfl.ecr.region.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25",
"container_image": "145236632541.lfl.ecr.region-#.amazonaws.com/redacted:ve3b56a45",
"container_name": "redacted-redacted",
"docker_id": "b431f9788f46sd5f4ds65f4sd56f4sd65f4d336fff4ca8030a216ecb9e0a",
"host": "ip-0.0.0.0.region-#.compute.internal",
"namespace_name": "redacted",
"pod_id": "podpodpod-296c-podpod-8954-podpodpod",
"pod_name": "redacted-redacted-redacted-7dcbfd4969-mb5f5"
},
"log": "[23/06/2022 12:21:34] loglineloglinelogline\ loglineloglinelogline \n",
"stream": "stdout"
}
{"kubernetes":{"redacted_redacted":"145236632541.lfl.ecr.region-#.amazonaws.com/redacted@sha256:59392fab7hsfghsfghsfghsfghsfghsfghc39c1bee75c0b4bfc2d9f4a405aef449b25","redacted_image
Which is also a bit horrible because every line is flooded with Kube.netes data. I would like to remove the Kube.netes data from the logs completely, But I would like to keep using $(kube.netes['container_name']) as the log stream name so that the logs are properly named. I have tried using filters with Remove_key and LUA scripts that would remove the Kube.netes data. But as soon as something removes it, the log stream cannot be named $(kube.netes['container_name']).
I have found very little documentation on this. And have not found a proper way to remove Kube.netes data and to keep my log_stream_name as my container_name.
Here is the raw with the fluent bit config that I used: https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/fluent-bit/fluent-bit-compatible.yaml
Any help would be appreciated.
There is an instruction https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-logs-FluentBit.html / (Optional) Reducing the log volume from Fluent Bit
Just adding nest filter in the log config. Eg
user-api.conf: |
[INPUT]
Name tail
Tag user-api.*
Path /var/log/containers/user-api*.log
Docker_Mode On
Docker_Mode_Flush 5
Docker_Mode_Parser container_firstline_user
Parser docker
DB /var/fluent-bit/state/flb_user_api.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
storage.type filesystem
Read_from_Head ${READ_FROM_HEAD}
[FILTER]
Name kubernetes
Match user-api.*
Kube_URL https://kubernetes.default.svc:443
Kube_Tag_Prefix user-api.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
K8S-Logging.Parser On
K8S-Logging.Exclude Off
Labels Off
Annotations Off
[FILTER]
Name grep
Match user-api.*
Exclude log /.*"GET \/ping HTTP\/1.1" 200.*/
[FILTER]
Name nest
Match user-api.*
Operation lift
Nested_under kubernetes
Add_prefix Kube.
[FILTER]
Name modify
Match user-api.*
Remove kubernetes.kubernetes.host
Remove Kube.container_hash
Remove Kube.container_image
Remove Kube.container_name
Remove Kube.docker_id
Remove Kube.host
Remove Kube.pod_id
[FILTER]
Name nest
Match user-api.*
Operation nest
Wildcard Kube.*
Nested_under kubernetes
Remove_prefix Kube.
[OUTPUT]
Name cloudwatch_logs
Match user-api.*
region ${AWS_REGION}
log_group_name /aws/containerinsights/${CLUSTER_NAME}/user-api
log_stream_prefix app-
auto_create_group true
extra_user_agent container-insights
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.