Skip to content

Commit

Permalink
Change processor tests to use the new metrics internal structs (#1680)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Aug 31, 2020
1 parent 6e05a9a commit 6a0d262
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 6 additions & 7 deletions processor/cloningfanoutconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/dataold/testdataold"
)

func TestTraceProcessorCloningNotMultiplexing(t *testing.T) {
Expand Down Expand Up @@ -83,12 +82,12 @@ func TestMetricsProcessorCloningMultiplexing(t *testing.T) {
}

mfc := NewMetricsCloningFanOutConnector(processors)
md := testdataold.GenerateMetricDataWithCountersHistogramAndSummary()
md := testdata.GenerateMetricsWithCountersHistograms()

var wantMetricsCount = 0
for i := 0; i < 2; i++ {
wantMetricsCount += md.MetricCount()
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromOldInternalMetrics(md))
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromInternalMetrics(md))
if err != nil {
t.Errorf("Wanted nil got error")
return
Expand All @@ -100,15 +99,15 @@ func TestMetricsProcessorCloningMultiplexing(t *testing.T) {
assert.Equal(t, wantMetricsCount, m.MetricsCount())
metricOrig := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0)
allMetrics := m.AllMetrics()
metricClone := pdatautil.MetricsToOldInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0)
metricClone := pdatautil.MetricsToInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0)
if i < len(processors)-1 {
assert.True(t, md.ResourceMetrics().At(0).Resource() != pdatautil.MetricsToOldInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.True(t, md.ResourceMetrics().At(0).Resource() != pdatautil.MetricsToInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.True(t, metricOrig != metricClone)
} else {
assert.True(t, md.ResourceMetrics().At(0).Resource() == pdatautil.MetricsToOldInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.True(t, md.ResourceMetrics().At(0).Resource() == pdatautil.MetricsToInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.True(t, metricOrig == metricClone)
}
assert.EqualValues(t, md.ResourceMetrics().At(0).Resource(), pdatautil.MetricsToOldInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.EqualValues(t, md.ResourceMetrics().At(0).Resource(), pdatautil.MetricsToInternalMetrics(allMetrics[0]).ResourceMetrics().At(0).Resource())
assert.EqualValues(t, metricOrig, metricClone)
}
}
Expand Down
11 changes: 5 additions & 6 deletions processor/fanoutconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/dataold/testdataold"
)

func TestTracesProcessorNotMultiplexing(t *testing.T) {
Expand Down Expand Up @@ -100,12 +99,12 @@ func TestMetricsProcessorMultiplexing(t *testing.T) {
}

mfc := NewMetricsFanOutConnector(processors)
md := testdataold.GenerateMetricDataOneMetric()
md := testdata.GenerateMetricsOneMetric()

var wantMetricsCount = 0
for i := 0; i < 2; i++ {
wantMetricsCount += md.MetricCount()
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromOldInternalMetrics(md))
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromInternalMetrics(md))
if err != nil {
t.Errorf("Wanted nil got error")
return
Expand All @@ -115,7 +114,7 @@ func TestMetricsProcessorMultiplexing(t *testing.T) {
for _, p := range processors {
m := p.(*exportertest.SinkMetricsExporter)
assert.Equal(t, wantMetricsCount, m.MetricsCount())
assert.EqualValues(t, md, pdatautil.MetricsToOldInternalMetrics(m.AllMetrics()[0]))
assert.EqualValues(t, md, pdatautil.MetricsToInternalMetrics(m.AllMetrics()[0]))
}
}

Expand All @@ -129,12 +128,12 @@ func TestMetricsProcessorWhenOneErrors(t *testing.T) {
processors[1].(*exportertest.SinkMetricsExporter).SetConsumeMetricsError(errors.New("my_error"))

mfc := NewMetricsFanOutConnector(processors)
md := testdataold.GenerateMetricDataOneMetric()
md := testdata.GenerateMetricsOneMetric()

var wantMetricsCount = 0
for i := 0; i < 2; i++ {
wantMetricsCount += md.MetricCount()
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromOldInternalMetrics(md))
err := mfc.ConsumeMetrics(context.Background(), pdatautil.MetricsFromInternalMetrics(md))
if err == nil {
t.Errorf("Wanted error got nil")
return
Expand Down

0 comments on commit 6a0d262

Please sign in to comment.