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

Resolving cloudwatch endpoint for all regions #4191

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1854,32 +1854,31 @@ func (engine *DockerTaskEngine) createContainer(task *apitask.Task, container *a
}
}

// This is a short term solution only for specific regions until AWS SDK Go is upgraded to V2
// We're currently relying on AWS SDK Go V1 to obtain/format the correct cloudwatch endpoint.
// This is will need to be updated once we upgrade to AWS SDK Go V2.
if hostConfig.LogConfig.Type == logDriverTypeAwslogs {
region := engine.cfg.AWSRegion
if region == "eu-isoe-west-1" || region == "us-isof-south-1" || region == "us-isof-east-1" {
endpoint := ""
dnsSuffix := ""
partition, ok := ep.PartitionForRegion(ep.DefaultPartitions(), region)
if !ok {
logger.Warn("No partition resolved for region. Using AWS default", logger.Fields{
"region": region,
"defaultDNSSuffix": ep.AwsPartition().DNSSuffix(),
})
dnsSuffix = ep.AwsPartition().DNSSuffix()
region := hostConfig.LogConfig.Config["awslogs-region"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would hostConfig.LogConfig.Config["awslogs-region"] ever be empty or null? If yes, should fallback to use region := engine.cfg.AWSRegion before moving to line 1863?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIght so awslogs-region shouldn't be empty/null ever. If a customer were to omit this option from the task definition then it would be considered invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original thought process was to also default to engine.cfg.AWSRegion but after testing manually I couldn't find a scenario where this is not aparent from the task payload. Although I'm open to have this as a safety net or maybe fail the task.

endpoint := ""
dnsSuffix := ""
partition, ok := ep.PartitionForRegion(ep.DefaultPartitions(), region)
if !ok {
logger.Warn("No partition resolved for region. Using AWS default", logger.Fields{
"region": region,
"defaultDNSSuffix": ep.AwsPartition().DNSSuffix(),
})
dnsSuffix = ep.AwsPartition().DNSSuffix()
} else {
resolvedEndpoint, err := partition.EndpointFor("logs", region)
if err == nil {
endpoint = resolvedEndpoint.URL
} else {
resolvedEndpoint, err := partition.EndpointFor("logs", region)
if err == nil {
endpoint = resolvedEndpoint.URL
} else {
dnsSuffix = partition.DNSSuffix()
}
dnsSuffix = partition.DNSSuffix()
}
if endpoint == "" {
endpoint = fmt.Sprintf("https://logs.%s.%s", region, dnsSuffix)
}
hostConfig.LogConfig.Config["awslogs-endpoint"] = endpoint
}
if endpoint == "" {
endpoint = fmt.Sprintf("https://logs.%s.%s", region, dnsSuffix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO: Just asking to learn, is this the default format of the endpoint if its not found in partition.EndpointFor? Does this mean it's a special type of region/not-opt in region?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work in Non-Commercial regions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is typically the format for all service endpoints. We're adding this in the case that AWS SDK Go V1 can't resolve it on it's own (i.e. the information for a new region aren't present).

https://docs.aws.amazon.com/general/latest/gr/rande.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work in Non-Commercial regions?

As in isolated regions? If so then yes they do. This is more of a follow up to #4143.

}
hostConfig.LogConfig.Config["awslogs-endpoint"] = endpoint
}

//Apply the log driver secret into container's LogConfig and Env secrets to container.Environment
Expand Down
18 changes: 15 additions & 3 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2877,7 +2877,17 @@ func TestCreateContainerAwslogsLogDriver(t *testing.T) {
{
name: "test container that uses awslogs log driver in IAD",
region: "us-east-1",
expectedLogConfigEndpoint: "",
expectedLogConfigEndpoint: "https://logs.us-east-1.amazonaws.com",
},
{
name: "test container that uses awslogs log driver in BJS",
region: "cn-north-1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: cn-north-1 and us-gov-east-1 are both available/published in https://github.com/aws/aws-sdk-go-v2, so we should be ok to use them in our test cases.

expectedLogConfigEndpoint: "https://logs.cn-north-1.amazonaws.com.cn",
},
{
name: "test container that uses awslogs log driver in OSU",
region: "us-gov-east-1",
expectedLogConfigEndpoint: "https://logs.us-gov-east-1.amazonaws.com",
},
{
name: "test container that uses awslogs log driver in NCL",
Expand Down Expand Up @@ -2906,8 +2916,10 @@ func TestCreateContainerAwslogsLogDriver(t *testing.T) {

rawHostConfigInput := dockercontainer.HostConfig{
LogConfig: dockercontainer.LogConfig{
Type: "awslogs",
Config: map[string]string{},
Type: "awslogs",
Config: map[string]string{
"awslogs-region": tc.region,
},
},
}
rawHostConfig, err := json.Marshal(&rawHostConfigInput)
Expand Down
Loading