-
Notifications
You must be signed in to change notification settings - Fork 11
[CONTP-1014] feat: Add UST docker labels to all container definitions #48
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
Merged
+169
−22
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1646017
feat: add ust docker labels
Mathew-Estafanous c996652
test: add ust docker label tests
Mathew-Estafanous 3e319c3
chore: terraform fmt
Mathew-Estafanous 28d5d98
feat: expose docker label config for datadog agent
Mathew-Estafanous 54f4a30
chore: add docs and fix variable def
Mathew-Estafanous 55ed512
fix: update test assertion
Mathew-Estafanous 1419f73
chore: update example
Mathew-Estafanous 6ee0a3b
chore: remove ust tagging for agent container
Mathew-Estafanous c3e0bf7
chore: terraform fmt
Mathew-Estafanous 7c5af11
chore: remove ust env from cws container
Mathew-Estafanous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the Apache License Version 2.0. | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| # Copyright 2025-present Datadog, Inc. | ||
|
|
||
| ################################################################################ | ||
| # Task Definition: UST Docker Labels Test | ||
| ################################################################################ | ||
|
|
||
| module "dd_task_ust_docker_labels" { | ||
| source = "../../modules/ecs_fargate" | ||
|
|
||
| # Configure Datadog with UST tags | ||
| dd_api_key = var.dd_api_key | ||
| dd_site = var.dd_site | ||
| dd_service = "ust-test-service" | ||
| dd_env = "ust-test-env" | ||
| dd_version = "1.2.3" | ||
| dd_tags = "team:test" | ||
| dd_essential = true | ||
|
|
||
| dd_is_datadog_dependency_enabled = true | ||
|
|
||
| dd_log_collection = { | ||
| enabled = true, | ||
| } | ||
|
|
||
| dd_cws = { | ||
| enabled = true, | ||
| } | ||
|
|
||
| dd_docker_labels = { | ||
| "com.datadoghq.tags.service" : "docker-agent-service", | ||
| "com.datadoghq.tags.env" : "agent-dev", | ||
| "com.datadoghq.tags.version" : "v1.2.3" | ||
| } | ||
|
|
||
| # Configure Task Definition with multiple containers | ||
| family = "${var.test_prefix}-ust-docker-labels" | ||
| container_definitions = jsonencode([ | ||
| { | ||
| name = "dummy-app", | ||
| image = "nginx:latest", | ||
| essential = true, | ||
| }, | ||
| ]) | ||
|
|
||
| requires_compatibilities = ["FARGATE"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2025-present Datadog, Inc. | ||
|
|
||
| package test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "log" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/service/ecs/types" | ||
| "github.com/gruntwork-io/terratest/modules/terraform" | ||
| ) | ||
|
|
||
| // TestUSTDockerLabels tests that UST docker labels are propagated to all container definitions | ||
| // when dd_service, dd_env, and dd_version are set | ||
| func (s *ECSFargateSuite) TestUSTDockerLabels() { | ||
| log.Println("TestUSTDockerLabels: Running test...") | ||
|
|
||
| // Retrieve the task output for the "ust-docker-labels" module | ||
| var containers []types.ContainerDefinition | ||
| task := terraform.OutputMap(s.T(), s.terraformOptions, "ust-docker-labels") | ||
| s.Equal(s.testPrefix+"-ust-docker-labels", task["family"], "Unexpected task family name") | ||
|
|
||
| err := json.Unmarshal([]byte(task["container_definitions"]), &containers) | ||
| s.NoError(err, "Failed to parse container definitions") | ||
| s.Equal(4, len(containers), "Expected 4 containers in the task definition (1 app container + 3 agent sidecar)") | ||
|
|
||
| // Expected UST docker labels that should be present on all application containers | ||
| expectedUSTLabels := map[string]string{ | ||
| "com.datadoghq.tags.service": "ust-test-service", | ||
| "com.datadoghq.tags.env": "ust-test-env", | ||
| "com.datadoghq.tags.version": "1.2.3", | ||
| } | ||
|
|
||
| dummyApp, found := GetContainer(containers, "dummy-app") | ||
| s.True(found, "Container dummy-app not found in definitions") | ||
| AssertDockerLabels(s.T(), dummyApp, expectedUSTLabels) | ||
|
|
||
| // Expect UST docker labels to be present on all Datadog containers with | ||
| // overwritten labels when UST docker labels are specified. | ||
| datadogContainers := []string{"datadog-agent", "datadog-log-router", "cws-instrumentation-init"} | ||
| expectedAgentUSTLabels := map[string]string{ | ||
| "com.datadoghq.tags.service": "docker-agent-service", | ||
| "com.datadoghq.tags.env": "agent-dev", | ||
| "com.datadoghq.tags.version": "v1.2.3", | ||
| } | ||
| for _, containerName := range datadogContainers { | ||
| container, found := GetContainer(containers, containerName) | ||
| s.True(found, "Container %s not found in definitions", containerName) | ||
| AssertDockerLabels(s.T(), container, expectedAgentUSTLabels) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other application container configured options like environment variables, mount points, and container dependencies give more precedence to the values defined by the Datadog Terraform module.
I think we should be fine to maintain that level of precedence here and assume that if a user defined the UST values for env, service, and version then those values would take precedence as well.
terraform-aws-ecs-datadog/modules/ecs_fargate/variables.tf
Lines 117 to 133 in 1419f73
We can leave a bugfix note in the changelog for the next release to notify users that the UST tagging has been fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understandable. I guess if they wanted unique UST values, then they shouldn't set the global env,service,and version. They should then manually set it per container definition.
I initially wanted to prioritize the user's docker labels over ours because the customer's problem description implied the need for different UST values.