diff --git a/exporter/awsemfexporter/grouped_metric.go b/exporter/awsemfexporter/grouped_metric.go index a3094d6a2c43..dd3426cdc2e9 100644 --- a/exporter/awsemfexporter/grouped_metric.go +++ b/exporter/awsemfexporter/grouped_metric.go @@ -27,9 +27,17 @@ type metricInfo struct { } // addToGroupedMetric processes OT metrics and adds them into GroupedMetric buckets -func addToGroupedMetric(pmd pmetric.Metric, groupedMetrics map[any]*groupedMetric, metadata cWMetricMetadata, patternReplaceSucceeded bool, logger *zap.Logger, descriptor map[string]MetricDescriptor, config *Config, calculators *emfCalculators) error { - - dps := getDataPoints(pmd, metadata, logger) +func addToGroupedMetric( + pmd pmetric.Metric, + groupedMetrics map[any]*groupedMetric, + metadata cWMetricMetadata, + patternReplaceSucceeded bool, + descriptor map[string]MetricDescriptor, + config *Config, + calculators *emfCalculators, +) error { + + dps := getDataPoints(pmd, metadata, config.logger) if dps == nil || dps.Len() == 0 { return nil } @@ -83,7 +91,7 @@ func addToGroupedMetric(pmd pmetric.Metric, groupedMetrics map[any]*groupedMetri if _, ok := groupedMetrics[groupKey]; ok { // if MetricName already exists in metrics map, print warning log if _, ok := groupedMetrics[groupKey].metrics[dp.name]; ok { - logger.Warn( + config.logger.Warn( "Duplicate metric found", zap.String("Name", dp.name), zap.Any("Labels", labels), diff --git a/exporter/awsemfexporter/grouped_metric_test.go b/exporter/awsemfexporter/grouped_metric_test.go index ca6483b9303e..dbbb7dfb1c97 100644 --- a/exporter/awsemfexporter/grouped_metric_test.go +++ b/exporter/awsemfexporter/grouped_metric_test.go @@ -27,7 +27,6 @@ func TestAddToGroupedMetric(t *testing.T) { namespace := "namespace" instrumentationLibName := "cloudwatch-otel" timestamp := time.Now().UnixNano() / int64(time.Millisecond) - logger := zap.NewNop() testCases := []struct { name string @@ -110,7 +109,7 @@ func TestAddToGroupedMetric(t *testing.T) { for i := 0; i < metrics.Len(); i++ { err := addToGroupedMetric(metrics.At(i), groupedMetrics, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(i).Type()), - true, zap.NewNop(), + true, nil, testCfg, emfCalcs) @@ -153,7 +152,6 @@ func TestAddToGroupedMetric(t *testing.T) { groupedMetrics, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(i).Type()), true, - logger, nil, testCfg, emfCalcs) @@ -226,7 +224,6 @@ func TestAddToGroupedMetric(t *testing.T) { groupedMetrics, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(i).Type()), true, - logger, nil, testCfg, emfCalcs) @@ -277,7 +274,7 @@ func TestAddToGroupedMetric(t *testing.T) { err := addToGroupedMetric(metric, groupedMetrics, metricMetadata1, - true, logger, + true, nil, testCfg, emfCalcs) @@ -290,7 +287,7 @@ func TestAddToGroupedMetric(t *testing.T) { instrumentationLibName, metric.Type(), ) - err = addToGroupedMetric(metric, groupedMetrics, metricMetadata2, true, logger, nil, testCfg, emfCalcs) + err = addToGroupedMetric(metric, groupedMetrics, metricMetadata2, true, nil, testCfg, emfCalcs) assert.NoError(t, err) assert.Len(t, groupedMetrics, 2) @@ -338,13 +335,13 @@ func TestAddToGroupedMetric(t *testing.T) { assert.Equal(t, 2, metrics.Len()) obs, logs := observer.New(zap.WarnLevel) - obsLogger := zap.New(obs) + testCfg.logger = zap.New(obs) for i := 0; i < metrics.Len(); i++ { err := addToGroupedMetric(metrics.At(i), groupedMetrics, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(i).Type()), - true, obsLogger, + true, nil, testCfg, emfCalcs, @@ -382,12 +379,11 @@ func TestAddToGroupedMetric(t *testing.T) { metric.SetUnit("Count") obs, logs := observer.New(zap.WarnLevel) - obsLogger := zap.New(obs) + testCfg.logger = zap.New(obs) err := addToGroupedMetric(metric, groupedMetrics, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, pmetric.MetricTypeEmpty), true, - obsLogger, nil, testCfg, emfCalcs, @@ -460,14 +456,12 @@ func BenchmarkAddToGroupedMetric(b *testing.B) { metrics := rms.At(0).ScopeMetrics().At(0).Metrics() numMetrics := metrics.Len() - logger := zap.NewNop() - b.ResetTimer() for n := 0; n < b.N; n++ { groupedMetrics := make(map[any]*groupedMetric) for i := 0; i < numMetrics; i++ { metadata := generateTestMetricMetadata("namespace", int64(1596151098037), "log-group", "log-stream", "cloudwatch-otel", metrics.At(i).Type()) - err := addToGroupedMetric(metrics.At(i), groupedMetrics, metadata, true, logger, nil, testCfg, emfCalcs) + err := addToGroupedMetric(metrics.At(i), groupedMetrics, metadata, true, nil, testCfg, emfCalcs) assert.Nil(b, err) } } diff --git a/exporter/awsemfexporter/metric_translator.go b/exporter/awsemfexporter/metric_translator.go index fbd601a33725..26aba7bd368e 100644 --- a/exporter/awsemfexporter/metric_translator.go +++ b/exporter/awsemfexporter/metric_translator.go @@ -145,7 +145,7 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri instrumentationScopeName: instrumentationScopeName, receiver: metricReceiver, } - err := addToGroupedMetric(metric, groupedMetrics, metadata, patternReplaceSucceeded, config.logger, mt.metricDescriptor, config, mt.calculators) + err := addToGroupedMetric(metric, groupedMetrics, metadata, patternReplaceSucceeded, mt.metricDescriptor, config, mt.calculators) if err != nil { return err }