Skip to content

Commit

Permalink
Correct erroneuous use of PodNameKey
Browse files Browse the repository at this point in the history
  • Loading branch information
dricross committed Jan 8, 2025
1 parent 2daedb1 commit 9b98910
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 58 deletions.
3 changes: 3 additions & 0 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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))

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))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 9b98910

Please sign in to comment.