From 9b989108b26ec2c7662b03a2d92151a98bba852f Mon Sep 17 00:00:00 2001 From: Rick Rossi Date: Wed, 8 Jan 2025 14:50:54 -0500 Subject: [PATCH] Correct erroneuous use of PodNameKey --- exporter/awsemfexporter/emf_exporter.go | 3 ++ .../cadvisor/container_info_processor.go | 4 +- .../internal/efa/efaSysfs.go | 2 +- .../internal/efa/efaSysfs_test.go | 8 ++-- .../internal/gpu/dcgmscraper_config.go | 2 +- .../internal/gpu/dcgmscraper_test.go | 4 +- .../internal/k8swindows/hcsshim/hcsshim.go | 2 +- .../k8swindows/hcsshim/hcsshim_test.go | 2 +- .../internal/k8swindows/kubelet/kubelet.go | 4 +- .../k8swindows/kubelet/kubelet_test.go | 6 +-- .../neuron/pod_attribute_decorator.go | 2 +- .../neuron/pod_attribute_decorator_test.go | 8 ++-- .../internal/stores/podstore.go | 2 +- .../internal/stores/podstore_test.go | 48 +++++++++---------- .../internal/stores/servicestore.go | 2 +- .../internal/stores/servicestore_test.go | 6 +-- .../internal/stores/utils.go | 6 +-- .../internal/stores/utils_test.go | 8 ++-- 18 files changed, 61 insertions(+), 58 deletions(-) diff --git a/exporter/awsemfexporter/emf_exporter.go b/exporter/awsemfexporter/emf_exporter.go index 7ae4d0d9e541..2a944aaf2a7e 100644 --- a/exporter/awsemfexporter/emf_exporter.go +++ b/exporter/awsemfexporter/emf_exporter.go @@ -12,6 +12,7 @@ import ( "sync" "github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/google/uuid" "go.opentelemetry.io/collector/component" @@ -204,6 +205,8 @@ func (emf *emfExporter) start(_ context.Context, host component.Host) error { return err } + awsConfig.LogLevel = aws.LogLevel(aws.LogDebugWithHTTPBody) + var userAgentExtras []string if emf.config.IsAppSignalsEnabled() { userAgentExtras = append(userAgentExtras, "AppSignals") diff --git a/receiver/awscontainerinsightreceiver/internal/cadvisor/container_info_processor.go b/receiver/awscontainerinsightreceiver/internal/cadvisor/container_info_processor.go index 750c2450e8b9..abe19191ca5f 100644 --- a/receiver/awscontainerinsightreceiver/internal/cadvisor/container_info_processor.go +++ b/receiver/awscontainerinsightreceiver/internal/cadvisor/container_info_processor.go @@ -124,7 +124,7 @@ func processContainer(info *cInfo.ContainerInfo, mInfo extractors.CPUMemInfoProv pKey = &podKey{cgroupPath: podPath, podName: podName, podID: podID, namespace: namespace} tags[ci.PodIDKey] = podID - tags[ci.PodNameKey] = podName + tags[ci.K8sPodNameKey] = podName tags[ci.K8sNamespace] = namespace switch containerName { // For docker, pause container name is set to POD while containerd does not set it. @@ -179,7 +179,7 @@ func processPod(info *cInfo.ContainerInfo, mInfo extractors.CPUMemInfoProvider, tags := map[string]string{} tags[ci.PodIDKey] = podKey.podID - tags[ci.PodNameKey] = podKey.podName + tags[ci.K8sPodNameKey] = podKey.podName tags[ci.K8sNamespace] = podKey.namespace tags[ci.Timestamp] = strconv.FormatInt(extractors.GetStats(info).Timestamp.UnixNano(), 10) diff --git a/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs.go b/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs.go index 38b063868c25..e6a2cd09b512 100644 --- a/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs.go +++ b/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs.go @@ -193,7 +193,7 @@ func (s *Scraper) GetMetrics() []pmetric.Metrics { } for _, m := range podContainerMetrics { m.AddTag(ci.K8sNamespace, containerInfo.Namespace) - m.AddTag(ci.PodNameKey, containerInfo.PodName) + m.AddTag(ci.K8sPodNameKey, containerInfo.PodName) m.AddTag(ci.ContainerNamekey, containerInfo.ContainerName) } diff --git a/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs_test.go b/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs_test.go index f219dd62d95e..8b34796a1805 100644 --- a/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs_test.go +++ b/receiver/awscontainerinsightreceiver/internal/efa/efaSysfs_test.go @@ -132,7 +132,7 @@ var efa0Metrics = []expectation{ ci.MetricType: ci.TypePodEFA, ci.EfaDevice: "efa0", ci.K8sNamespace: "namespace0", - ci.PodNameKey: "pod0", + ci.K8sPodNameKey: "pod0", ci.ContainerNamekey: "container0", ci.Timestamp: "to-be-replaced", "decorated": "true", @@ -151,7 +151,7 @@ var efa0Metrics = []expectation{ ci.MetricType: ci.TypeContainerEFA, ci.EfaDevice: "efa0", ci.K8sNamespace: "namespace0", - ci.PodNameKey: "pod0", + ci.K8sPodNameKey: "pod0", ci.ContainerNamekey: "container0", ci.Timestamp: "to-be-replaced", "decorated": "true", @@ -190,7 +190,7 @@ var efa1PodContainerMetrics = []expectation{ ci.MetricType: ci.TypePodEFA, ci.EfaDevice: "efa1", ci.K8sNamespace: "namespace1", - ci.PodNameKey: "pod1", + ci.K8sPodNameKey: "pod1", ci.ContainerNamekey: "container1", ci.Timestamp: "to-be-replaced", "decorated": "true", @@ -209,7 +209,7 @@ var efa1PodContainerMetrics = []expectation{ ci.MetricType: ci.TypeContainerEFA, ci.EfaDevice: "efa1", ci.K8sNamespace: "namespace1", - ci.PodNameKey: "pod1", + ci.K8sPodNameKey: "pod1", ci.ContainerNamekey: "container1", ci.Timestamp: "to-be-replaced", "decorated": "true", diff --git a/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_config.go b/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_config.go index 414ffcb0be9d..22ba5d8c2f53 100644 --- a/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_config.go +++ b/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_config.go @@ -116,7 +116,7 @@ func getMetricRelabelConfig(hostInfoProvider hostInfoProvider) []*relabel.Config // additional k8s podname for service name and k8s blob decoration { SourceLabels: model.LabelNames{"pod"}, - TargetLabel: ci.PodNameKey, + TargetLabel: ci.K8sPodNameKey, Regex: relabel.MustNewRegexp("(.*)"), Replacement: "${1}", Action: relabel.Replace, diff --git a/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_test.go b/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_test.go index c43ed6b5b04d..27ce3a229974 100644 --- a/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_test.go +++ b/receiver/awscontainerinsightreceiver/internal/gpu/dcgmscraper_test.go @@ -110,7 +110,7 @@ func TestNewDcgmScraperEndToEnd(t *testing.T) { ci.InstanceID: dummyInstanceID, ci.InstanceType: dummyInstanceType, ci.FullPodNameKey: "fullname-hash", - ci.PodNameKey: "fullname-hash", + ci.K8sPodNameKey: "fullname-hash", ci.ContainerNamekey: "main", ci.GpuDevice: "nvidia0", }, @@ -124,7 +124,7 @@ func TestNewDcgmScraperEndToEnd(t *testing.T) { ci.InstanceID: dummyInstanceID, ci.InstanceType: dummyInstanceType, ci.FullPodNameKey: "fullname-hash", - ci.PodNameKey: "fullname-hash", + ci.K8sPodNameKey: "fullname-hash", ci.ContainerNamekey: "main", ci.GpuDevice: "nvidia0", }, diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go index 15de5eb07535..2b33a3bedb0d 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim.go @@ -134,7 +134,7 @@ func (hp *HCSStatsProvider) getPodMetrics() ([]*stores.CIMetricImpl, error) { tags := map[string]string{} tags[ci.PodIDKey] = pod.PodId - tags[ci.PodNameKey] = pod.PodName + tags[ci.K8sPodNameKey] = pod.PodName tags[ci.K8sNamespace] = pod.PodNamespace for _, container := range pod.Containers { diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go index 2d02e525bdfc..659ebbb4b756 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/hcsshim/hcsshim_test.go @@ -146,7 +146,7 @@ func TestGetPodMetrics(t *testing.T) { podMetric := metrics[0] assert.Equal(t, ci.TypePodNet, podMetric.GetMetricType()) assert.NotNil(t, podMetric.GetTag(ci.PodIDKey)) - assert.NotNil(t, podMetric.GetTag(ci.PodNameKey)) + assert.NotNil(t, podMetric.GetTag(ci.K8sPodNameKey)) assert.NotNil(t, podMetric.GetTag(ci.K8sNamespace)) assert.NotNil(t, podMetric.GetTag(ci.Timestamp)) assert.NotNil(t, podMetric.GetTag(ci.SourcesKey)) diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go index db4314cced58..ef17ad57a41a 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet.go @@ -83,7 +83,7 @@ func (sp *SummaryProvider) getContainerMetrics(pod stats.PodStats) ([]*stores.CI tags := map[string]string{} tags[ci.PodIDKey] = pod.PodRef.UID - tags[ci.PodNameKey] = pod.PodRef.Name + tags[ci.K8sPodNameKey] = pod.PodRef.Name tags[ci.K8sNamespace] = pod.PodRef.Namespace tags[ci.ContainerNamekey] = container.Name containerID := fmt.Sprintf("%s-%s", pod.PodRef.UID, container.Name) @@ -119,7 +119,7 @@ func (sp *SummaryProvider) getPodMetrics(summary *stats.Summary) ([]*stores.CIMe tags := map[string]string{} tags[ci.PodIDKey] = pod.PodRef.UID - tags[ci.PodNameKey] = pod.PodRef.Name + tags[ci.K8sPodNameKey] = pod.PodRef.Name tags[ci.K8sNamespace] = pod.PodRef.Namespace rawMetric := extractors.ConvertPodToRaw(pod) diff --git a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go index 233e11a86f79..67fac8bc09c0 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go +++ b/receiver/awscontainerinsightreceiver/internal/k8swindows/kubelet/kubelet_test.go @@ -67,7 +67,7 @@ func TestGetPodMetrics(t *testing.T) { podMetric := metrics[1] assert.Equal(t, ci.TypePod, podMetric.GetMetricType()) assert.NotNil(t, podMetric.GetTag(ci.PodIDKey)) - assert.NotNil(t, podMetric.GetTag(ci.PodNameKey)) + assert.NotNil(t, podMetric.GetTag(ci.K8sPodNameKey)) assert.NotNil(t, podMetric.GetTag(ci.K8sNamespace)) assert.NotNil(t, podMetric.GetTag(ci.Timestamp)) assert.NotNil(t, podMetric.GetTag(ci.SourcesKey)) @@ -75,7 +75,7 @@ func TestGetPodMetrics(t *testing.T) { containerMetric := metrics[len(metrics)-1] assert.Equal(t, ci.TypeContainer, containerMetric.GetMetricType()) assert.NotNil(t, containerMetric.GetTag(ci.PodIDKey)) - assert.NotNil(t, containerMetric.GetTag(ci.PodNameKey)) + assert.NotNil(t, containerMetric.GetTag(ci.K8sPodNameKey)) assert.NotNil(t, containerMetric.GetTag(ci.K8sNamespace)) assert.NotNil(t, containerMetric.GetTag(ci.Timestamp)) assert.NotNil(t, containerMetric.GetTag(ci.ContainerNamekey)) @@ -97,7 +97,7 @@ func TestGetContainerMetrics(t *testing.T) { containerMetric := metrics[1] assert.Equal(t, ci.TypeContainer, containerMetric.GetMetricType()) assert.NotNil(t, containerMetric.GetTag(ci.PodIDKey)) - assert.NotNil(t, containerMetric.GetTag(ci.PodNameKey)) + assert.NotNil(t, containerMetric.GetTag(ci.K8sPodNameKey)) assert.NotNil(t, containerMetric.GetTag(ci.K8sNamespace)) assert.NotNil(t, containerMetric.GetTag(ci.Timestamp)) assert.NotNil(t, containerMetric.GetTag(ci.ContainerNamekey)) diff --git a/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator.go b/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator.go index 76e9b8b09caf..a75cd6d5bb70 100644 --- a/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator.go +++ b/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator.go @@ -120,7 +120,7 @@ func (pdc *PodAttributesDecoratorConsumer) getContainerInfoForNeuronDeviceIndex( func populateAttributes(attributes *pcommon.Map, containerInfo *stores.ContainerInfo) { if containerInfo != nil { attributes.PutStr(ci.ContainerNamekey, containerInfo.ContainerName) - attributes.PutStr(ci.PodNameKey, containerInfo.PodName) + attributes.PutStr(ci.K8sPodNameKey, containerInfo.PodName) attributes.PutStr(ci.K8sNamespace, containerInfo.Namespace) } } diff --git a/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator_test.go b/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator_test.go index ea2bf8a60a12..6829134918af 100644 --- a/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator_test.go +++ b/receiver/awscontainerinsightreceiver/internal/neuron/pod_attribute_decorator_test.go @@ -104,7 +104,7 @@ func TestConsumeMetricsForPodAttributeDecorator(t *testing.T) { "device": "test0", neuronDeviceAttributeKey: "1", ci.ContainerNamekey: dummyContainerName, - ci.PodNameKey: dummyPodName, + ci.K8sPodNameKey: dummyPodName, ci.K8sNamespace: dummyNamespace, }, }, @@ -137,7 +137,7 @@ func TestConsumeMetricsForPodAttributeDecorator(t *testing.T) { neuronCoreAttributeKey: "10", neuronDeviceAttributeKey: "5", ci.ContainerNamekey: dummyContainerName, - ci.PodNameKey: dummyPodName, + ci.K8sPodNameKey: dummyPodName, ci.K8sNamespace: dummyNamespace, }, }, @@ -171,7 +171,7 @@ func TestConsumeMetricsForPodAttributeDecorator(t *testing.T) { neuronCoreAttributeKey: "10", neuronDeviceAttributeKey: "5", ci.ContainerNamekey: dummyContainerName, - ci.PodNameKey: dummyPodName, + ci.K8sPodNameKey: dummyPodName, ci.K8sNamespace: dummyNamespace, }, }, @@ -214,7 +214,7 @@ func TestConsumeMetricsForPodAttributeDecorator(t *testing.T) { "device": "test0", neuronDeviceAttributeKey: "1", ci.ContainerNamekey: dummyContainerName, - ci.PodNameKey: dummyPodNameForAltResource, + ci.K8sPodNameKey: dummyPodNameForAltResource, ci.K8sNamespace: dummyNamespace, }, }, diff --git a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go index 2de7a1c91fb6..d14fedc3a1fc 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go @@ -218,7 +218,7 @@ func (p *PodStore) RefreshTick(ctx context.Context) { func (p *PodStore) Decorate(ctx context.Context, metric CIMetric, kubernetesBlob map[string]any) bool { if metric.GetTag(ci.MetricType) == ci.TypeNode { p.decorateNode(metric) - } else if metric.GetTag(ci.PodNameKey) != "" { + } else if metric.GetTag(ci.K8sPodNameKey) != "" { podKey := createPodKeyFromMetric(metric) if podKey == "" { p.logger.Error("podKey is unavailable when decorating pod") diff --git a/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go b/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go index 8f4aee2abb4f..8aba3958a155 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go @@ -310,7 +310,7 @@ func TestPodStore_previousCleanupLocking(_ *testing.T) { pod := getBaseTestPodInfo() ctx := context.TODO() - tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} metric := generateMetric(fields, tags) @@ -451,7 +451,7 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { containerCopy.Name = "ubuntu2" pod.Status.ContainerStatuses = append(pod.Status.ContainerStatuses, containerCopy) - tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} podStore := getPodStore() podStore.includeEnhancedMetrics = true @@ -464,21 +464,21 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { assert.Nil(t, val) // set up container defaults - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, "Running", metric.GetTag(ci.ContainerStatus)) val = metric.GetField(ci.ContainerRestartCount) assert.Nil(t, val) // set up the other container - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu2"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu2"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, "Running", metric.GetTag(ci.ContainerStatus)) val = metric.GetField(ci.ContainerRestartCount) assert.Nil(t, val) - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -499,7 +499,7 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[1].RestartCount = 1 pod.Status.Phase = "Succeeded" - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -508,18 +508,18 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { // update the container metrics // set up container defaults - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, 1, metric.GetField(ci.ContainerRestartCount)) // test the other container - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu2"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu2"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, 1, metric.GetField(ci.ContainerRestartCount)) - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -531,7 +531,7 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[1].LastTerminationState.Terminated = nil pod.Status.ContainerStatuses[1].State.Waiting = &corev1.ContainerStateWaiting{Reason: "CrashLoopBackOff"} - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -547,7 +547,7 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[0].State.Waiting = &corev1.ContainerStateWaiting{Reason: "ImagePullBackOff"} pod.Status.ContainerStatuses[1].State.Waiting = &corev1.ContainerStateWaiting{Reason: "StartError"} - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -584,13 +584,13 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { // test delta of restartCount pod.Status.ContainerStatuses[0].RestartCount = 3 - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, 2, metric.GetField(ci.MetricName(ci.TypePod, ci.ContainerRestartCount))) - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -599,7 +599,7 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { pod := getBaseTestPodInfo() - tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} podStore := getPodStore() podStore.includeEnhancedMetrics = false @@ -610,7 +610,7 @@ func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { val := metric.GetField(ci.MetricName(ci.TypePod, ci.ContainerRestartCount)) assert.Nil(t, val) - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -625,14 +625,14 @@ func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[0].RestartCount = 1 pod.Status.Phase = "Succeeded" - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, "Succeeded", metric.GetTag(ci.PodStatus)) assert.Equal(t, int(1), metric.GetField(ci.MetricName(ci.TypePod, ci.ContainerRestartCount)).(int)) - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -644,7 +644,7 @@ func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[0].State.Terminated = nil pod.Status.ContainerStatuses[0].State.Waiting = &corev1.ContainerStateWaiting{Reason: "CrashLoopBackOff"} - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -654,7 +654,7 @@ func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { pod.Status.ContainerStatuses[0].State.Waiting = &corev1.ContainerStateWaiting{Reason: "SomeOtherReason"} - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -664,13 +664,13 @@ func TestPodStore_addStatus_without_enhanced_metrics(t *testing.T) { // test delta of restartCount pod.Status.ContainerStatuses[0].RestartCount = 3 - tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags = map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) assert.Equal(t, int(2), metric.GetField(ci.MetricName(ci.TypePod, ci.ContainerRestartCount)).(int)) - tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} + tags = map[string]string{ci.MetricType: ci.TypeContainer, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit", ci.ContainerNamekey: "ubuntu"} metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) @@ -1070,7 +1070,7 @@ func TestPodStore_Decorate(t *testing.T) { tags = map[string]string{ ci.ContainerNamekey: "testContainer", ci.PodIDKey: "123", - ci.PodNameKey: "testPod", + ci.K8sPodNameKey: "testPod", // ci.K8sNamespace: "testNamespace", ci.TypeService: "testService", ci.NodeNameKey: "testNode", @@ -1084,7 +1084,7 @@ func TestPodStore_Decorate(t *testing.T) { // metric with pod info not in cache tags = map[string]string{ ci.ContainerNamekey: "testContainer", - ci.PodNameKey: "testPod", + ci.K8sPodNameKey: "testPod", ci.PodIDKey: "123", ci.K8sNamespace: "testNamespace", ci.TypeService: "testService", @@ -1124,7 +1124,7 @@ func generatePodInfo(sourceFileName string) *corev1.Pod { } func generateRawCIMetric() CIMetric { - tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.PodNameKey: "cpu-limit"} + tags := map[string]string{ci.MetricType: ci.TypePod, ci.K8sNamespace: "default", ci.K8sPodNameKey: "cpu-limit"} fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} return generateMetric(fields, tags) } diff --git a/receiver/awscontainerinsightreceiver/internal/stores/servicestore.go b/receiver/awscontainerinsightreceiver/internal/stores/servicestore.go index 64e15f257ac8..88882e7eeb0c 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/servicestore.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/servicestore.go @@ -59,7 +59,7 @@ func (s *ServiceStore) RefreshTick(ctx context.Context) { // Decorate decorates metrics and update kubernetesBlob // service info is not mandatory func (s *ServiceStore) Decorate(_ context.Context, metric CIMetric, _ map[string]any) bool { - if metric.HasTag(ci.PodNameKey) { + if metric.HasTag(ci.K8sPodNameKey) { podKey := createPodKeyFromMetric(metric) if podKey == "" { s.logger.Error("podKey is unavailable when decorating service.", zap.Any("podKey", podKey)) diff --git a/receiver/awscontainerinsightreceiver/internal/stores/servicestore_test.go b/receiver/awscontainerinsightreceiver/internal/stores/servicestore_test.go index 6c50f885df66..b1f7ec7a6574 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/servicestore_test.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/servicestore_test.go @@ -36,8 +36,8 @@ func TestServiceStore(t *testing.T) { // test the case when it decorates metrics successfully metric := &mockCIMetric{ tags: map[string]string{ - ci.PodNameKey: "test-pod", - ci.K8sNamespace: "default", + ci.K8sPodNameKey: "test-pod", + ci.K8sNamespace: "default", }, } kubernetesBlob := map[string]any{} @@ -48,7 +48,7 @@ func TestServiceStore(t *testing.T) { // test the case when it fails to decorate metrics metric = &mockCIMetric{ tags: map[string]string{ - ci.PodNameKey: "test-pod", + ci.K8sPodNameKey: "test-pod", }, } kubernetesBlob = map[string]any{} diff --git a/receiver/awscontainerinsightreceiver/internal/stores/utils.go b/receiver/awscontainerinsightreceiver/internal/stores/utils.go index aed810d28cb9..1b0df410e9b2 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/utils.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/utils.go @@ -33,13 +33,13 @@ func createPodKeyFromMetaData(pod *corev1.Pod) string { func createPodKeyFromMetric(metric CIMetric) string { namespace := metric.GetTag(ci.K8sNamespace) - podName := metric.GetTag(ci.PodNameKey) + podName := metric.GetTag(ci.K8sPodNameKey) return k8sutil.CreatePodKey(namespace, podName) } func createContainerKeyFromMetric(metric CIMetric) string { namespace := metric.GetTag(ci.K8sNamespace) - podName := metric.GetTag(ci.PodNameKey) + podName := metric.GetTag(ci.K8sPodNameKey) containerName := metric.GetTag(ci.ContainerNamekey) return k8sutil.CreateContainerKey(namespace, podName, containerName) } @@ -193,7 +193,7 @@ func tagMetricSourceWindows(metric CIMetric) { } func AddKubernetesInfo(metric CIMetric, kubernetesBlob map[string]any, retainContainerNameTag bool) { - needMoveToKubernetes := map[string]string{ci.PodNameKey: "pod_name", ci.PodIDKey: "pod_id"} + needMoveToKubernetes := map[string]string{ci.K8sPodNameKey: "pod_name", ci.PodIDKey: "pod_id"} needCopyToKubernetes := map[string]string{ci.K8sNamespace: "namespace_name", ci.TypeService: "service_name", ci.NodeNameKey: "host"} if retainContainerNameTag { diff --git a/receiver/awscontainerinsightreceiver/internal/stores/utils_test.go b/receiver/awscontainerinsightreceiver/internal/stores/utils_test.go index 89620d3522ce..98f1b1d817b5 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/utils_test.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/utils_test.go @@ -131,7 +131,7 @@ func TestUtils_addKubernetesInfo(t *testing.T) { fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} tags := map[string]string{ ci.ContainerNamekey: "testContainer", - ci.PodNameKey: "testPod", + ci.K8sPodNameKey: "testPod", ci.PodIDKey: "123", ci.K8sNamespace: "testNamespace", ci.TypeService: "testService", @@ -147,7 +147,7 @@ func TestUtils_addKubernetesInfo(t *testing.T) { kubernetesBlob := map[string]any{} AddKubernetesInfo(metric, kubernetesBlob, false) assert.Equal(t, "", metric.GetTag(ci.ContainerNamekey)) - assert.Equal(t, "", metric.GetTag(ci.PodNameKey)) + assert.Equal(t, "", metric.GetTag(ci.K8sPodNameKey)) assert.Equal(t, "", metric.GetTag(ci.PodIDKey)) assert.Equal(t, "testNamespace", metric.GetTag(ci.K8sNamespace)) assert.Equal(t, "testService", metric.GetTag(ci.TypeService)) @@ -161,7 +161,7 @@ func TestUtils_addKubernetesInfoRetainContainerNameTag(t *testing.T) { fields := map[string]any{ci.MetricName(ci.TypePod, ci.CPUTotal): float64(1)} tags := map[string]string{ ci.ContainerNamekey: "testContainer", - ci.PodNameKey: "testPod", + ci.K8sPodNameKey: "testPod", ci.PodIDKey: "123", ci.K8sNamespace: "testNamespace", ci.TypeService: "testService", @@ -177,7 +177,7 @@ func TestUtils_addKubernetesInfoRetainContainerNameTag(t *testing.T) { kubernetesBlob := map[string]any{} AddKubernetesInfo(metric, kubernetesBlob, true) assert.Equal(t, "testContainer", metric.GetTag(ci.ContainerNamekey)) - assert.Equal(t, "", metric.GetTag(ci.PodNameKey)) + assert.Equal(t, "", metric.GetTag(ci.K8sPodNameKey)) assert.Equal(t, "", metric.GetTag(ci.PodIDKey)) assert.Equal(t, "testNamespace", metric.GetTag(ci.K8sNamespace)) assert.Equal(t, "testService", metric.GetTag(ci.TypeService))