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

Add namespaced azure container app tags to spans and profiles #30637

Merged
Merged
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
19 changes: 12 additions & 7 deletions cmd/serverless-init/cloudservice/containerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,29 @@ func (c *ContainerApp) GetTags() map[string]string {
replica := os.Getenv(ContainerAppReplicaName)

tags := map[string]string{
"app_name": appName,
"region": region,
"revision": revision,
"replica_name": replica,
"origin": c.GetOrigin(),
"_dd.origin": c.GetOrigin(),
"app_name": appName,
"region": region,
"revision": revision,
"replica_name": replica,
"aca.replica.name": replica,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want all of these new aca tags to be shown in the flame graph UI? If not it might be nice to prefix them with either _dd or just _ (this also causes them to be skipped for some types of obfuscation which can be nice)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even though this change was motivated by billing I do think that these are helpful tags to have available for customers to use to filter to spans related to a specific resource/subscription/replica.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, although it may be a bit confusing (and inefficient) to have duplicates here, is there a plan to deprecate and remove the "old" names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good point because I agree it is messy having these duplicate tags. I chatted with my team internally and there is not a plan to deprecate them at this time since we want to avoid any breaking changes for customers using the "old" tags. That's not to say we will never deprecate them but there would need to be more reasons to warrant a new major version than just removing these duplicate tags.

"origin": c.GetOrigin(),
"_dd.origin": c.GetOrigin(),
}

if c.SubscriptionId != "" {
tags["subscription_id"] = c.SubscriptionId
tags["aca.subscription.id"] = c.SubscriptionId
}

if c.ResourceGroup != "" {
tags["resource_group"] = c.ResourceGroup
tags["aca.resource.group"] = c.ResourceGroup
}

if c.SubscriptionId != "" && c.ResourceGroup != "" {
tags["resource_id"] = fmt.Sprintf("/subscriptions/%v/resourcegroups/%v/providers/microsoft.app/containerapps/%v", c.SubscriptionId, c.ResourceGroup, strings.ToLower(appName))
resourceID := fmt.Sprintf("/subscriptions/%v/resourcegroups/%v/providers/microsoft.app/containerapps/%v", c.SubscriptionId, c.ResourceGroup, strings.ToLower(appName))
tags["resource_id"] = resourceID
tags["aca.resource.id"] = resourceID
}

return tags
Expand Down
35 changes: 20 additions & 15 deletions cmd/serverless-init/cloudservice/containerapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ func TestGetContainerAppTags(t *testing.T) {
tags := service.GetTags()

assert.Equal(t, map[string]string{
"app_name": "test_app_name",
"origin": "containerapp",
"region": "eastus",
"revision": "test_revision",
"replica_name": "test--6nyz8z7-b845f7667-m7hlv",
"_dd.origin": "containerapp",
"app_name": "test_app_name",
"origin": "containerapp",
"region": "eastus",
"revision": "test_revision",
"replica_name": "test--6nyz8z7-b845f7667-m7hlv",
"aca.replica.name": "test--6nyz8z7-b845f7667-m7hlv",
"_dd.origin": "containerapp",
}, tags)
}

Expand All @@ -53,15 +54,19 @@ func TestGetContainerAppTagsWithOptionalEnvVars(t *testing.T) {
tags := service.GetTags()

assert.Equal(t, map[string]string{
"app_name": "test_app_name",
"origin": "containerapp",
"region": "eastus",
"revision": "test_revision",
"replica_name": "test--6nyz8z7-b845f7667-m7hlv",
"_dd.origin": "containerapp",
"subscription_id": "test_subscription_id",
"resource_id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name",
"resource_group": "test_resource_group",
"app_name": "test_app_name",
"origin": "containerapp",
"region": "eastus",
"revision": "test_revision",
"replica_name": "test--6nyz8z7-b845f7667-m7hlv",
"aca.replica.name": "test--6nyz8z7-b845f7667-m7hlv",
"_dd.origin": "containerapp",
"subscription_id": "test_subscription_id",
"aca.subscription.id": "test_subscription_id",
"resource_id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name",
"aca.resource.id": "/subscriptions/test_subscription_id/resourcegroups/test_resource_group/providers/microsoft.app/containerapps/test_app_name",
"resource_group": "test_resource_group",
"aca.resource.group": "test_resource_group",
}, tags)

assert.Nil(t, err)
Expand Down
24 changes: 15 additions & 9 deletions pkg/trace/api/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ const (
profilingV1EndpointSuffix = "v1/input"
)

var azureContainerAppTags = []string{
"subscription_id",
"resource_group",
"resource_id",
"replicate_name",
"aca.subscription.id",
"aca.resource.group",
"aca.resource.id",
"aca.replica.name",
}

// profilingEndpoints returns the profiling intake urls and their corresponding
// api keys based on agent configuration. The main endpoint is always returned as
// the first element in the slice.
Expand Down Expand Up @@ -87,15 +98,10 @@ func (r *HTTPReceiver) profileProxyHandler() http.Handler {
tags.WriteString("_dd.origin:lambda")
}

// Azure Container App metadata
if subscriptionID, ok := r.conf.GlobalTags["subscription_id"]; ok {
tags.WriteString(fmt.Sprintf(",subscription_id:%s", subscriptionID))
}
if resourceGroup, ok := r.conf.GlobalTags["resource_group"]; ok {
tags.WriteString(fmt.Sprintf(",resource_group:%s", resourceGroup))
}
if resourceID, ok := r.conf.GlobalTags["resource_id"]; ok {
tags.WriteString(fmt.Sprintf(",resource_id:%s", resourceID))
for _, azureContainerAppTag := range azureContainerAppTags {
if value, ok := r.conf.GlobalTags[azureContainerAppTag]; ok {
tags.WriteString(fmt.Sprintf(",%s:%s", azureContainerAppTag, value))
}
}

return newProfileProxy(r.conf, targets, keys, tags.String(), r.statsd)
Expand Down
12 changes: 8 additions & 4 deletions pkg/trace/api/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestProfileProxyHandler(t *testing.T) {
kv := strings.Split(tag, ":")
m[kv[0]] = kv[1]
}
for _, tag := range []string{"subscription_id", "resource_group", "resource_id"} {
for _, tag := range []string{"subscription_id", "resource_group", "resource_id", "aca.subscription.id", "aca.resource.group", "aca.resource.id", "aca.replica.name"} {
if _, ok := m[tag]; !ok {
t.Fatalf("invalid X-Datadog-Additional-Tags header, should contain '%s': %q", tag, v)
}
Expand All @@ -324,9 +324,13 @@ func TestProfileProxyHandler(t *testing.T) {
conf := newTestReceiverConfig()
conf.ProfilingProxy = config.ProfilingProxyConfig{DDURL: srv.URL}
conf.GlobalTags = map[string]string{
"subscription_id": "123",
"resource_group": "test-rg",
"resource_id": "456",
"subscription_id": "123",
"resource_group": "test-rg",
"resource_id": "456",
"aca.subscription.id": "123",
"aca.resource.group": "test-rg",
"aca.resource.id": "456",
"aca.replica.name": "test-replica",
}
req, err := http.NewRequest("POST", "/some/path", nil)
if err != nil {
Expand Down
Loading