Skip to content
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

[exporter/awsemf] Drop redundant arg from addToGroupedMetric #30813

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading