Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifically set the CW endpoint when using awslogs as log driver for specifc regions #4143

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

mye956
Copy link
Contributor

@mye956 mye956 commented Apr 18, 2024

Summary

This PR will provide a short term workaround regarding issues with using awslogs as the log driver type for new/specific regions. Essentially, the Docker version that ECS Agent is using is unable to resolve the correct Cloudwatch endpoint on its own for new regions which should be done via the AWS SDK Go package. This was fixed/support for new regions were added in AWS SDK Go V2 which will need a docker upgrade in order to so. As a short term solution, we'll explicitly set these endpoints as the awslogs-endpoint log option when invoking docker to run the task containers for the new regions until a long term solution is available.

Here's an example of the errors we're encountering

Error response from daemon: failed to create task for container: failed to initialize logging driver: failed to create Cloudwatch 
log stream: operation error CloudWatch Logs: CreateLogStream, exceeded maximum number of attempts, 3, https response 
error StatusCode: 0, RequestID: , request send failed, Post \"https://logs.eu-isoe-west-1.amazonaws.com/\": dial tcp: lookup 
logs.eu-isoe-west-1.amazonaws.com on 172.31.0.2:53: no such host

Implementation details

  • Now checking if the log driver type is of awslogs during createContainer whenever we're in the new regions. Then set the awslogs-endpoint as one of the hostConfig.LogConfig.Config that we're passing into docker.
    • We'll rely on the resolving the correct endpoints via the endpoints directory in AWS SDK Go [V1].
    • Here's also a list of known CW endpoints for commercial regions as reference

Testing

  • Implemented new unit tests that are defined in TestCreateContainerAwslogsLogDriver
  • Manual testing

Launched a new task in one of the new regions with the following definition:

{
    "family": "test",
    "containerDefinitions": [{
        "memory": 64,
        "cpu": 256,
        "name": "awslogs-test",
        "image": "busybox",
        "command": ["sh", "-c", "echo hello world"],
        "logConfiguration":{
            "logDriver": "awslogs",
            "options": {
                "awslogs-group": "cw-test",
                "awslogs-region": "eu-isoe-west-1",
                "awslogs-stream-prefix":"cw-test"
            }
        }
    }]
}

Outcome:

[ec2-user@ip-172-31-26-139 ~]$ docker ps -a
CONTAINER ID   IMAGE                            COMMAND                  CREATED             STATUS                         PORTS     NAMES
32d41a82cdc6   busybox                          "sh -c 'echo hello w…"   10 seconds ago      Exited (0) 8 seconds ago                 ecs-test-1-awslogs-test-90f088edf6b8a99d5e00

Manually executing docker run (in PDX):

[ec2-user@ip-172-31-44-187 ~]$ docker run --log-driver=awslogs --log-opt awslogs-region=us-west-2 --log-opt awslogs-group=cw-test --log-opt awslogs-endpoint=https://logs.us-west-2.amazonaws.com  busybox:latest
[ec2-user@ip-172-31-44-187 ~]$ docker ps -a
CONTAINER ID   IMAGE                            COMMAND    CREATED          STATUS                      PORTS     NAMES
f097a73a3413   busybox:latest                   "sh"       3 seconds ago    Exited (0) 2 seconds ago              lucid_yalow

New tests cover the changes: Yes

Description for the changelog

Explicitly pass in awslogs-endpoint for new regions as a short term workaround

Does this PR include breaking model changes? If so, Have you added transformation functions?

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mye956 mye956 requested a review from a team as a code owner April 18, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants