diff --git a/comp/core/autodiscovery/listeners/service.go b/comp/core/autodiscovery/listeners/service.go index 841af2456caa8..f0b4e7448c0e4 100644 --- a/comp/core/autodiscovery/listeners/service.go +++ b/comp/core/autodiscovery/listeners/service.go @@ -89,7 +89,7 @@ func (s *service) GetPorts(_ context.Context) ([]ContainerPort, error) { // GetTags returns the tags associated with the service. func (s *service) GetTags() ([]string, error) { - return tagger.Tag(taggercommon.BuildTaggerEntityID(s.entity.GetID()).String(), tagger.ChecksCardinality()) + return tagger.Tag(taggercommon.BuildTaggerEntityID(s.entity.GetID()), tagger.ChecksCardinality()) } // GetPid returns the process ID of the service. diff --git a/comp/otelcol/otlp/collector.go b/comp/otelcol/otlp/collector.go index 2ce66bf173972..6207e329a100a 100644 --- a/comp/otelcol/otlp/collector.go +++ b/comp/otelcol/otlp/collector.go @@ -70,7 +70,7 @@ func (t *tagEnricher) Enrich(_ context.Context, extraTags []string, dimensions * enrichedTags = append(enrichedTags, extraTags...) enrichedTags = append(enrichedTags, dimensions.Tags()...) - entityTags, err := tagger.Tag(dimensions.OriginID(), t.cardinality) + entityTags, err := tagger.LegacyTag(dimensions.OriginID(), t.cardinality) if err != nil { log.Tracef("Cannot get tags for entity %s: %s", dimensions.OriginID(), err) } else { diff --git a/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients.go b/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients.go index 297e4f724f3b3..cd6e1cb7de8a9 100644 --- a/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients.go +++ b/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients.go @@ -11,7 +11,7 @@ import "github.com/DataDog/datadog-agent/comp/core/tagger/types" // see comp/core/tagger for tagger functions; client for tagger interface type taggerClient interface { // Tag is an interface function that queries taggerclient singleton - Tag(entity string, cardinality types.TagCardinality) ([]string, error) + Tag(entity types.EntityID, cardinality types.TagCardinality) ([]string, error) // GlobalTags is an interface function that queries taggerclient singleton GlobalTags(cardinality types.TagCardinality) ([]string, error) } diff --git a/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients_test.go b/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients_test.go index 989623475184a..3069eec0acd56 100644 --- a/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients_test.go +++ b/comp/otelcol/otlp/components/processor/infraattributesprocessor/helperclients_test.go @@ -24,8 +24,8 @@ func newTestTaggerClient() *testTaggerClient { } // Tag mocks taggerimpl.Tag functionality for the purpose of testing, removing dependency on Taggerimpl -func (t *testTaggerClient) Tag(entityID string, _ types.TagCardinality) ([]string, error) { - return t.tagMap[entityID], nil +func (t *testTaggerClient) Tag(entityID types.EntityID, _ types.TagCardinality) ([]string, error) { + return t.tagMap[entityID.String()], nil } // GlobalTags mocks taggerimpl.GlobalTags functionality for purpose of testing, removing dependency on Taggerimpl diff --git a/comp/otelcol/otlp/components/processor/infraattributesprocessor/logs.go b/comp/otelcol/otlp/components/processor/infraattributesprocessor/logs.go index 8d63b39c3754b..0ff72e0b56605 100644 --- a/comp/otelcol/otlp/components/processor/infraattributesprocessor/logs.go +++ b/comp/otelcol/otlp/components/processor/infraattributesprocessor/logs.go @@ -43,7 +43,7 @@ func (ialp *infraAttributesLogProcessor) processLogs(_ context.Context, ld plog. // Get all unique tags from resource attributes and global tags for _, entityID := range entityIDs { - entityTags, err := ialp.tagger.Tag(entityID.String(), ialp.cardinality) + entityTags, err := ialp.tagger.Tag(entityID, ialp.cardinality) if err != nil { ialp.logger.Error("Cannot get tags for entity", zap.String("entityID", entityID.String()), zap.Error(err)) continue diff --git a/comp/otelcol/otlp/components/processor/infraattributesprocessor/metrics.go b/comp/otelcol/otlp/components/processor/infraattributesprocessor/metrics.go index e7a8cb3d7a700..8b7f5f14d8e49 100644 --- a/comp/otelcol/otlp/components/processor/infraattributesprocessor/metrics.go +++ b/comp/otelcol/otlp/components/processor/infraattributesprocessor/metrics.go @@ -97,7 +97,7 @@ func (iamp *infraAttributesMetricProcessor) processMetrics(_ context.Context, md // Get all unique tags from resource attributes and global tags for _, entityID := range entityIDs { - entityTags, err := iamp.tagger.Tag(entityID.String(), iamp.cardinality) + entityTags, err := iamp.tagger.Tag(entityID, iamp.cardinality) if err != nil { iamp.logger.Error("Cannot get tags for entity", zap.String("entityID", entityID.String()), zap.Error(err)) continue diff --git a/comp/otelcol/otlp/components/processor/infraattributesprocessor/traces.go b/comp/otelcol/otlp/components/processor/infraattributesprocessor/traces.go index ce6fe02674e95..eca0363e4ab9d 100644 --- a/comp/otelcol/otlp/components/processor/infraattributesprocessor/traces.go +++ b/comp/otelcol/otlp/components/processor/infraattributesprocessor/traces.go @@ -42,7 +42,7 @@ func (iasp *infraAttributesSpanProcessor) processTraces(_ context.Context, td pt // Get all unique tags from resource attributes and global tags for _, entityID := range entityIDs { - entityTags, err := iasp.tagger.Tag(entityID.String(), iasp.cardinality) + entityTags, err := iasp.tagger.Tag(entityID, iasp.cardinality) if err != nil { iasp.logger.Error("Cannot get tags for entity", zap.String("entityID", entityID.String()), zap.Error(err)) continue diff --git a/comp/trace/config/setup.go b/comp/trace/config/setup.go index ab9361127c633..6bd3be6278696 100644 --- a/comp/trace/config/setup.go +++ b/comp/trace/config/setup.go @@ -123,7 +123,7 @@ func prepareConfig(c corecompcfg.Component) (*config.AgentConfig, error) { } func containerTagsFunc(cid string) ([]string, error) { - return tagger.Tag(types.NewEntityID(types.ContainerID, cid).String(), types.HighCardinality) + return tagger.Tag(types.NewEntityID(types.ContainerID, cid), types.HighCardinality) } // appendEndpoints appends any endpoint configuration found at the given cfgKey. diff --git a/pkg/collector/corechecks/cluster/orchestrator/processors/k8s/pod_tag_provider/node_provider.go b/pkg/collector/corechecks/cluster/orchestrator/processors/k8s/pod_tag_provider/node_provider.go index 484fc20efb093..9235a7e02de58 100644 --- a/pkg/collector/corechecks/cluster/orchestrator/processors/k8s/pod_tag_provider/node_provider.go +++ b/pkg/collector/corechecks/cluster/orchestrator/processors/k8s/pod_tag_provider/node_provider.go @@ -20,5 +20,5 @@ func newNodePodTagProvider() PodTagProvider { return &nodePodTagProvider{} } // GetTags implements PodTagProvider#GetTags func (p *nodePodTagProvider) GetTags(pod *corev1.Pod, cardinality taggertypes.TagCardinality) ([]string, error) { - return tagger.Tag(taggertypes.NewEntityID(taggertypes.KubernetesPodUID, string(pod.UID)).String(), cardinality) + return tagger.Tag(taggertypes.NewEntityID(taggertypes.KubernetesPodUID, string(pod.UID)), cardinality) } diff --git a/pkg/collector/corechecks/cluster/orchestrator/transformers/ecs/task.go b/pkg/collector/corechecks/cluster/orchestrator/transformers/ecs/task.go index 0526ab2d659b1..4f01d045b3514 100644 --- a/pkg/collector/corechecks/cluster/orchestrator/transformers/ecs/task.go +++ b/pkg/collector/corechecks/cluster/orchestrator/transformers/ecs/task.go @@ -58,7 +58,7 @@ func ExtractECSTask(task TaskWithContainers) *model.ECSTask { } entityID := types.NewEntityID(types.ECSTask, task.Task.EntityID.ID) - tags, err := tagger.Tag(entityID.String(), types.HighCardinality) + tags, err := tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Debugf("Could not retrieve tags for task: %s", err.Error()) } diff --git a/pkg/collector/corechecks/containerimage/processor.go b/pkg/collector/corechecks/containerimage/processor.go index 668a84fd93bfa..c9dcea2cefaeb 100644 --- a/pkg/collector/corechecks/containerimage/processor.go +++ b/pkg/collector/corechecks/containerimage/processor.go @@ -75,7 +75,7 @@ func (p *processor) processRefresh(allImages []*workloadmeta.ContainerImageMetad func (p *processor) processImage(img *workloadmeta.ContainerImageMetadata) { entityID := types.NewEntityID(types.ContainerImageMetadata, img.ID) - ddTags, err := tagger.Tag(entityID.String(), types.HighCardinality) + ddTags, err := tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Errorf("Could not retrieve tags for container image %s: %v", img.ID, err) } diff --git a/pkg/collector/corechecks/containers/containerd/events.go b/pkg/collector/corechecks/containers/containerd/events.go index 71c14aa585ac5..91c30213b93f4 100644 --- a/pkg/collector/corechecks/containers/containerd/events.go +++ b/pkg/collector/corechecks/containers/containerd/events.go @@ -52,7 +52,7 @@ func computeEvents(events []containerdEvent, sender sender.Sender, fil *containe alertType := event.AlertTypeInfo if split[1] == "containers" || split[1] == "tasks" { // For task events, we use the container ID in order to query the Tagger's API - t, err := tagger.Tag(types.NewEntityID(types.ContainerID, e.ID).String(), types.HighCardinality) + t, err := tagger.Tag(types.NewEntityID(types.ContainerID, e.ID), types.HighCardinality) if err != nil { // If there is an error retrieving tags from the Tagger, we can still submit the event as is. log.Errorf("Could not retrieve tags for the container %s: %v", e.ID, err) diff --git a/pkg/collector/corechecks/containers/docker/check.go b/pkg/collector/corechecks/containers/docker/check.go index 1fea8ba33f979..036e3a4e748e5 100644 --- a/pkg/collector/corechecks/containers/docker/check.go +++ b/pkg/collector/corechecks/containers/docker/check.go @@ -239,7 +239,7 @@ func (d *DockerCheck) runDockerCustom(sender sender.Sender, du docker.Client, ra isContainerExcluded := d.containerFilter.IsExcluded(annotations, containerName, resolvedImageName, rawContainer.Labels[kubernetes.CriContainerNamespaceLabel]) isContainerRunning := rawContainer.State == string(workloadmeta.ContainerStatusRunning) - taggerEntityID := types.NewEntityID(types.ContainerID, rawContainer.ID).String() + taggerEntityID := types.NewEntityID(types.ContainerID, rawContainer.ID) tags, err := getImageTagsFromContainer(taggerEntityID, resolvedImageName, isContainerExcluded || !isContainerRunning) if err != nil { log.Debugf("Unable to fetch tags for image: %s, err: %v", rawContainer.ImageID, err) diff --git a/pkg/collector/corechecks/containers/docker/eventbundle.go b/pkg/collector/corechecks/containers/docker/eventbundle.go index 6f67d03d7a29a..4dfeac8f769af 100644 --- a/pkg/collector/corechecks/containers/docker/eventbundle.go +++ b/pkg/collector/corechecks/containers/docker/eventbundle.go @@ -93,7 +93,7 @@ func (b *dockerEventBundle) toDatadogEvent(hostname string) (event.Event, error) for cid := range seenContainers { - tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, cid).String(), types.HighCardinality) + tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, cid), types.HighCardinality) if err != nil { log.Debugf("no tags for %s: %s", cid, err) } else { diff --git a/pkg/collector/corechecks/containers/docker/events.go b/pkg/collector/corechecks/containers/docker/events.go index b492305983408..a1dbc0337df93 100644 --- a/pkg/collector/corechecks/containers/docker/events.go +++ b/pkg/collector/corechecks/containers/docker/events.go @@ -83,7 +83,7 @@ func (d *DockerCheck) reportExitCodes(events []*docker.ContainerEvent, sender se status = servicecheck.ServiceCheckCritical } - tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, ev.ContainerID).String(), types.HighCardinality) + tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, ev.ContainerID), types.HighCardinality) if err != nil { log.Debugf("no tags for %s: %s", ev.ContainerID, err) tags = []string{} diff --git a/pkg/collector/corechecks/containers/docker/unbundled_events.go b/pkg/collector/corechecks/containers/docker/unbundled_events.go index ddb763e97f77f..19c2273ebb9c7 100644 --- a/pkg/collector/corechecks/containers/docker/unbundled_events.go +++ b/pkg/collector/corechecks/containers/docker/unbundled_events.go @@ -57,7 +57,7 @@ func (t *unbundledTransformer) Transform(events []*docker.ContainerEvent) ([]eve emittedEvents.Inc(string(alertType)) tags, err := tagger.Tag( - types.NewEntityID(types.ContainerID, ev.ContainerID).String(), + types.NewEntityID(types.ContainerID, ev.ContainerID), types.HighCardinality, ) if err != nil { diff --git a/pkg/collector/corechecks/containers/docker/utils.go b/pkg/collector/corechecks/containers/docker/utils.go index 500cf6cdde2d7..3b3990cbfdf8f 100644 --- a/pkg/collector/corechecks/containers/docker/utils.go +++ b/pkg/collector/corechecks/containers/docker/utils.go @@ -30,7 +30,7 @@ func getProcessorFilter(legacyFilter *containers.Filter, store workloadmeta.Comp } } -func getImageTagsFromContainer(taggerEntityID string, resolvedImageName string, isContainerExcluded bool) ([]string, error) { +func getImageTagsFromContainer(taggerEntityID types.EntityID, resolvedImageName string, isContainerExcluded bool) ([]string, error) { if isContainerExcluded { return getImageTags(resolvedImageName) } diff --git a/pkg/collector/corechecks/containers/generic/processor.go b/pkg/collector/corechecks/containers/generic/processor.go index a40fe1512f4e3..44612d6839c52 100644 --- a/pkg/collector/corechecks/containers/generic/processor.go +++ b/pkg/collector/corechecks/containers/generic/processor.go @@ -73,7 +73,7 @@ func (p *Processor) Run(sender sender.Sender, cacheValidity time.Duration) error entityID := types.NewEntityID(types.ContainerID, container.ID) - tags, err := tagger.Tag(entityID.String(), types.HighCardinality) + tags, err := tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Errorf("Could not collect tags for container %q, err: %v", container.ID[:12], err) continue diff --git a/pkg/collector/corechecks/containers/generic/processor_network.go b/pkg/collector/corechecks/containers/generic/processor_network.go index d83fd0f215043..52b992dee3937 100644 --- a/pkg/collector/corechecks/containers/generic/processor_network.go +++ b/pkg/collector/corechecks/containers/generic/processor_network.go @@ -98,7 +98,7 @@ func (pn *ProcessorNetwork) processGroupedContainerNetwork() { pn.generateNetworkMetrics(containerNetworks.tags, containerNetworks.stats) } else if containerNetworks.owner != nil && containerNetworks.owner.Kind == workloadmeta.KindKubernetesPod { podEntityID := types.NewEntityID(types.KubernetesPodUID, containerNetworks.owner.ID) - orchTags, err := tagger.Tag(podEntityID.String(), types.HighCardinality) + orchTags, err := tagger.Tag(podEntityID, types.HighCardinality) if err != nil { log.Debugf("Unable to get orchestrator tags for pod: %s", containerNetworks.owner.ID) continue diff --git a/pkg/collector/corechecks/containers/generic/processor_network_test.go b/pkg/collector/corechecks/containers/generic/processor_network_test.go index fee5d7c42cf67..a6aa31341e2b5 100644 --- a/pkg/collector/corechecks/containers/generic/processor_network_test.go +++ b/pkg/collector/corechecks/containers/generic/processor_network_test.go @@ -192,19 +192,19 @@ func TestNetworkProcessorExtension(t *testing.T) { // Running them through the ProcessorExtension networkProcessor.PreProcess(MockSendMetric, mockSender) - container1Tags, _ := fakeTagger.Tag("container_id://1", types.HighCardinality) + container1Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "1"), types.HighCardinality) networkProcessor.Process(container1Tags, container1, mockCollector, 0) - container2Tags, _ := fakeTagger.Tag("container_id://2", types.HighCardinality) + container2Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "2"), types.HighCardinality) networkProcessor.Process(container2Tags, container2, mockCollector, 0) - container3Tags, _ := fakeTagger.Tag("container_id://3", types.HighCardinality) + container3Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "3"), types.HighCardinality) networkProcessor.Process(container3Tags, container3, mockCollector, 0) - container4Tags, _ := fakeTagger.Tag("container_id://4", types.HighCardinality) + container4Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "4"), types.HighCardinality) networkProcessor.Process(container4Tags, container4, mockCollector, 0) - container5Tags, _ := fakeTagger.Tag("container_id://5", types.HighCardinality) + container5Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "5"), types.HighCardinality) networkProcessor.Process(container5Tags, container5, mockCollector, 0) - container6Tags, _ := fakeTagger.Tag("container_id://6", types.HighCardinality) + container6Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "6"), types.HighCardinality) networkProcessor.Process(container6Tags, container6, mockCollector, 0) - container7Tags, _ := fakeTagger.Tag("container_id://7", types.HighCardinality) + container7Tags, _ := fakeTagger.Tag(types.NewEntityID(types.ContainerID, "7"), types.HighCardinality) networkProcessor.Process(container7Tags, container7, mockCollector, 0) networkProcessor.PostProcess() diff --git a/pkg/collector/corechecks/containers/kubelet/common/pod.go b/pkg/collector/corechecks/containers/kubelet/common/pod.go index 7949d89e5f8a0..54a105c90bab2 100644 --- a/pkg/collector/corechecks/containers/kubelet/common/pod.go +++ b/pkg/collector/corechecks/containers/kubelet/common/pod.go @@ -85,7 +85,7 @@ func (p *PodUtils) PopulateForPod(pod *kubelet.Pod) { // computePodTagsByPVC stores the tags for a given pod in a global caching layer, indexed by pod namespace and persistent // volume name. func (p *PodUtils) computePodTagsByPVC(pod *kubelet.Pod) { - podUID := types.NewEntityID(types.KubernetesPodUID, pod.Metadata.UID).String() + podUID := types.NewEntityID(types.KubernetesPodUID, pod.Metadata.UID) tags, _ := tagger.Tag(podUID, types.OrchestratorCardinality) if len(tags) == 0 { return @@ -192,7 +192,5 @@ func GetContainerID(store workloadmeta.Component, metric model.Metric, filter *c return "", ErrContainerExcluded } - cID := types.NewEntityID(types.ContainerID, container.ID).String() - - return cID, nil + return container.ID, nil } diff --git a/pkg/collector/corechecks/containers/kubelet/provider/cadvisor/provider.go b/pkg/collector/corechecks/containers/kubelet/provider/cadvisor/provider.go index d32cd95ab2027..7d2a65ad04f71 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/cadvisor/provider.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/cadvisor/provider.go @@ -152,7 +152,7 @@ func (p *Provider) processContainerMetric(metricType, metricName string, metricF // for static pods, see https://github.com/kubernetes/kubernetes/pull/59948 pod := p.getPodByMetricLabel(sample.Metric) if pod != nil && p.podUtils.IsStaticPendingPod(pod.ID) { - podTags, _ := tagger.Tag(taggercommon.BuildTaggerEntityID(pod.GetID()).String(), types.HighCardinality) + podTags, _ := tagger.Tag(taggercommon.BuildTaggerEntityID(pod.GetID()), types.HighCardinality) if len(podTags) == 0 { continue } @@ -208,7 +208,7 @@ func (p *Provider) processPodRate(metricName string, metricFam *prom.MetricFamil continue } entityID := taggercommon.BuildTaggerEntityID(pod.GetID()) - tags, _ := tagger.Tag(entityID.String(), types.HighCardinality) + tags, _ := tagger.Tag(entityID, types.HighCardinality) if len(tags) == 0 { continue } @@ -250,7 +250,7 @@ func (p *Provider) processUsageMetric(metricName string, metricFam *prom.MetricF pod := p.getPodByMetricLabel(sample.Metric) if pod != nil && p.podUtils.IsStaticPendingPod(pod.ID) { entityID := taggercommon.BuildTaggerEntityID(pod.EntityID) - podTags, _ := tagger.Tag(entityID.String(), types.HighCardinality) + podTags, _ := tagger.Tag(entityID, types.HighCardinality) if len(podTags) == 0 { continue } @@ -352,7 +352,7 @@ func (p *Provider) getEntityIDIfContainerMetric(labels model.Metric) string { return p.getPodUID(labels) } cID, _ := common.GetContainerID(p.store, labels, p.filter) - return cID + return types.NewEntityID(types.ContainerID, cID).String() } return "" } diff --git a/pkg/collector/corechecks/containers/kubelet/provider/kubelet/provider.go b/pkg/collector/corechecks/containers/kubelet/provider/kubelet/provider.go index ea3d40af9c990..2307903d85cd0 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/kubelet/provider.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/kubelet/provider.go @@ -185,7 +185,7 @@ func (p *Provider) kubeletContainerLogFilesystemUsedBytes(metricFam *prom.Metric continue } - tags, _ := tagger.Tag(cID, types.HighCardinality) + tags, _ := tagger.Tag(types.NewEntityID(types.ContainerID, cID), types.HighCardinality) if len(tags) == 0 { log.Debugf("Tags not found for container: %s/%s/%s:%s", metric.Metric["namespace"], metric.Metric["pod"], metric.Metric["container"], cID) } diff --git a/pkg/collector/corechecks/containers/kubelet/provider/pod/provider.go b/pkg/collector/corechecks/containers/kubelet/provider/pod/provider.go index aa2a19af797c5..38ee589c389cf 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/pod/provider.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/pod/provider.go @@ -116,7 +116,7 @@ func (p *Provider) Provide(kc kubelet.KubeUtilInterface, sender sender.Sender) e return nil } -func (p *Provider) generateContainerSpecMetrics(sender sender.Sender, pod *kubelet.Pod, container *kubelet.ContainerSpec, cStatus *kubelet.ContainerStatus, containerID string) { +func (p *Provider) generateContainerSpecMetrics(sender sender.Sender, pod *kubelet.Pod, container *kubelet.ContainerSpec, cStatus *kubelet.ContainerStatus, containerID types.EntityID) { if pod.Status.Phase != "Running" && pod.Status.Phase != "Pending" { return } @@ -140,7 +140,7 @@ func (p *Provider) generateContainerSpecMetrics(sender sender.Sender, pod *kubel } } -func (p *Provider) generateContainerStatusMetrics(sender sender.Sender, pod *kubelet.Pod, _ *kubelet.ContainerSpec, cStatus *kubelet.ContainerStatus, containerID string) { +func (p *Provider) generateContainerStatusMetrics(sender sender.Sender, pod *kubelet.Pod, _ *kubelet.ContainerSpec, cStatus *kubelet.ContainerStatus, containerID types.EntityID) { if pod.Metadata.UID == "" || pod.Metadata.Name == "" { return } @@ -184,7 +184,7 @@ func newRunningAggregator() *runningAggregator { } } -func (r *runningAggregator) recordContainer(p *Provider, pod *kubelet.Pod, cStatus *kubelet.ContainerStatus, containerID string) { +func (r *runningAggregator) recordContainer(p *Provider, pod *kubelet.Pod, cStatus *kubelet.ContainerStatus, containerID types.EntityID) { if cStatus.State.Running == nil || time.Time.IsZero(cStatus.State.Running.StartedAt) { return } @@ -210,7 +210,7 @@ func (r *runningAggregator) recordPod(p *Provider, pod *kubelet.Pod) { log.Debug("skipping pod with no uid") return } - entityID := types.NewEntityID(types.KubernetesPodUID, podID).String() + entityID := types.NewEntityID(types.KubernetesPodUID, podID) tagList, _ := tagger.Tag(entityID, types.LowCardinality) if len(tagList) == 0 { return diff --git a/pkg/collector/corechecks/containers/kubelet/provider/probe/provider.go b/pkg/collector/corechecks/containers/kubelet/provider/probe/provider.go index f6f1f2ae62255..ca8d8369e3009 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/probe/provider.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/probe/provider.go @@ -88,7 +88,7 @@ func (p *Provider) proberProbeTotal(metricFam *prom.MetricFamily, sender sender. continue } - tags, _ := tagger.Tag(cID, types.HighCardinality) + tags, _ := tagger.Tag(types.NewEntityID(types.ContainerID, cID), types.HighCardinality) if len(tags) == 0 { continue } diff --git a/pkg/collector/corechecks/containers/kubelet/provider/summary/provider.go b/pkg/collector/corechecks/containers/kubelet/provider/summary/provider.go index 6e2d330d66d7d..37635048ad41d 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/summary/provider.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/summary/provider.go @@ -150,7 +150,7 @@ func (p *Provider) processPodStats(sender sender.Sender, } entityID := types.NewEntityID(types.KubernetesPodUID, podStats.PodRef.UID) - podTags, _ := tagger.Tag(entityID.String(), + podTags, _ := tagger.Tag(entityID, types.OrchestratorCardinality) if len(podTags) == 0 { @@ -221,7 +221,7 @@ func (p *Provider) processContainerStats(sender sender.Sender, podStats.PodRef.Namespace) { continue } - tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, ctr.ID).String(), types.HighCardinality) + tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, ctr.ID), types.HighCardinality) if err != nil || len(tags) == 0 { log.Debugf("Tags not found for container: %s/%s/%s:%s - no metrics will be sent", podStats.PodRef.Namespace, podStats.PodRef.Name, containerName, ctr.ID) diff --git a/pkg/collector/corechecks/ebpf/oomkill/oom_kill.go b/pkg/collector/corechecks/ebpf/oomkill/oom_kill.go index 0a5b506ce1e7b..fa511a4e66db5 100644 --- a/pkg/collector/corechecks/ebpf/oomkill/oom_kill.go +++ b/pkg/collector/corechecks/ebpf/oomkill/oom_kill.go @@ -115,9 +115,9 @@ func (m *OOMKillCheck) Run() error { log.Debugf("Unable to extract containerID from cgroup name: %s, err: %v", line.CgroupName, err) } - entityID := types.NewEntityID(types.ContainerID, containerID).String() + entityID := types.NewEntityID(types.ContainerID, containerID) var tags []string - if entityID != "" { + if entityID.Empty() { tags, err = tagger.Tag(entityID, tagger.ChecksCardinality()) if err != nil { log.Errorf("Error collecting tags for container %s: %s", containerID, err) diff --git a/pkg/collector/corechecks/ebpf/tcpqueuelength/tcp_queue_length.go b/pkg/collector/corechecks/ebpf/tcpqueuelength/tcp_queue_length.go index 126f949876c87..8a8b8c9cd5bb7 100644 --- a/pkg/collector/corechecks/ebpf/tcpqueuelength/tcp_queue_length.go +++ b/pkg/collector/corechecks/ebpf/tcpqueuelength/tcp_queue_length.go @@ -110,9 +110,9 @@ func (t *TCPQueueLengthCheck) Run() error { continue } - entityID := types.NewEntityID(types.ContainerID, containerID).String() + entityID := types.NewEntityID(types.ContainerID, containerID) var tags []string - if entityID != "" { + if entityID.Empty() { tags, err = tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Errorf("Error collecting tags for container %s: %s", k, err) diff --git a/pkg/collector/corechecks/sbom/processor.go b/pkg/collector/corechecks/sbom/processor.go index 91bfeddccf531..b26e2eaebc596 100644 --- a/pkg/collector/corechecks/sbom/processor.go +++ b/pkg/collector/corechecks/sbom/processor.go @@ -242,7 +242,7 @@ func (p *processor) processImageSBOM(img *workloadmeta.ContainerImageMetadata) { return } - entityID := types.NewEntityID(types.ContainerImageMetadata, img.ID).String() + entityID := types.NewEntityID(types.ContainerImageMetadata, img.ID) ddTags, err := tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Errorf("Could not retrieve tags for container image %s: %v", img.ID, err) diff --git a/pkg/collector/python/tagger.go b/pkg/collector/python/tagger.go index e572e7474a935..0638963dea642 100644 --- a/pkg/collector/python/tagger.go +++ b/pkg/collector/python/tagger.go @@ -26,7 +26,7 @@ import "C" // for testing purposes var ( - tagsFunc = tagger.TagDeprecated + tagsFunc = tagger.LegacyTag ) // Tags bridges towards tagger.Tag to retrieve container tags diff --git a/pkg/collector/python/test_tagger.go b/pkg/collector/python/test_tagger.go index f3acbf2e03c32..bbeff9e0dfd7e 100644 --- a/pkg/collector/python/test_tagger.go +++ b/pkg/collector/python/test_tagger.go @@ -49,7 +49,7 @@ func tagsMockEmpty(string, types.TagCardinality) ([]string, error) { func testTags(t *testing.T) { tagsFunc = tagsMock - defer func() { tagsFunc = tagger.Tag }() + defer func() { tagsFunc = tagger.LegacyTag }() id := C.CString("test") defer C.free(unsafe.Pointer(id)) @@ -68,7 +68,7 @@ func testTags(t *testing.T) { func testTagsNull(t *testing.T) { tagsFunc = tagsMockNull - defer func() { tagsFunc = tagger.Tag }() + defer func() { tagsFunc = tagger.LegacyTag }() id := C.CString("test") defer C.free(unsafe.Pointer(id)) @@ -79,7 +79,7 @@ func testTagsNull(t *testing.T) { func testTagsEmpty(t *testing.T) { tagsFunc = tagsMockEmpty - defer func() { tagsFunc = tagger.Tag }() + defer func() { tagsFunc = tagger.LegacyTag }() id := C.CString("test") defer C.free(unsafe.Pointer(id)) diff --git a/pkg/logs/internal/tag/provider.go b/pkg/logs/internal/tag/provider.go index 7196bacb02646..1a78e2f2d11e9 100644 --- a/pkg/logs/internal/tag/provider.go +++ b/pkg/logs/internal/tag/provider.go @@ -24,12 +24,12 @@ type Provider interface { // EntityTagAdder returns the associated tag for an entity and their cardinality type EntityTagAdder interface { - Tag(entity string, cardinality types.TagCardinality) ([]string, error) + Tag(entity types.EntityID, cardinality types.TagCardinality) ([]string, error) } // provider provides a list of up-to-date tags for a given entity by calling the tagger. type provider struct { - entityID string + entityID types.EntityID taggerWarmupDuration time.Duration localTagProvider Provider clock clock.Clock @@ -38,12 +38,12 @@ type provider struct { } // NewProvider returns a new Provider. -func NewProvider(entityID string, tagAdder EntityTagAdder) Provider { +func NewProvider(entityID types.EntityID, tagAdder EntityTagAdder) Provider { return newProviderWithClock(entityID, clock.New(), tagAdder) } // newProviderWithClock returns a new provider using the given clock. -func newProviderWithClock(entityID string, clock clock.Clock, tagAdder EntityTagAdder) Provider { +func newProviderWithClock(entityID types.EntityID, clock clock.Clock, tagAdder EntityTagAdder) Provider { p := &provider{ entityID: entityID, taggerWarmupDuration: config.TaggerWarmupDuration(pkgconfigsetup.Datadog()), diff --git a/pkg/logs/internal/tag/provider_benchmark_test.go b/pkg/logs/internal/tag/provider_benchmark_test.go index 8b2ece36e2d83..ce47807725883 100644 --- a/pkg/logs/internal/tag/provider_benchmark_test.go +++ b/pkg/logs/internal/tag/provider_benchmark_test.go @@ -28,7 +28,7 @@ func setupConfig(t testing.TB, tags []string) (model.Config, time.Time) { type dummyTagAdder struct{} -func (dummyTagAdder) Tag(string, types.TagCardinality) ([]string, error) { +func (dummyTagAdder) Tag(types.EntityID, types.TagCardinality) ([]string, error) { return nil, nil } @@ -46,7 +46,7 @@ func BenchmarkProviderExpectedTags(b *testing.B) { m.SetWithoutSource("logs_config.expected_tags_duration", "1m") defer m.SetWithoutSource("logs_config.expected_tags_duration", 0) - p := NewProvider("foo", dummyTagAdder{}) + p := NewProvider(types.NewEntityID(types.ContainerID, "foo"), dummyTagAdder{}) for i := 0; i < b.N; i++ { p.GetTags() @@ -69,7 +69,7 @@ func BenchmarkProviderExpectedTagsEmptySlice(b *testing.B) { m.SetWithoutSource("logs_config.expected_tags_duration", "1m") defer m.SetWithoutSource("logs_config.expected_tags_duration", 0) - p := NewProvider("foo", dummyTagAdder{}) + p := NewProvider(types.NewEntityID(types.ContainerID, "foo"), dummyTagAdder{}) for i := 0; i < b.N; i++ { p.GetTags() @@ -92,7 +92,7 @@ func BenchmarkProviderExpectedTagsNil(b *testing.B) { m.SetWithoutSource("logs_config.expected_tags_duration", "1m") defer m.SetWithoutSource("logs_config.expected_tags_duration", 0) - p := NewProvider("foo", dummyTagAdder{}) + p := NewProvider(types.NewEntityID(types.ContainerID, "foo"), dummyTagAdder{}) for i := 0; i < b.N; i++ { p.GetTags() @@ -112,7 +112,7 @@ func BenchmarkProviderNoExpectedTags(b *testing.B) { // Setting a test-friendly value for the deadline (test should not take 1m) m.SetWithoutSource("logs_config.expected_tags_duration", "0") - p := NewProvider("foo", dummyTagAdder{}) + p := NewProvider(types.NewEntityID(types.ContainerID, "foo"), dummyTagAdder{}) for i := 0; i < b.N; i++ { p.GetTags() @@ -132,7 +132,7 @@ func BenchmarkProviderNoExpectedTagsNil(b *testing.B) { // Setting a test-friendly value for the deadline (test should not take 1m) m.SetWithoutSource("logs_config.expected_tags_duration", "0") - p := NewProvider("foo", dummyTagAdder{}) + p := NewProvider(types.NewEntityID(types.ContainerID, "foo"), dummyTagAdder{}) for i := 0; i < b.N; i++ { p.GetTags() diff --git a/pkg/logs/internal/tag/provider_test.go b/pkg/logs/internal/tag/provider_test.go index b238d9c58b542..3b7b361ec550d 100644 --- a/pkg/logs/internal/tag/provider_test.go +++ b/pkg/logs/internal/tag/provider_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" + "github.com/DataDog/datadog-agent/comp/core/tagger/types" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -41,7 +42,7 @@ func TestProviderExpectedTags(t *testing.T) { m.SetWithoutSource("logs_config.expected_tags_duration", "5s") defer m.SetWithoutSource("logs_config.expected_tags_duration", 0) - p := newProviderWithClock("foo", clock, fakeTagger) + p := newProviderWithClock(types.NewEntityID(types.ContainerID, "foo"), clock, fakeTagger) pp := p.(*provider) var tt []string diff --git a/pkg/logs/tailers/docker/tailer.go b/pkg/logs/tailers/docker/tailer.go index be25cdc72b521..7eb2b19b6ee64 100644 --- a/pkg/logs/tailers/docker/tailer.go +++ b/pkg/logs/tailers/docker/tailer.go @@ -86,7 +86,7 @@ func NewTailer(cli *dockerutil.DockerUtil, containerID string, source *sources.L outputChan: outputChan, decoder: decoder.NewDecoderWithFraming(sources.NewReplaceableSource(source), dockerstream.New(containerID), framer.DockerStream, nil, status.NewInfoRegistry()), Source: source, - tagProvider: tag.NewProvider(types.NewEntityID(types.ContainerID, containerID).String(), tagger), + tagProvider: tag.NewProvider(types.NewEntityID(types.ContainerID, containerID), tagger), dockerutil: cli, readTimeout: readTimeout, sleepDuration: defaultSleepDuration, diff --git a/pkg/logs/tailers/file/tailer.go b/pkg/logs/tailers/file/tailer.go index 4cd584b6e509e..b9d96b982fcf8 100644 --- a/pkg/logs/tailers/file/tailer.go +++ b/pkg/logs/tailers/file/tailer.go @@ -144,7 +144,7 @@ type TailerOptions struct { func NewTailer(opts *TailerOptions) *Tailer { var tagProvider tag.Provider if opts.File.Source.Config().Identifier != "" { - tagProvider = tag.NewProvider(types.NewEntityID(types.ContainerID, opts.File.Source.Config().Identifier).String(), opts.TagAdder) + tagProvider = tag.NewProvider(types.NewEntityID(types.ContainerID, opts.File.Source.Config().Identifier), opts.TagAdder) } else { tagProvider = tag.NewLocalProvider([]string{}) } diff --git a/pkg/logs/tailers/journald/docker.go b/pkg/logs/tailers/journald/docker.go index 0c80df85cf435..bcc835d341373 100644 --- a/pkg/logs/tailers/journald/docker.go +++ b/pkg/logs/tailers/journald/docker.go @@ -34,7 +34,7 @@ func (t *Tailer) getContainerID(entry *sdjournal.JournalEntry) string { // getContainerTags returns all the tags of a given container. func (t *Tailer) getContainerTags(containerID string) []string { - tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, containerID).String(), types.HighCardinality) + tags, err := tagger.Tag(types.NewEntityID(types.ContainerID, containerID), types.HighCardinality) if err != nil { log.Warn(err) } diff --git a/pkg/process/util/containers/containers.go b/pkg/process/util/containers/containers.go index fd66a93ae0af4..6ab0b27c1e32c 100644 --- a/pkg/process/util/containers/containers.go +++ b/pkg/process/util/containers/containers.go @@ -119,7 +119,7 @@ func (p *containerProvider) GetContainers(cacheValidity time.Duration, previousC continue } - entityID := types.NewEntityID(types.ContainerID, container.ID).String() + entityID := types.NewEntityID(types.ContainerID, container.ID) tags, err := tagger.Tag(entityID, types.HighCardinality) if err != nil { log.Debugf("Could not collect tags for container %q, err: %v", container.ID[:12], err) diff --git a/pkg/security/resolvers/tags/resolver.go b/pkg/security/resolvers/tags/resolver.go index e62736f1e5afa..c8674a0bfa3f0 100644 --- a/pkg/security/resolvers/tags/resolver.go +++ b/pkg/security/resolvers/tags/resolver.go @@ -24,7 +24,7 @@ import ( type Tagger interface { Start(ctx context.Context) error Stop() error - Tag(entity string, cardinality types.TagCardinality) ([]string, error) + Tag(entity types.EntityID, cardinality types.TagCardinality) ([]string, error) } type nullTagger struct{} @@ -37,7 +37,7 @@ func (n *nullTagger) Stop() error { return nil } -func (n *nullTagger) Tag(_ string, _ types.TagCardinality) ([]string, error) { +func (n *nullTagger) Tag(_ types.EntityID, _ types.TagCardinality) ([]string, error) { return nil, nil } @@ -80,14 +80,14 @@ func (t *DefaultResolver) Resolve(id string) []string { } entityID := types.NewEntityID(types.ContainerID, id) - tags, _ := t.tagger.Tag(entityID.String(), types.OrchestratorCardinality) + tags, _ := t.tagger.Tag(entityID, types.OrchestratorCardinality) return tags } // ResolveWithErr returns the tags for the given id func (t *DefaultResolver) ResolveWithErr(id string) ([]string, error) { entityID := types.NewEntityID(types.ContainerID, id) - return t.tagger.Tag(entityID.String(), types.OrchestratorCardinality) + return t.tagger.Tag(entityID, types.OrchestratorCardinality) } // GetValue return the tag value for the given id and tag name diff --git a/pkg/util/kubernetes/kubelet/kubelet_common.go b/pkg/util/kubernetes/kubelet/kubelet_common.go index e8fe1e94fafec..cb27bcdb8dfac 100644 --- a/pkg/util/kubernetes/kubelet/kubelet_common.go +++ b/pkg/util/kubernetes/kubelet/kubelet_common.go @@ -60,27 +60,27 @@ func ParseMetricFromRaw(raw []byte, metric string) (string, error) { // KubeContainerIDToTaggerEntityID builds an entity ID from a container ID coming from // the pod status (i.e. including the :// prefix). -func KubeContainerIDToTaggerEntityID(ctrID string) (string, error) { +func KubeContainerIDToTaggerEntityID(ctrID string) (types.EntityID, error) { sep := strings.LastIndex(ctrID, containers.EntitySeparator) if sep != -1 && len(ctrID) > sep+len(containers.EntitySeparator) { - return types.NewEntityID(types.ContainerID, ctrID[sep+len(containers.EntitySeparator):]).String(), nil + return types.NewEntityID(types.ContainerID, ctrID[sep+len(containers.EntitySeparator):]), nil } - return "", fmt.Errorf("can't extract an entity ID from container ID %s", ctrID) + return types.EntityID{}, fmt.Errorf("can't extract an entity ID from container ID %s", ctrID) } // KubePodUIDToTaggerEntityID builds an entity ID from a pod UID coming from // the pod status (i.e. including the :// prefix). -func KubePodUIDToTaggerEntityID(podUID string) (string, error) { +func KubePodUIDToTaggerEntityID(podUID string) (types.EntityID, error) { sep := strings.LastIndex(podUID, containers.EntitySeparator) if sep != -1 && len(podUID) > sep+len(containers.EntitySeparator) { - return types.NewEntityID(types.KubernetesPodUID, podUID[sep+len(containers.EntitySeparator):]).String(), nil + return types.NewEntityID(types.KubernetesPodUID, podUID[sep+len(containers.EntitySeparator):]), nil } - return "", fmt.Errorf("can't extract an entity ID from pod UID %s", podUID) + return types.EntityID{}, fmt.Errorf("can't extract an entity ID from pod UID %s", podUID) } // KubeIDToTaggerEntityID builds a tagger entity ID from an entity ID belonging to // a container or pod. -func KubeIDToTaggerEntityID(entityName string) (string, error) { +func KubeIDToTaggerEntityID(entityName string) (types.EntityID, error) { prefix, _ := containers.SplitEntityName(entityName) if prefix == KubePodEntityName { diff --git a/pkg/util/kubernetes/kubelet/kubelet_common_test.go b/pkg/util/kubernetes/kubelet/kubelet_common_test.go index 1119161dc6c19..1d105dd978703 100644 --- a/pkg/util/kubernetes/kubelet/kubelet_common_test.go +++ b/pkg/util/kubernetes/kubelet/kubelet_common_test.go @@ -72,7 +72,7 @@ func TestKubeContainerIDToTaggerEntityID(t *testing.T) { } { t.Run(fmt.Sprintf("case: %s", in), func(t *testing.T) { res, _ := KubeContainerIDToTaggerEntityID(in) - assert.Equal(t, out, res) + assert.Equal(t, out, res.String()) }) } } @@ -89,7 +89,7 @@ func TestKubePodUIDToTaggerEntityID(t *testing.T) { } { t.Run(fmt.Sprintf("case: %s", in), func(t *testing.T) { res, _ := KubePodUIDToTaggerEntityID(in) - assert.Equal(t, out, res) + assert.Equal(t, out, res.String()) }) } } @@ -106,7 +106,7 @@ func TestKubeIDToTaggerEntityID(t *testing.T) { } { t.Run(fmt.Sprintf("case: %s", in), func(t *testing.T) { res, _ := KubeIDToTaggerEntityID(in) - assert.Equal(t, out, res) + assert.Equal(t, out, res.String()) }) } }