Skip to content

Commit

Permalink
[pkg/util/cloudproviders/gce] Add host tag for DD_PROVIDER_KIND (Da…
Browse files Browse the repository at this point in the history
  • Loading branch information
jennchenn authored Nov 25, 2024
1 parent 84c20fb commit b65ed90
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/config/setup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ func InitConfig(config pkgconfigmodel.Setup) {
config.SetKnown("cluster_name")
config.SetKnown("listeners")

config.BindEnv("provider_kind")

// Orchestrator Explorer DCA and core agent
config.BindEnvAndSetDefault("orchestrator_explorer.enabled", true)
// enabling/disabling the environment variables & command scrubbing from the container specs
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/cloudproviders/gce/gce_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func GetTags(ctx context.Context) ([]string, error) {
}
}

if providerKind := pkgconfigsetup.Datadog().GetString("provider_kind"); providerKind != "" {
tags = append(tags, fmt.Sprintf("provider_kind:%s", providerKind))
}

// save tags to the cache in case we exceed quotas later
cache.Cache.Set(tagsCacheKey, tags, cache.NoExpiration)

Expand Down
18 changes: 18 additions & 0 deletions pkg/util/cloudproviders/gce/gce_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
"google-compute-enable-pcid:true",
"instance-template:projects/111111111111/global/instanceTemplates/gke-test-cluster-default-pool-0012834b",
}
expectedTagsWithProviderKind = append(expectedFullTags, "provider_kind:test-provider")
)

func mockMetadataRequest(t *testing.T) *httptest.Server {
Expand Down Expand Up @@ -146,3 +147,20 @@ func TestGetHostTagsWithNonDefaultTagFilters(t *testing.T) {
require.NoError(t, err)
testTags(t, tags, expectedExcludedTags)
}

func TestGetHostTagsWithProviderKind(t *testing.T) {
ctx := context.Background()
mockConfig := configmock.New(t)
defaultProviderKind := mockConfig.GetString("provider_kind")
defer mockConfig.SetWithoutSource("provider_kind", defaultProviderKind)

mockConfig.SetWithoutSource("provider_kind", "test-provider")

server := mockMetadataRequest(t)
defer server.Close()
defer cache.Cache.Delete(tagsCacheKey)

tags, err := GetTags(ctx)
require.NoError(t, err)
testTags(t, tags, expectedTagsWithProviderKind)
}
11 changes: 11 additions & 0 deletions releasenotes/notes/add-provider-kind-tag-518f76ee283bc1ff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
enhancements:
- |
Add new host tag `provider_kind` from the value of `DD_PROVIDER_KIND` for Agents running in GCE.

0 comments on commit b65ed90

Please sign in to comment.