Skip to content

Commit

Permalink
[FA] Add config version tag in metric (#33068)
Browse files Browse the repository at this point in the history
Co-authored-by: AlexandreYang <alexandre.yang@datadoghq.com>
  • Loading branch information
coignetp and AlexandreYang authored Feb 1, 2025
1 parent dcd0631 commit bb3d594
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type BufferedAggregator struct {
serializer serializer.MetricSerializer
eventPlatformForwarder eventplatform.Component
haAgent haagent.Component
configID string
hostname string
hostnameUpdate chan string
hostnameUpdateDone chan struct{} // signals that the hostname update is finished
Expand Down Expand Up @@ -307,6 +308,9 @@ func NewBufferedAggregator(s serializer.MetricSerializer, eventPlatformForwarder
})
}

// configID can only change on agent restart, and will only change if the configuration applied by Fleet Automation changes
configID := pkgconfigsetup.Datadog().GetString("config_id")

tagsStore := tags.NewStore(pkgconfigsetup.Datadog().GetBool("aggregator_use_tags_store"), "aggregator")

aggregator := &BufferedAggregator{
Expand All @@ -328,6 +332,7 @@ func NewBufferedAggregator(s serializer.MetricSerializer, eventPlatformForwarder
serializer: s,
eventPlatformForwarder: eventPlatformForwarder,
haAgent: haAgent,
configID: configID,
hostname: hostname,
hostnameUpdate: make(chan string),
hostnameUpdateDone: make(chan struct{}),
Expand Down Expand Up @@ -875,6 +880,9 @@ func (agg *BufferedAggregator) tags(withVersion bool) []string {
if version.AgentPackageVersion != "" {
tags = append(tags, "package_version:"+version.AgentPackageVersion)
}
if agg.configID != "" {
tags = append(tags, "config_id:"+agg.configID)
}
}
if agg.haAgent.Enabled() {
tags = append(tags, "ha_agent_enabled:true")
Expand Down
12 changes: 12 additions & 0 deletions pkg/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ func TestTags(t *testing.T) {
globalTags func(types.TagCardinality) ([]string, error)
withVersion bool
haAgentEnabled bool
configID string
want []string
}{
{
Expand Down Expand Up @@ -655,11 +656,22 @@ func TestTags(t *testing.T) {
haAgentEnabled: true,
want: []string{"ha_agent_enabled:true"},
},
{
name: "tags enabled, with version, with config id",
hostname: "hostname",
tlmContainerTagsEnabled: true,
agentTags: func(types.TagCardinality) ([]string, error) { return []string{"container_name:agent"}, nil },
globalTags: func(types.TagCardinality) ([]string, error) { return []string{"kube_cluster_name:foo"}, nil },
withVersion: true,
configID: "config123",
want: []string{"container_name:agent", "version:" + version.AgentVersion, "kube_cluster_name:foo", "config_id:config123"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockConfig := configmock.New(t)
mockConfig.SetWithoutSource("basic_telemetry_add_container_tags", tt.tlmContainerTagsEnabled)
mockConfig.SetWithoutSource("config_id", tt.configID)

taggerComponent := taggerMock.SetupFakeTagger(t)

Expand Down
1 change: 1 addition & 0 deletions pkg/config/setup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ func fleet(config pkgconfigmodel.Setup) {
// Directory to store fleet policies
config.BindEnv("fleet_policies_dir")
config.SetDefault("fleet_layers", []string{})
config.BindEnvAndSetDefault("config_id", "")
}

func autoscaling(config pkgconfigmodel.Setup) {
Expand Down

0 comments on commit bb3d594

Please sign in to comment.