Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
  • Loading branch information
musa-asad committed Feb 6, 2025
1 parent 50fcb37 commit 1ee3543
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 1 addition & 3 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
labels := map[string]string{}
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)
fmt.Printf("Before AddEntity - Attributes: %v\n", rm.Resource().Attributes().AsRaw())
entity.AddEntity(&rm)
fmt.Printf("After AddEntity - Attributes: %v\n", rm.Resource().Attributes().AsRaw())
am := rm.Resource().Attributes()
entity.AddEntity(am)
if am.Len() > 0 {
am.Range(func(k string, v pcommon.Value) bool {
labels[k] = v.Str()
Expand Down
18 changes: 9 additions & 9 deletions exporter/awsemfexporter/internal/entity/entityattributes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package entity

import (
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pcommon"
)

const (
Expand Down Expand Up @@ -49,29 +49,29 @@ var attributeEntityToFieldMap = map[string]string{
AttributeEntityServiceNameSource: AWSServiceNameSource,
}

func AddEntity(rm *pmetric.ResourceMetrics) {
func AddEntity(am pcommon.Map) {
// Check if all resource attributes for entity exist, otherwise don't add entity
for internalAttr := range attributeEntityToFieldMap {
if _, found := rm.Resource().Attributes().Get(internalAttr); !found {
if _, found := am.Get(internalAttr); !found {
return
}
}

if _, found := rm.Resource().Attributes().Get(AttributeEntityK8sClusterName); !found {
if _, found := am.Get(AttributeEntityK8sClusterName); !found {
return
}

// Populate resource attributes with entity fields
for internalAttr, entityField := range attributeEntityToFieldMap {
val, _ := rm.Resource().Attributes().Get(internalAttr)
val.CopyTo(rm.Resource().Attributes().PutEmpty(entityField))
val, _ := am.Get(internalAttr)
val.CopyTo(am.PutEmpty(entityField))
}

val, _ := rm.Resource().Attributes().Get(AttributeEntityK8sClusterName)
val, _ := am.Get(AttributeEntityK8sClusterName)
switch val.Str() {
case AttributeEntityEKSPlatform:
val.CopyTo(rm.Resource().Attributes().PutEmpty(EksCluster))
val.CopyTo(am.PutEmpty(EksCluster))
case AttributeEntityK8sPlatform:
val.CopyTo(rm.Resource().Attributes().PutEmpty(K8sCluster))
val.CopyTo(am.PutEmpty(K8sCluster))
}
}

0 comments on commit 1ee3543

Please sign in to comment.