Skip to content

Commit

Permalink
[exporter/awsemf] Drop redundant arg from addToGroupedMetric (#30813)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
The `addToGroupedMetric` previously took the logger as well as the
config as arguments. However, the logger is already available as a field
in the config so it is redundant to pass it separately.

This commit removes the logger argument.

**Testing:** 
The affected unit tests were updated
  • Loading branch information
arjunmahishi authored Feb 9, 2024
1 parent 5dc8c45 commit debaf05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
16 changes: 12 additions & 4 deletions exporter/awsemfexporter/grouped_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 7 additions & 13 deletions exporter/awsemfexporter/grouped_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -277,7 +274,7 @@ func TestAddToGroupedMetric(t *testing.T) {
err := addToGroupedMetric(metric,
groupedMetrics,
metricMetadata1,
true, logger,
true,
nil,
testCfg,
emfCalcs)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit debaf05

Please sign in to comment.