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

Fix RAT processor only copying to first metric #159

Merged
merged 2 commits into from
Jan 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p resourceAttributeTransposerProcessor) ConsumeMetrics(ctx context.Context
ilm := ilms.At(j)
metrics := ilm.Metrics()
for k := 0; k < metrics.Len(); k++ {
metric := metrics.At(j)
metric := metrics.At(k)
setMetricAttr(metric, op.To, resourceValue)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,56 @@ func TestConsumeMetricsMoveExistingAttribs(t *testing.T) {
}, getMetricAttrsFromMetrics(metricsOut))
}

func TestConsumeMetricsMoveToMultipleMetrics(t *testing.T) {
ctx := context.Background()
metrics := createMetrics()

attrs := metrics.ResourceMetrics().At(0).Resource().Attributes()
attrs.Insert("resourceattrib1", pdata.NewAttributeValueString("value"))

var metricsOut pdata.Metrics

consumer := &mockConsumer{}
consumer.On("ConsumeMetrics", ctx, metrics).Run(func(args mock.Arguments) {
metricsOut = args[1].(pdata.Metrics)
}).Return(nil)

cfg := createDefaultConfig().(*Config)
cfg.Operations = []CopyResourceConfig{
{
From: "resourceattrib1",
To: "resourceattrib1",
},
}

p := newResourceAttributeTransposerProcessor(
zap.NewNop(),
consumer,
cfg,
)
metricsSlice := getMetricSlice(metrics)
metric1 := metricsSlice.At(0)
metric1.SetDataType(pdata.MetricDataTypeGauge)
dp1 := metric1.Gauge().DataPoints()
dp1.AppendEmpty().SetDoubleVal(3.0)

metric2 := metricsSlice.AppendEmpty()
metric2.SetDataType(pdata.MetricDataTypeGauge)
dp2 := metric2.Gauge().DataPoints()
dp2.AppendEmpty().SetDoubleVal(3.0)

err := p.ConsumeMetrics(ctx, metrics)
require.NoError(t, err)

require.Equal(t, map[string]interface{}{
"resourceattrib1": "value",
}, getMetricAttrsFromMetric(getMetricSlice(metricsOut).At(0)))

require.Equal(t, map[string]interface{}{
"resourceattrib1": "value",
}, getMetricAttrsFromMetric(getMetricSlice(metricsOut).At(1)))
}

func TestConsumeMetricsMixedExistence(t *testing.T) {
ctx := context.Background()
metrics := createMetrics()
Expand Down Expand Up @@ -470,8 +520,12 @@ func (m *mockConsumer) Shutdown(ctx context.Context) error {
return args.Error(0)
}

func getMetricSlice(m pdata.Metrics) pdata.MetricSlice {
return m.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics()
}

func getMetric(m pdata.Metrics) pdata.Metric {
return m.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0)
return getMetricSlice(m).At(0)
}

func createMetrics() pdata.Metrics {
Expand Down