1

我已经根据这个文档创建了 ECS 集群

我正在使用 CloudFormation 模板:

    AWSTemplateFormatVersion: "2010-09-09"
    Resources:
      # ...
      TaskDefinition:
        Type: AWS::ECS::TaskDefinition
        Properties:
          Family: !Sub "${Application}-${Env}"
          ExecutionRoleArn:
            Fn::ImportValue:
              !Sub "${Env}-TaskExecutionRole"
          Cpu: 256
          Memory: 256
          ContainerDefinitions:
            - Name: nextjs
              Image: nextjs
              DependsOn:
                - containerName: log_router
                  condition: START
              Essential: true
              LogConfiguration:
                LogDriver: awsfirelens
                Options:
                  Name: loki
                  Url: "http://loki.xxx.com/loki/api/v1/push"
                  Labels: "{job=\"firelens\"}"
                  RemoveKeys: "container_id,ecs_task_arn"
                  LabelKeys: "container_name,ecs_task_definition,source,ecs_cluster"
                  LineFormat: key_value
              Links:
                - log_router
            - Name: nginx
              Image: nginx
              DependsOn:
                - containerName: nextjs
                  condition: START
              Essential: true
              PortMappings:
                - ContainerPort: 80
              LogConfiguration:
                LogDriver: awsfirelens
                Options:
                  Name: loki
                  Url: "http://loki.xxx.com/loki/api/v1/push"
                  Labels: "{job=\"firelens\"}"
                  RemoveKeys: "container_id,ecs_task_arn"
                  LabelKeys: "container_name,ecs_task_definition,source,ecs_cluster"
                  LineFormat: key_value
              Links:
                - nextjs
                - log_router
            - Name: log_router
              Image: grafana/fluent-bit-plugin-loki:latest
              Essential: true
              FirelensConfiguration:
                Type: fluentbit
                Options:
                  enable-ecs-log-metadata: true
              LogConfiguration:
                LogDriver: awslogs
                Options:
                  awslogs-group: firelens-container
                  awslogs-region: us-east-1
                  awslogs-create-group: true
                  awslogs-stream-prefix: firelens
              memoryReservation: 50

所有三个容器都已启动并正在运行,但我在 CloudWatch 中收到以下错误消息:

无法加载输出插件“loki”

截图(对不起,当我将它添加为图像时它失败了):https ://imgur.com/qnE0Cjd

Grafana Loki 是空的

错误在哪里?它可能与DependsOn或有关Links吗?

4

1 回答 1

1

为同样的问题而苦苦挣扎。事实证明,文档是错误的。该插件的名称是“grafana-loki”,而不仅仅是文档中所述的“loki”。也许这改变了一段时间,文档已经过时了。

"logConfiguration": {
    "logDriver": "awsfirelens",
    "options": {
        "Name": "grafana-loki",
        "Url": "https://[...]/loki/api/v1/push",
        "Labels": "{job=\"firelens\"}",
        "RemoveKeys": "container_id,ecs_task_arn",
        "LabelKeys": "container_name,ecs_task_definition,source,ecs_cluster",
        "LineFormat": "key_value"
    }
},
于 2021-02-25T15:59:39.217 回答