Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitlab/functional_test/regression_detector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ single_machine_performance-regression_detector-merge_base_check:
--comparison-sha ${CI_COMMIT_SHA} \
--target-config-dir test/regression/ \
--submission-metadata submission_metadata \
--replicas 20 \
--tags ${SMP_TAGS} || {
exit_code=$?
echo "smp job submit command failed with code $exit_code"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package utils

import (
"fmt"

"github.com/DataDog/datadog-agent/comp/core/autodiscovery/common/types"
"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
"github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers/names"
Expand All @@ -26,7 +28,7 @@ const (
// ConfigsForService returns the openmetrics configurations for a given service if it matches the AD configuration
func ConfigsForService(pc *types.PrometheusCheck, svc *v1.Service) []integration.Config {
var configs []integration.Config
namespacedName := svc.GetNamespace() + "/" + svc.GetName()
namespacedName := fmt.Sprintf("%s/%s", svc.GetNamespace(), svc.GetName())

// Ignore headless services because we can't resolve the IP.
// Ref: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services
Expand Down Expand Up @@ -56,7 +58,7 @@ func ConfigsForService(pc *types.PrometheusCheck, svc *v1.Service) []integration
// configuration for related service
func ConfigsForServiceEndpoints(pc *types.PrometheusCheck, svc *v1.Service, ep *v1.Endpoints) []integration.Config {
var configs []integration.Config
namespacedName := svc.GetNamespace() + "/" + svc.GetName()
namespacedName := fmt.Sprintf("%s/%s", svc.GetNamespace(), svc.GetName())
instances, found := buildInstances(pc, svc.GetAnnotations(), namespacedName)
if found {
for _, subset := range ep.Subsets {
Expand Down
2 changes: 1 addition & 1 deletion comp/core/autodiscovery/common/utils/prometheus_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// ConfigsForPod returns the openmetrics configurations for a given pod if it matches the AD configuration
func ConfigsForPod(pc *types.PrometheusCheck, pod *workloadmeta.KubernetesPod, wmeta workloadmeta.Component) ([]integration.Config, error) {
var configs []integration.Config
namespacedName := pod.Namespace + "/" + pod.Name
namespacedName := fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)
if pc.IsExcluded(pod.Annotations, namespacedName) {
return nil, nil
}
Expand Down
7 changes: 4 additions & 3 deletions comp/core/autodiscovery/listeners/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package listeners

import (
"fmt"
"hash/fnv"
"maps"
"strconv"
Expand All @@ -30,18 +31,18 @@ const (

// getStandardTags extract standard tags from labels of kubernetes services
func getStandardTags(labels map[string]string) []string {
tags := []string{}
if labels == nil {
return []string{}
return tags
}
labelToTagKeys := map[string]string{
kubernetes.EnvTagLabelKey: tagKeyEnv,
kubernetes.VersionTagLabelKey: tagKeyVersion,
kubernetes.ServiceTagLabelKey: tagKeyService,
}
tags := make([]string, 0, len(labelToTagKeys))
for labelKey, tagKey := range labelToTagKeys {
if tagValue, found := labels[labelKey]; found {
tags = append(tags, tagKey+":"+tagValue)
tags = append(tags, fmt.Sprintf("%s:%s", tagKey, tagValue))
}
}
return tags
Expand Down
8 changes: 4 additions & 4 deletions comp/core/tagger/collectors/workloadmeta_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (c *WorkloadMetaCollector) handleContainer(ev workloadmeta.Event) []*types.

if container.Runtime == workloadmeta.ContainerRuntimeDocker {
if image.Tag != "" {
tagList.AddLow(tags.DockerImage, image.Name+":"+image.Tag)
tagList.AddLow(tags.DockerImage, fmt.Sprintf("%s:%s", image.Name, image.Tag))
} else {
tagList.AddLow(tags.DockerImage, image.Name)
}
Expand Down Expand Up @@ -840,9 +840,9 @@ func (c *WorkloadMetaCollector) extractTagsFromPodContainer(pod *workloadmeta.Ku
tagList.AddHigh(tags.ContainerID, container.ID)

if container.Name != "" && pod.Name != "" {
tagList.AddHigh(tags.DisplayContainerName, container.Name+"_"+pod.Name)
tagList.AddHigh(tags.DisplayContainerName, fmt.Sprintf("%s_%s", container.Name, pod.Name))
} else if podContainer.Name != "" && pod.Name != "" {
tagList.AddHigh(tags.DisplayContainerName, podContainer.Name+"_"+pod.Name)
tagList.AddHigh(tags.DisplayContainerName, fmt.Sprintf("%s_%s", podContainer.Name, pod.Name))
}

image := podContainer.Image
Expand Down Expand Up @@ -977,7 +977,7 @@ func (c *WorkloadMetaCollector) addOpenTelemetryStandardTags(container *workload
}

func buildTaggerSource(entityID workloadmeta.EntityID) string {
return workloadmetaCollectorName + "-" + string(entityID.Kind)
return fmt.Sprintf("%s-%s", workloadmetaCollectorName, string(entityID.Kind))
}

func parseJSONValue(value string, tags *taglist.TagList) error {
Expand Down
5 changes: 3 additions & 2 deletions comp/core/tagger/taglist/taglist.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package taglist

import (
"fmt"
"maps"
"strings"
"unique"
Expand Down Expand Up @@ -45,13 +46,13 @@ func addTags(target map[string]bool, name string, value string, splits map[strin
// common for tags like "kube_namespace", "pod_phase", "env",
// "kube_qos", etc. Using the unique package helps optimize memory usage
// in such cases.
key := unique.Make(name + ":" + value)
key := unique.Make(fmt.Sprintf("%s:%s", name, value))
target[key.Value()] = true
return
}

for _, elt := range strings.Split(value, sep) {
key := unique.Make(name + ":" + elt)
key := unique.Make(fmt.Sprintf("%s:%s", name, elt))
target[key.Value()] = true
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/clusteragent/admission/common/lib_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func (lc LibConfig) ToEnvs() []corev1.EnvVar {
})
}
if lc.TracingServiceMapping != nil {
pairs := make([]string, len(lc.TracingServiceMapping))
for i, m := range lc.TracingServiceMapping {
pairs[i] = m.FromKey + ":" + m.ToName
pairs := make([]string, 0, len(lc.TracingServiceMapping))
for _, m := range lc.TracingServiceMapping {
pairs = append(pairs, fmt.Sprintf("%s:%s", m.FromKey, m.ToName))
}
envs = append(envs, corev1.EnvVar{
Name: "DD_TRACE_SERVICE_MAPPING",
Expand All @@ -129,9 +129,9 @@ func (lc LibConfig) ToEnvs() []corev1.EnvVar {
})
}
if lc.TracingHeaderTags != nil {
pairs := make([]string, len(lc.TracingHeaderTags))
for i, m := range lc.TracingHeaderTags {
pairs[i] = m.Header + ":" + m.TagName
pairs := make([]string, 0, len(lc.TracingHeaderTags))
for _, m := range lc.TracingHeaderTags {
pairs = append(pairs, fmt.Sprintf("%s:%s", m.Header, m.TagName))
}
envs = append(envs, corev1.EnvVar{
Name: "DD_TRACE_HEADER_TAGS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *Controller) enqueueOnLeaderNotif(stop <-chan struct{}) {

// triggerReconciliation forces a reconciliation loop by enqueuing the secret object namespaced name.
func (c *Controller) triggerReconciliation() {
c.queue.Add(c.config.GetNs() + "/" + c.config.GetName())
c.queue.Add(fmt.Sprintf("%s/%s", c.config.GetNs(), c.config.GetName()))
}

// handleObject enqueues the targeted Secret object when an event occurs.
Expand Down
3 changes: 2 additions & 1 deletion pkg/clusteragent/admission/controllers/webhook/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package webhook

import (
"fmt"
"strings"

"github.com/DataDog/datadog-agent/comp/core/config"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (w *Config) getTimeout() int32 { return w.timeout }
func (w *Config) getFailurePolicy() string { return w.failurePolicy }
func (w *Config) getReinvocationPolicy() string { return w.reinvocationPolicy }
func (w *Config) configName(suffix string) string {
name := strings.ReplaceAll(w.webhookName+"."+suffix, "-", ".")
name := strings.ReplaceAll(fmt.Sprintf("%s.%s", w.webhookName, suffix), "-", ".")
name = strings.ReplaceAll(name, "_", ".")
return name
}
2 changes: 1 addition & 1 deletion pkg/clusteragent/admission/mutate/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func PodString(pod *corev1.Pod) string {
if pod.GetNamespace() == "" || pod.GetName() == "" {
return "with generate name " + pod.GetGenerateName()
}
return pod.GetNamespace() + "/" + pod.GetName()
return fmt.Sprintf("%s/%s", pod.GetNamespace(), pod.GetName())
}

// containsVolumeMount returns whether a list of volume mounts contains
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusteragent/admission/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetStatus(apiCl kubernetes.Interface) map[string]interface{} {
webhookName := pkgconfigsetup.Datadog().GetString("admission_controller.webhook_name")
secretName := pkgconfigsetup.Datadog().GetString("admission_controller.certificate.secret_name")
status["WebhookName"] = webhookName
status["SecretName"] = ns + "/" + secretName
status["SecretName"] = fmt.Sprintf("%s/%s", ns, secretName)

validatingWebhookStatus, err := getValidatingWebhookStatus(webhookName, apiCl)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ func generateDatadogEvent(request *admission.Request, webhookName string) (event

// Add labels to the tags.
for key, value := range newResource.GetLabels() {
tags = append(tags, key+":"+value)
tags = append(tags, fmt.Sprintf("%s:%s", key, value))
}
for key, value := range oldResource.GetLabels() {
tags = append(tags, key+":"+value)
tags = append(tags, fmt.Sprintf("%s:%s", key, value))
}

return event.Event{
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusteragent/appsec/envoygateway/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type envoyGatewayInjectionPattern struct {

func (e *envoyGatewayInjectionPattern) IsInjectionPossible(ctx context.Context) error {
gvrToName := func(gvr schema.GroupVersionResource) string {
return gvr.Resource + "." + gvr.Group
return fmt.Sprintf("%s.%s", gvr.Resource, gvr.Group)
}

// Check if the EnvoyExtensionPolicy CRD is present
Expand Down
4 changes: 2 additions & 2 deletions pkg/clusteragent/appsec/istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type istioInjectionPattern struct {

func (i *istioInjectionPattern) IsInjectionPossible(ctx context.Context) error {
gvrToName := func(gvr schema.GroupVersionResource) string {
return gvr.Resource + "." + gvr.Group
return fmt.Sprintf("%s.%s", gvr.Resource, gvr.Group)
}

// Check if the EnvoyFilter CRD is present
Expand Down Expand Up @@ -191,7 +191,7 @@ func (i *istioInjectionPattern) createEnvoyFilter(ctx context.Context, namespace

func (i *istioInjectionPattern) newFilter(namespace string) istiov1alpha3.EnvoyFilter {
const clusterName = "datadog_appsec_ext_proc_cluster"
processorAddress := i.config.Processor.ServiceName + "." + i.config.Processor.Namespace + ".svc"
processorAddress := fmt.Sprintf("%s.%s.svc", i.config.Processor.ServiceName, i.config.Processor.Namespace)

httpFilterPatch, err := i.buildHTTPFilterPatch(clusterName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/clusteragent/autoscaling/externalmetrics/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func buildDatadogQueryForExternalMetric(metricName string, labels map[string]str
if len(labels) == 0 {
result = metricName + "{*}"
} else {
datadogTags := make([]string, 0, len(labels))
datadogTags := []string{}
for key, val := range labels {
datadogTags = append(datadogTags, key+":"+val)
datadogTags = append(datadogTags, fmt.Sprintf("%s:%s", key, val))
}
sort.Strings(datadogTags)
tags := strings.Join(datadogTags, ",")
result = metricName + "{" + tags + "}"
result = fmt.Sprintf("%s{%s}", metricName, tags)
}

return fmt.Sprintf("%s:%s.rollup(%d)", queryConfigAggregator, result, queryConfigRollup)
Expand Down
3 changes: 2 additions & 1 deletion pkg/clusteragent/clusterchecks/dispatcher_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package clusterchecks

import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ func newDispatcher(tagger tagger.Component) *dispatcher {
clusterTagName := pkgconfigsetup.Datadog().GetString("cluster_checks.cluster_tag_name")
if clusterTagValue != "" {
if clusterTagName != "" && !pkgconfigsetup.Datadog().GetBool("disable_cluster_name_tag_key") {
d.extraTags = append(d.extraTags, clusterTagName+":"+clusterTagValue)
d.extraTags = append(d.extraTags, fmt.Sprintf("%s:%s", clusterTagName, clusterTagValue))
log.Info("Adding both tags cluster_name and kube_cluster_name. You can use 'disable_cluster_name_tag_key' in the Agent config to keep the kube_cluster_name tag only")
}
d.extraTags = append(d.extraTags, tags.KubeClusterName+":"+clusterTagValue)
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusteragent/languagedetection/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (lp *languagePatcher) processOwner(ctx context.Context, owner langUtil.Name
}

func (lp *languagePatcher) handleDeployment(ctx context.Context, owner langUtil.NamespacedOwnerReference) error {
deploymentID := owner.Namespace + "/" + owner.Name
deploymentID := fmt.Sprintf("%s/%s", owner.Namespace, owner.Name)

// get the complete entity
deployment, err := lp.store.GetKubernetesDeployment(deploymentID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/corechecks/cluster/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (hc *HelmCheck) tagsForMetricsAndEvents(release *release, includeRevision b
log.Tracef("Value for %s specified in helm_values_as_tags not found", helmValue)
continue
}
tags = append(tags, tagName+":"+value)
tags = append(tags, fmt.Sprintf("%s:%s", tagName, value))
}

return tags
Expand All @@ -266,7 +266,7 @@ func (hc *HelmCheck) tagsForMetricsAndEvents(release *release, includeRevision b
func commonTags(release *release, storageDriver helmStorage) []string {
tags := []string{
"helm_release:" + release.Name,
"helm_storage:" + string(storageDriver),
fmt.Sprintf("helm_storage:%s", storageDriver),
"kube_namespace:" + release.Namespace,

// "helm_namespace" is just an alias for "kube_namespace".
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/cluster/helm/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type namespacedName string
type revision int

func (rel *release) namespacedName() namespacedName {
return namespacedName(rel.Namespace + "/" + rel.Name)
return namespacedName(fmt.Sprintf("%s/%s", rel.Namespace, rel.Name))
}

func (rel *release) revision() revision {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func getInvolvedObjectTags(involvedObject v1.ObjectReference, taggerInstance tag
case podKind:
entityID = types.NewEntityID(types.KubernetesPodUID, string(involvedObject.UID))
case deploymentKind:
entityID = types.NewEntityID(types.KubernetesDeployment, involvedObject.Namespace+"/"+involvedObject.Name)
entityID = types.NewEntityID(types.KubernetesDeployment, fmt.Sprintf("%s/%s", involvedObject.Namespace, involvedObject.Name))
default:
apiGroup := apiserver.GetAPIGroup(involvedObject.APIVersion)
resourceType, err := apiserver.GetResourceType(involvedObject.Kind, apiGroup)
Expand Down Expand Up @@ -395,7 +395,7 @@ func getKindTag(kind, name string) string {
return ""
}

return tagName + ":" + name
return fmt.Sprintf("%s:%s", tagName, name)
}

func buildReadableKey(obj v1.ObjectReference) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestFormatEvent(t *testing.T) {
SourceTypeName: "kubernetes",
EventType: CheckName,
Ts: timestamp,
Host: nodeName + "-" + clusterName,
Host: fmt.Sprintf("%s-%s", nodeName, clusterName),
Tags: []string{
"kube_namespace:default",
"kube_kind:Pod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *unbundledTransformer) Transform(events []*v1.Event) ([]event.Event, []e
collectedByDefault := false
if c.filteringEnabled {
if !shouldCollectByDefault(ev) {
source = source + "_" + customEventSourceSuffix
source = fmt.Sprintf("%s_%s", source, customEventSourceSuffix)
} else {
collectedByDefault = true
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/collector/corechecks/containers/containerd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ func (c *ContainerdCheck) computeEvents(events []containerdEvent, sender sender.
continue
}

tags := make([]string, 0, len(e.Extra))
for k, v := range e.Extra {
tags = append(tags, k+":"+v)
var tags []string
if len(e.Extra) > 0 {
for k, v := range e.Extra {
tags = append(tags, fmt.Sprintf("%s:%s", k, v))
}
}

alertType := event.AlertTypeInfo
Expand Down
6 changes: 3 additions & 3 deletions pkg/collector/corechecks/containers/kubelet/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *PodUtils) computePodTagsByPVC(pod *workloadmeta.KubernetesPod) {
return
}

filteredTags := make([]string, 0, len(tags))
var filteredTags []string
for t := range tags {
omitTag := false
for i := range volumeTagKeysToExclude {
Expand All @@ -112,7 +112,7 @@ func (p *PodUtils) computePodTagsByPVC(pod *workloadmeta.KubernetesPod) {
if v.PersistentVolumeClaim != nil {
pvcName := v.PersistentVolumeClaim.ClaimName
if pvcName != "" {
p.podTagsByPVC[pod.Namespace+"/"+pvcName] = filteredTags
p.podTagsByPVC[fmt.Sprintf("%s/%s", pod.Namespace, pvcName)] = filteredTags
}
}

Expand All @@ -130,7 +130,7 @@ func (p *PodUtils) computePodTagsByPVC(pod *workloadmeta.KubernetesPod) {

// GetPodTagsByPVC returns the computed pod tags for a PVC with a given name in a given namespace.
func (p *PodUtils) GetPodTagsByPVC(namespace, pvcName string) []string {
return p.podTagsByPVC[namespace+"/"+pvcName]
return p.podTagsByPVC[fmt.Sprintf("%s/%s", namespace, pvcName)]
}

// IsStaticPendingPod returns whether the pod with the given UID is a static pending pod or not, or returns false
Expand Down
Loading
Loading