Fluent Bit 是输出字段之一中的字符串的一部分?

Fluent Bit part of a string in one of the output field?

我正在使用 AWS Firelens 将日志发送到 Cloudwatch。默认情况下,Firelens 将以下这些字段与日志消息一起发送到 fluentbit 容器。

{
    "container_id": "asdfasdfasdfadsf",
    "container_name": "/ecs-microservice-ms-233-microservice-ms-e8e2e9e3b3c9e5e02100",
    "ecs_cluster": "arn:aws:ecs:us-east-1:1234:cluster/app-microservices",
    "ecs_task_arn": "arn:aws:ecs:us-east-1:1234:task/asdf",
    "ecs_task_definition": "microservice-ms:233"
}

我想在输出部分做这样的事情,

[OUTPUT]
    Name cloudwatch
    Match **
    region us-east-1
    log_group_name /ecs/${microservice}
    log_stream_prefix ${TAG}
    auto_create_group true

其中,日志组名应该是ecs服务名。但是我没有任何带有服务名称的字段。 ecs_task_definition 是最接近的,但它有任务修订号。

是否有可能实现我想要做的事情?

Fluentbit 允许我们在输出部分使用环境变量。话虽如此,问题的解决方案是将环境变量传递给 Firelens 容器。

在 AWS ECS 中,这必须从 firelens sidecar 容器定义内的任务定义部分传递,

    {
        "name": "firelens_log_router",
        "image": "<account_id>.dkr.ecr.us-east-1.amazonaws.com/accel-aws-for-fluent-bit:latest",
        "logConfiguration": {
            "logDriver": "awslogs",
            "options": {
                "awslogs-group": "firelens-container",
                "awslogs-region": "us-east-1",
                "awslogs-create-group": "true",
                "awslogs-stream-prefix": "firelens"
            }
        },
        "memory": 100,
        "memoryReservation": 50,
        "firelensConfiguration": {
            "type": "fluentbit",
            "options": {
                "config-file-type": "file",
                "config-file-value": "/fluent-bit/etc/fluent-bit-accel.conf"
            }
        },
        "environment": [
            {
                "name": "MICROSERVICE_NAME",
                "value": "${microservice_name}"
            }
        ]
    }

然后在Fluentbit配置文件的OUTPUT部分,

[OUTPUT]
    Name cloudwatch
    Match **
    region us-east-1
    log_group_name /ecs/${MICROSERVICE_NAME}
    log_stream_prefix fluentbit.
    auto_create_group true