Skip to content

[awsemfexporter] Fix grouping for container insights metrics for mixed metric types #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 13, 2025
Merged
9 changes: 9 additions & 0 deletions exporter/awsemfexporter/grouped_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
// them together into one EMF log event, so don't set batchIndex when it's a summary metric
metadata.batchIndex = i
}

// Handle metric types with container insights
if metadata.receiver == containerInsightsReceiver {
// For container insights, treat gauge metrics as sum
if metadata.groupedMetricMetadata.metricDataType == pmetric.MetricTypeGauge {

Check failure on line 98 in exporter/awsemfexporter/grouped_metric.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, exporter-0)

QF1008: could remove embedded field "groupedMetricMetadata" from selector (staticcheck)

Check failure on line 98 in exporter/awsemfexporter/grouped_metric.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, exporter-0)

QF1008: could remove embedded field "groupedMetricMetadata" from selector (staticcheck)
metadata.groupedMetricMetadata.metricDataType = pmetric.MetricTypeSum

Check failure on line 99 in exporter/awsemfexporter/grouped_metric.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, exporter-0)

QF1008: could remove embedded field "groupedMetricMetadata" from selector (staticcheck)

Check failure on line 99 in exporter/awsemfexporter/grouped_metric.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, exporter-0)

QF1008: could remove embedded field "groupedMetricMetadata" from selector (staticcheck)
}
}

groupKey := aws.NewKey(metadata.groupedMetricMetadata, labels)
if _, ok := groupedMetrics[groupKey]; ok {
// if MetricName already exists in metrics map, print warning log
Expand Down
3 changes: 2 additions & 1 deletion exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri
if strings.HasPrefix(serviceName.Str(), "containerInsightsKubeAPIServerScraper") ||
strings.HasPrefix(serviceName.Str(), "containerInsightsDCGMExporterScraper") ||
strings.HasPrefix(serviceName.Str(), "containerInsightsNeuronMonitorScraper") ||
strings.HasPrefix(serviceName.Str(), "containerInsightsKueueMetricsScraper") {
strings.HasPrefix(serviceName.Str(), "containerInsightsKueueMetricsScraper") ||
strings.HasPrefix(serviceName.Str(), "containerInsightsNVMeExporterScraper") {
// the prometheus metrics that come from the container insight receiver need to be clearly tagged as coming from container insights
metricReceiver = containerInsightsReceiver
}
Expand Down
37 changes: 37 additions & 0 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@
neuronMetric.Resource().Attributes().PutStr(conventions.AttributeServiceName, "containerInsightsNeuronMonitorScraper")
kueueMetric := createTestResourceMetricsHelper(defaultNumberOfTestMetrics + 1)
kueueMetric.Resource().Attributes().PutStr(conventions.AttributeServiceName, "containerInsightsKueueMetricsScraper")
nvmeMetric := createTestResourceMetricsHelper(defaultNumberOfTestMetrics + 1)
nvmeMetric.Resource().Attributes().PutStr(conventions.AttributeServiceName, "containerInsightsNVMeExporterScraper")

counterSumMetrics := map[string]*metricInfo{
"spanCounter": {
Expand Down Expand Up @@ -395,6 +397,32 @@
"myServiceNS/containerInsightsKueueMetricsScraper",
containerInsightsReceiver,
},
{
"nvme receiver",
nvmeMetric,
map[string]string{
"isItAnError": "false",
"spanName": "testSpan",
},
map[string]string{
"spanName": "testSpan",
},
"myServiceNS/containerInsightsNVMeExporterScraper",
containerInsightsReceiver,
},
{
"container insights gauge/sum metrics",
containerInsightMetric,
map[string]string{
"isItAnError": "false",
"spanName": "testSpan",
},
map[string]string{
"spanName": "testSpan",
},
"myServiceNS/containerInsightsKubeAPIServerScraper",
containerInsightsReceiver,
},
}

for _, tc := range testCases {
Expand All @@ -416,6 +444,15 @@
}
}


Check failure on line 447 in exporter/awsemfexporter/metric_translator_test.go

View workflow job for this annotation

GitHub Actions / lint-matrix (windows, exporter-0)

File is not properly formatted (gci)

Check failure on line 447 in exporter/awsemfexporter/metric_translator_test.go

View workflow job for this annotation

GitHub Actions / lint-matrix (linux, exporter-0)

File is not properly formatted (gci)
if tc.expectedReceiver == containerInsightsReceiver {
assert.Equal(t, pmetric.MetricTypeSum, v.metadata.metricDataType)
assert.True(t, reflect.DeepEqual(counterSumMetrics, v.metrics) ||
reflect.DeepEqual(counterGaugeMetrics, v.metrics),
)
continue
}

switch v.metadata.metricDataType {
case pmetric.MetricTypeSum:
assert.Len(t, v.metrics, 2)
Expand Down
Loading