amazon-cloudwatch-logs-for-fluent-bit icon indicating copy to clipboard operation
amazon-cloudwatch-logs-for-fluent-bit copied to clipboard

Log group and log name templating support in `cloudwatch_logs`

Open aerlaut opened this issue 3 years ago • 4 comments

Hi,

The documentation mentions that log group and log name templating support is not yet implemented in the new plugin (cloudwatch_logs): https://github.com/aws/amazon-cloudwatch-logs-for-fluent-bit#do-you-plan-to-deprecate-this-older-plugin

However, this merged PR implemented that feature: https://github.com/fluent/fluent-bit/pull/5633

So is the templating feature available in the new plugin?

I tried using the new plugin for creating custom log groups to for EKS Fargate logs, but doesn't seem to work and had to fallback to the old cloudwatch plugin.

aerlaut avatar Sep 28 '22 06:09 aerlaut

I tried to use the log_stream_template in the cloudwatch_logs plugin. Here is my config

[OUTPUT]
    Name cloudwatch_logs
    Match nginx-firelens*
    region ${AWS_DEFAULT_REGION}
    log_group_name ${LOG_GROUP_NAME}
    log_stream_name nginx-firelens-json
    log_stream_template nginx-firelens-$(ecs_task_id)
    auto_create_group On

And have been getting this error,

[2022/10/14 10:42:00] [ warn] [record accessor] translation failed, root key=ecs_task_id

This means the templating parameter is working, but it's not able to find the value of ecs_task_id in my case 👎🏽

nikhilo avatar Oct 14 '22 10:10 nikhilo

The docs for the cloudwatch_logs support are here: https://docs.fluentbit.io/manual/pipeline/outputs/cloudwatch#log-stream-and-group-name-templating-using-record_accessor-syntax

The feature is still a templating feature but it BOTH uses different syntax and also is not exactly the same feature. I can not inject ECS Metadata unlike the go plugin templating feature. To get metadata in your logs, there is this env var feature: https://github.com/aws/aws-for-fluent-bit/blob/mainline/use_cases/init-process-for-fluent-bit/README.md#how-init-process-works

PettitWesley avatar Oct 18 '22 22:10 PettitWesley

I got templating to work with cloudwatch_logs (at least with $ecs_task_id). See https://github.com/aws/amazon-cloudwatch-logs-for-fluent-bit/issues/289#issuecomment-1289595810

ojacques avatar Oct 24 '22 20:10 ojacques

@PettitWesley I was able to use the image with "init" script and use the ECS_TASK_ID env variable.

nikhilo avatar Oct 31 '22 12:10 nikhilo