Skip to content

Commit

Permalink
fix: set the kube_cluster_name tag via event summary if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mrparkers committed Aug 3, 2023
1 parent f4a0b6f commit c7a70ae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/notifier/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,20 @@ func (d *DataDog) toDataDogTags(event *eventv1.Event) []string {
// "env" is a standard tag for datadog and usually matches the cluster name: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes
fmt.Sprintf("env:%s", d.env),
// Note: DataDog standardizes kubernetes tags as "kube_*": https://github.com/DataDog/datadog-agent/blob/82dc933aa86de037c70fe960384aa06a62e457a8/pkg/collector/corechecks/cluster/kubernetesapiserver/events_common.go#L48
fmt.Sprintf("kube_cluster_name:%s", d.env),
fmt.Sprintf("kube_kind:%s", event.InvolvedObject.Kind),
fmt.Sprintf("kube_name:%s", event.InvolvedObject.Name),
fmt.Sprintf("kube_namespace:%s", event.InvolvedObject.Namespace),
}

// set the cluster name to the value of the summary field if it exists
// otherwise, set it to the value of the channel
if v, ok := event.Metadata["summary"]; ok {
tags = append(tags, fmt.Sprintf("kube_cluster_name:%s", v))
delete(event.Metadata, "summary")
} else {
tags = append(tags, fmt.Sprintf("kube_cluster_name:%s", d.env))
}

// add extra tags from event metadata
for k, v := range event.Metadata {
tags = append(tags, fmt.Sprintf("%s:%s", k, v))
Expand Down

0 comments on commit c7a70ae

Please sign in to comment.