From 0af2e2db6efd0c0c5bf4f823c6048f040c489121 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Fri, 31 Jan 2025 09:31:47 -0800 Subject: [PATCH] [chore] Replace usage of metadatatest.SetupTelemetry with new componentest (#37613) Signed-off-by: Bogdan Drutu --- .../exporter_test.go | 59 +- .../groupbyattrsprocessor/processor_test.go | 259 ++----- receiver/solacereceiver/receiver_test.go | 698 ++++-------------- .../unmarshaller_egress_test.go | 88 +-- .../unmarshaller_receive_test.go | 110 +-- 5 files changed, 290 insertions(+), 924 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index 80c2dcf90e87..e27f69b94f62 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -736,11 +736,7 @@ func Test_PushMetrics(t *testing.T) { } assert.NotNil(t, cfg) - buildInfo := component.BuildInfo{ - Description: "OpenTelemetry Collector", - Version: "1.0", - } - tel := metadatatest.SetupTelemetry( + tel := componenttest.NewTelemetry( componenttest.WithMetricOptions(sdkmetric.WithView( // Drop otelhttp metrics sdkmetric.NewView( @@ -752,8 +748,12 @@ func Test_PushMetrics(t *testing.T) { }, ))), ) - set := tel.NewSettings() - set.BuildInfo = buildInfo + t.Cleanup(func() { require.NoError(t, tel.Shutdown(context.Background())) }) + set := metadatatest.NewSettings(tel) + set.BuildInfo = component.BuildInfo{ + Description: "OpenTelemetry Collector", + Version: "1.0", + } prwe, nErr := newPRWExporter(cfg, set) @@ -769,42 +769,22 @@ func Test_PushMetrics(t *testing.T) { assert.Error(t, err) return } - expectedMetrics := []metricdata.Metrics{} + assert.NoError(t, err) if tt.expectedFailedTranslations > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_exporter_prometheusremotewrite_failed_translations", - Description: "Number of translation operations that failed to translate metrics from Otel to Prometheus", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.expectedFailedTranslations), - Attributes: attribute.NewSet(attribute.String("exporter", "prometheusremotewrite")), - }, - }, + metadatatest.AssertEqualExporterPrometheusremotewriteFailedTranslations(t, tel, []metricdata.DataPoint[int64]{ + { + Value: int64(tt.expectedFailedTranslations), + Attributes: attribute.NewSet(attribute.String("exporter", "prometheusremotewrite")), }, - }) + }, metricdatatest.IgnoreTimestamp()) } - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_exporter_prometheusremotewrite_translated_time_series", - Description: "Number of Prometheus time series that were translated from OTel metrics", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.expectedTimeSeries), - Attributes: attribute.NewSet(attribute.String("exporter", "prometheusremotewrite")), - }, - }, + metadatatest.AssertEqualExporterPrometheusremotewriteTranslatedTimeSeries(t, tel, []metricdata.DataPoint[int64]{ + { + Value: int64(tt.expectedTimeSeries), + Attributes: attribute.NewSet(attribute.String("exporter", "prometheusremotewrite")), }, - }) - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) - assert.NoError(t, err) + }, metricdatatest.IgnoreTimestamp()) }) } }) @@ -1306,8 +1286,7 @@ func benchmarkPushMetrics(b *testing.B, numMetrics, numConsumers int) { endpointURL, err := url.Parse(mockServer.URL) require.NoError(b, err) - tel := metadatatest.SetupTelemetry() - set := tel.NewSettings() + set := exportertest.NewNopSettings() // Adjusted retry settings for faster testing retrySettings := configretry.BackOffConfig{ Enabled: true, diff --git a/processor/groupbyattrsprocessor/processor_test.go b/processor/groupbyattrsprocessor/processor_test.go index 7d54aad593f0..511e5392f15e 100644 --- a/processor/groupbyattrsprocessor/processor_test.go +++ b/processor/groupbyattrsprocessor/processor_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" @@ -273,8 +274,10 @@ func TestComplexAttributeGrouping(t *testing.T) { inputMetrics := someComplexMetrics(tt.withResourceAttrIndex, tt.inputResourceCount, tt.inputInstrumentationLibraryCount, 2) inputHistogramMetrics := someComplexHistogramMetrics(tt.withResourceAttrIndex, tt.inputResourceCount, tt.inputInstrumentationLibraryCount, 2, 2) - tel := metadatatest.SetupTelemetry() - gap, err := createGroupByAttrsProcessor(tel.NewSettings(), tt.groupByKeys) + tel := componenttest.NewTelemetry() + t.Cleanup(func() { require.NoError(t, tel.Shutdown(context.Background())) }) + + gap, err := createGroupByAttrsProcessor(metadatatest.NewSettings(tel), tt.groupByKeys) require.NoError(t, err) processedLogs, err := gap.processLogs(context.Background(), inputLogs) @@ -374,213 +377,105 @@ func TestComplexAttributeGrouping(t *testing.T) { } } } - var want []metricdata.Metrics if tt.shouldMoveCommonGroupedAttr { - want = []metricdata.Metrics{ + metadatatest.AssertEqualProcessorGroupbyattrsNumGroupedLogs(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_grouped_logs", - Description: "Number of logs that had attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsNumGroupedMetrics(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_grouped_metrics", - Description: "Number of metrics that had attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 4 * int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: 4 * int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsNumGroupedSpans(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_grouped_spans", - Description: "Number of spans that had attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsLogGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_log_groups", - Description: "Distribution of groups extracted for logs", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 1, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 1, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: int64(tt.outputResourceCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsMetricGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_metric_groups", - Description: "Distribution of groups extracted for metrics", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 2, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: 2 * int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 2, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: 2 * int64(tt.outputResourceCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsSpanGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_span_groups", - Description: "Distribution of groups extracted for spans", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 1, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 1, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: int64(tt.outputResourceCount), }, - } + }, metricdatatest.IgnoreTimestamp()) } else { - want = []metricdata.Metrics{ + metadatatest.AssertEqualProcessorGroupbyattrsNumNonGroupedLogs(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_non_grouped_logs", - Description: "Number of logs that did not have attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsNumNonGroupedMetrics(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_non_grouped_metrics", - Description: "Number of metrics that did not have attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 4 * int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: 4 * int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsNumNonGroupedSpans(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_num_non_grouped_spans", - Description: "Number of spans that did not have attributes grouped", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(tt.outputTotalRecordsCount), - }, - }, - }, + Value: int64(tt.outputTotalRecordsCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsLogGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_log_groups", - Description: "Distribution of groups extracted for logs", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 1, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 1, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: int64(tt.outputResourceCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsMetricGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_metric_groups", - Description: "Distribution of groups extracted for metrics", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 2, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: 2 * int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 2, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: 2 * int64(tt.outputResourceCount), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualProcessorGroupbyattrsSpanGroups(t, tel, []metricdata.HistogramDataPoint[int64]{ { - Name: "otelcol_processor_groupbyattrs_span_groups", - Description: "Distribution of groups extracted for spans", - Unit: "1", - Data: metricdata.Histogram[int64]{ - Temporality: metricdata.CumulativeTemporality, - DataPoints: []metricdata.HistogramDataPoint[int64]{ - { - Attributes: *attribute.EmptySet(), - Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, - BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Count: 1, - Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), - Sum: int64(tt.outputResourceCount), - }, - }, - }, + Attributes: *attribute.EmptySet(), + Bounds: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}, + BucketCounts: []uint64{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Count: 1, + Min: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Max: metricdata.NewExtrema(int64(tt.outputResourceCount)), + Sum: int64(tt.outputResourceCount), }, - } + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, want, metricdatatest.IgnoreTimestamp()) }) } } diff --git a/receiver/solacereceiver/receiver_test.go b/receiver/solacereceiver/receiver_test.go index 74d488b6eaa1..d67139f36ba2 100644 --- a/receiver/solacereceiver/receiver_test.go +++ b/receiver/solacereceiver/receiver_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/consumertest" @@ -32,75 +33,36 @@ import ( func TestReceiveMessage(t *testing.T) { someError := errors.New("some error") - validateMetrics := func(receivedMsgVal, droppedMsgVal, fatalUnmarshalling, reportedSpan int64) func(t *testing.T, tt metadatatest.Telemetry) { - return func(t *testing.T, tt metadatatest.Telemetry) { - var expected []metricdata.Metrics + validateMetrics := func(receivedMsgVal, droppedMsgVal, fatalUnmarshalling, reportedSpan int64) func(t *testing.T, tt *componenttest.Telemetry) { + return func(t *testing.T, tt *componenttest.Telemetry) { if reportedSpan > 0 { - expected = append(expected, - metricdata.Metrics{ - Name: "otelcol_solacereceiver_reported_spans", - Description: "Number of reported spans", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: reportedSpan, - }, - }, - }, - }) + metadatatest.AssertEqualSolacereceiverReportedSpans(t, tt, []metricdata.DataPoint[int64]{ + { + Value: reportedSpan, + }, + }, metricdatatest.IgnoreTimestamp()) } if receivedMsgVal > 0 { - expected = append(expected, metricdata.Metrics{ - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: receivedMsgVal, - }, - }, + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ + { + Value: receivedMsgVal, }, - }) + }, metricdatatest.IgnoreTimestamp()) } if droppedMsgVal > 0 { - expected = append(expected, metricdata.Metrics{ - Name: "otelcol_solacereceiver_dropped_span_messages", - Description: "Number of dropped span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: droppedMsgVal, - }, - }, + metadatatest.AssertEqualSolacereceiverDroppedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ + { + Value: droppedMsgVal, }, - }) + }, metricdatatest.IgnoreTimestamp()) } if fatalUnmarshalling > 0 { - expected = append(expected, metricdata.Metrics{ - Name: "otelcol_solacereceiver_fatal_unmarshalling_errors", - Description: "Number of fatal message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: fatalUnmarshalling, - }, - }, + metadatatest.AssertEqualSolacereceiverFatalUnmarshallingErrors(t, tt, []metricdata.DataPoint[int64]{ + { + Value: fatalUnmarshalling, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tt.AssertMetrics(t, expected, metricdatatest.IgnoreTimestamp()) } } @@ -114,7 +76,7 @@ func TestReceiveMessage(t *testing.T) { // expected error from receiveMessage expectedErr error // validate constraints after the fact - validation func(t *testing.T, tt metadatatest.Telemetry) + validation func(t *testing.T, tt *componenttest.Telemetry) // traces provided by the trace function traces ptrace.Traces }{ @@ -253,34 +215,14 @@ func TestReceiveMessagesTerminateWithCtxDone(t *testing.T) { assert.True(t, receiveMessagesCalled) assert.True(t, unmarshalCalled) assert.True(t, ackCalled) - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReportedSpans(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_reported_spans", - Description: "Number of reported spans", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, }, metricdatatest.IgnoreTimestamp()) } @@ -289,30 +231,14 @@ func TestReceiverLifecycle(t *testing.T) { receiver, messagingService, _, tt := newReceiver(t) dialCalled := make(chan struct{}) messagingService.dialFunc = func(context.Context) error { - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateConnecting), - }, - }, - }, + Value: int64(receiverStateConnecting), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, }, metricdatatest.IgnoreTimestamp()) close(dialCalled) @@ -320,60 +246,28 @@ func TestReceiverLifecycle(t *testing.T) { } closeCalled := make(chan struct{}) messagingService.closeFunc = func(context.Context) { - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateTerminating), - }, - }, - }, + Value: int64(receiverStateTerminating), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, }, metricdatatest.IgnoreTimestamp()) close(closeCalled) } receiveMessagesCalled := make(chan struct{}) messagingService.receiveMessageFunc = func(ctx context.Context) (*inboundMessage, error) { - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateConnected), - }, - }, - }, + Value: int64(receiverStateConnected), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, }, metricdatatest.IgnoreTimestamp()) close(receiveMessagesCalled) @@ -389,30 +283,14 @@ func TestReceiverLifecycle(t *testing.T) { assert.NoError(t, err) assertChannelClosed(t, closeCalled) // we error on receive message, so we should not report any additional metrics - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateTerminated), - }, - }, - }, + Value: int64(receiverStateTerminated), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, }, metricdatatest.IgnoreTimestamp()) } @@ -444,44 +322,19 @@ func TestReceiverDialFailureContinue(t *testing.T) { msgService.closeFunc = func(ctx context.Context) { closeCalled++ // assert we never left connecting state prior to closing closeDone - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateConnecting), - }, - }, - }, + Value: int64(receiverStateConnecting), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverFailedReconnections(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_failed_reconnections", - Description: "Number of failed broker reconnections", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(closeCalled), - }, - }, - }, + Value: int64(closeCalled), }, }, metricdatatest.IgnoreTimestamp()) if closeCalled == expectedAttempts { @@ -504,44 +357,19 @@ func TestReceiverDialFailureContinue(t *testing.T) { err = receiver.Shutdown(context.Background()) assert.NoError(t, err) // we error on dial, should never get to receive messages - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateTerminated), - }, - }, - }, + Value: int64(receiverStateTerminated), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverFailedReconnections(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_failed_reconnections", - Description: "Number of failed broker reconnections", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 3, - }, - }, - }, + Value: 3, }, }, metricdatatest.IgnoreTimestamp()) } @@ -590,70 +418,29 @@ func TestReceiverUnmarshalVersionFailureExpectingDisable(t *testing.T) { assertChannelClosed(t, closeDone) // we receive 1 message, encounter a fatal unmarshalling error and we nack the message so it is not actually dropped // assert idle state - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverFatalUnmarshallingErrors(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_fatal_unmarshalling_errors", - Description: "Number of fatal message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_status", - Description: "Indicates the status of the receiver as an enum. 0 = starting, 1 = connecting, 2 = connected, 3 = disabled (often paired with needs_upgrade), 4 = terminating, 5 = terminated", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(receiverStateIdle), - }, - }, - }, + Value: int64(receiverStateIdle), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverNeedUpgrade(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_need_upgrade", - Description: "Indicates with value 1 that receiver requires an upgrade and is not compatible with messages received from a broker", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, }, metricdatatest.IgnoreTimestamp()) err = receiver.Shutdown(context.Background()) @@ -665,7 +452,7 @@ func TestReceiverFlowControlDelayedRetry(t *testing.T) { testCases := []struct { name string nextConsumer consumer.Traces - validation func(*testing.T, metadatatest.Telemetry) + validation func(*testing.T, *componenttest.Telemetry) }{ { name: "Without error", @@ -674,87 +461,35 @@ func TestReceiverFlowControlDelayedRetry(t *testing.T) { { name: "With error", nextConsumer: consumertest.NewErr(someError), - validation: func(t *testing.T, tt metadatatest.Telemetry) { - tt.AssertMetrics(t, []metricdata.Metrics{ + validation: func(t *testing.T, tt *componenttest.Telemetry) { + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_recent_retries", - Description: "Most recent/current retry count when flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlRecentRetries(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlTotal(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_total", - Description: "Number of times the receiver instance became flow controlled", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverDroppedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_dropped_span_messages", - Description: "Number of dropped span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlWithSingleSuccessfulRetry(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_with_single_successful_retry", - Description: "Number of times the receiver instance became flow controlled and resolved situations after the first retry", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, }, metricdatatest.IgnoreTimestamp()) }, @@ -803,44 +538,19 @@ func TestReceiverFlowControlDelayedRetry(t *testing.T) { require.Fail(t, "Did not expect receiveMessage to return before delay interval") } // Check that we are currently flow controlled - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_recent_retries", - Description: "Most recent/current retry count when flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: int64(flowControlStateControlled), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlRecentRetries(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateControlled), - }, - }, - }, + Value: 1, }, }, metricdatatest.IgnoreTimestamp()) // since we set the next consumer to a noop, this should succeed @@ -854,86 +564,34 @@ func TestReceiverFlowControlDelayedRetry(t *testing.T) { if tc.validation != nil { tc.validation(t, tt) } else { - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_recent_retries", - Description: "Most recent/current retry count when flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlRecentRetries(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlTotal(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_total", - Description: "Number of times the receiver instance became flow controlled", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReportedSpans(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_reported_spans", - Description: "Number of reported spans", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 0, - }, - }, - }, + Value: 0, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlWithSingleSuccessfulRetry(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_with_single_successful_retry", - Description: "Number of times the receiver instance became flow controlled and resolved situations after the first retry", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, }, metricdatatest.IgnoreTimestamp()) } @@ -1003,44 +661,19 @@ func TestReceiverFlowControlDelayedRetryMultipleRetries(t *testing.T) { // we want to return an error at first, then set the next consumer to a noop consumer receiver.nextConsumer, err = consumer.NewTraces(func(context.Context, ptrace.Traces) error { if currentRetries > 0 { - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_recent_retries", - Description: "Most recent/current retry count when flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: currentRetries, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: int64(flowControlStateControlled), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlRecentRetries(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateControlled), - }, - }, - }, + Value: currentRetries, }, }, metricdatatest.IgnoreTimestamp()) } @@ -1087,83 +720,40 @@ func TestReceiverFlowControlDelayedRetryMultipleRetries(t *testing.T) { assert.NoError(t, err) } assert.True(t, ackCalled) - tt.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverReceivedSpanMessages(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_recent_retries", - Description: "Most recent/current retry count when flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: retryCount, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlStatus(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_received_span_messages", - Description: "Number of received span messages", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: int64(flowControlStateClear), }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlRecentRetries(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_status", - Description: "Indicates the flow control status of the receiver. 0 = not flow controlled, 1 = currently flow controlled", - Unit: "1", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: int64(flowControlStateClear), - }, - }, - }, + Value: retryCount, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReceiverFlowControlTotal(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_receiver_flow_control_total", - Description: "Number of times the receiver instance became flow controlled", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - }, - }, - }, + Value: 1, }, + }, metricdatatest.IgnoreTimestamp()) + metadatatest.AssertEqualSolacereceiverReportedSpans(t, tt, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_reported_spans", - Description: "Number of reported spans", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 0, - }, - }, - }, + Value: 0, }, }, metricdatatest.IgnoreTimestamp()) } -func newReceiver(t *testing.T) (*solaceTracesReceiver, *mockMessagingService, *mockUnmarshaller, metadatatest.Telemetry) { +func newReceiver(t *testing.T) (*solaceTracesReceiver, *mockMessagingService, *mockUnmarshaller, *componenttest.Telemetry) { unmarshaller := &mockUnmarshaller{} service := &mockMessagingService{} messagingServiceFactory := func() messagingService { return service } - tel := metadatatest.SetupTelemetry() + tel := componenttest.NewTelemetry() t.Cleanup(func() { require.NoError(t, tel.Shutdown(context.Background())) }) telemetryBuilder, err := metadata.NewTelemetryBuilder(tel.NewTelemetrySettings()) require.NoError(t, err) diff --git a/receiver/solacereceiver/unmarshaller_egress_test.go b/receiver/solacereceiver/unmarshaller_egress_test.go index fa1d3127a9b7..e0e70c9e90cf 100644 --- a/receiver/solacereceiver/unmarshaller_egress_test.go +++ b/receiver/solacereceiver/unmarshaller_egress_test.go @@ -10,6 +10,7 @@ import ( "github.com/Azure/go-amqp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/otel/attribute" @@ -306,24 +307,12 @@ func TestEgressUnmarshallerEgressSpan(t *testing.T) { if tt.want != nil { assert.Equal(t, 1, actual.Len()) compareSpans(t, *tt.want, actual.At(0)) - tel.AssertMetrics(t, []metricdata.Metrics{}, metricdatatest.IgnoreTimestamp()) } else { assert.Equal(t, 0, actual.Len()) - tel.AssertMetrics(t, []metricdata.Metrics{ + metadatatest.AssertEqualSolacereceiverDroppedEgressSpans(t, tel, []metricdata.DataPoint[int64]{ { - Name: "otelcol_solacereceiver_dropped_egress_spans", - Description: "Number of dropped egress spans", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - Attributes: u.metricAttrs, - }, - }, - }, + Value: 1, + Attributes: u.metricAttrs, }, }, metricdatatest.IgnoreTimestamp()) } @@ -435,25 +424,14 @@ func TestEgressUnmarshallerSendSpanAttributes(t *testing.T) { actual := ptrace.NewSpan() u.mapSendSpan(tt.spanData, actual) compareSpans(t, tt.want, actual) - var expectedMetrics []metricdata.Metrics if tt.expectedUnmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.expectedUnmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.expectedUnmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } // test the various outcomes @@ -749,25 +727,14 @@ func TestEgressUnmarshallerDeleteSpanAttributes(t *testing.T) { actual := ptrace.NewSpan() u.mapDeleteSpan(tt.spanData, actual) compareSpans(t, tt.want, actual) - var expectedMetrics []metricdata.Metrics if tt.expectedUnmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.expectedUnmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.expectedUnmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } @@ -931,34 +898,23 @@ func TestEgressUnmarshallerTransactionEvent(t *testing.T) { u.mapTransactionEvent(tt.spanData, actual.Events().AppendEmpty()) // order is nondeterministic for attributes, so we must sort to get a valid comparison compareSpans(t, expected, actual) - var expectedMetrics []metricdata.Metrics if tt.expectedUnmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.expectedUnmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.expectedUnmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } -func newTestEgressV1Unmarshaller(t *testing.T) (*brokerTraceEgressUnmarshallerV1, metadatatest.Telemetry) { - tt := metadatatest.SetupTelemetry() +func newTestEgressV1Unmarshaller(t *testing.T) (*brokerTraceEgressUnmarshallerV1, *componenttest.Telemetry) { + tt := componenttest.NewTelemetry() t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) builder, err := metadata.NewTelemetryBuilder(tt.NewTelemetrySettings()) require.NoError(t, err) - metricAttr := attribute.NewSet(attribute.String("receiver_name", tt.NewSettings().ID.Name())) + metricAttr := attribute.NewSet(attribute.String("receiver_name", "")) return &brokerTraceEgressUnmarshallerV1{zap.NewNop(), builder, metricAttr}, tt } diff --git a/receiver/solacereceiver/unmarshaller_receive_test.go b/receiver/solacereceiver/unmarshaller_receive_test.go index a7465ef76acd..48ee818795f7 100644 --- a/receiver/solacereceiver/unmarshaller_receive_test.go +++ b/receiver/solacereceiver/unmarshaller_receive_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/otel/attribute" @@ -62,25 +63,14 @@ func TestReceiveUnmarshallerMapResourceSpan(t *testing.T) { actual := pcommon.NewMap() u.mapResourceSpanAttributes(tt.spanData, actual) assert.Equal(t, tt.want, actual.AsRaw()) - var expectedMetrics []metricdata.Metrics if tt.expectedUnmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.expectedUnmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.expectedUnmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } @@ -338,25 +328,14 @@ func TestReceiveUnmarshallerMapClientSpanAttributes(t *testing.T) { actual := pcommon.NewMap() u.mapClientSpanAttributes(tt.spanData, actual) assert.Equal(t, tt.want, actual.AsRaw()) - var expectedMetrics []metricdata.Metrics if tt.expectedUnmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.expectedUnmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.expectedUnmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } @@ -612,25 +591,14 @@ func TestReceiveUnmarshallerEvents(t *testing.T) { u.mapEvents(tt.spanData, actual) // order is nondeterministic for attributes, so we must sort to get a valid comparison compareSpans(t, expected, actual) - var expectedMetrics []metricdata.Metrics if tt.unmarshallingErrors > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.unmarshallingErrors, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.unmarshallingErrors, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } @@ -670,25 +638,14 @@ func TestReceiveUnmarshallerRGMID(t *testing.T) { u, tel := newTestReceiveV1Unmarshaller(t) actual := u.rgmidToString(tt.in) assert.Equal(t, tt.expected, actual) - var expectedMetrics []metricdata.Metrics if tt.numErr > 0 { - expectedMetrics = append(expectedMetrics, metricdata.Metrics{ - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: tt.numErr, - Attributes: u.metricAttrs, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tel, []metricdata.DataPoint[int64]{ + { + Value: tt.numErr, + Attributes: u.metricAttrs, }, - }) + }, metricdatatest.IgnoreTimestamp()) } - tel.AssertMetrics(t, expectedMetrics, metricdatatest.IgnoreTimestamp()) }) } } @@ -907,30 +864,19 @@ func TestSolaceMessageReceiveUnmarshallerV1InsertUserPropertyUnsupportedType(t * u.insertUserProperty(attributeMap, key, "invalid data type") _, ok := attributeMap.Get("messaging.solace.user_properties." + key) assert.False(t, ok) - tt.AssertMetrics(t, []metricdata.Metrics{ - { - Name: "otelcol_solacereceiver_recoverable_unmarshalling_errors", - Description: "Number of recoverable message unmarshalling errors", - Unit: "1", - Data: metricdata.Sum[int64]{ - Temporality: metricdata.CumulativeTemporality, - IsMonotonic: true, - DataPoints: []metricdata.DataPoint[int64]{ - { - Value: 1, - Attributes: u.metricAttrs, - }, - }, - }, + metadatatest.AssertEqualSolacereceiverRecoverableUnmarshallingErrors(t, tt, []metricdata.DataPoint[int64]{ + { + Value: 1, + Attributes: u.metricAttrs, }, }, metricdatatest.IgnoreTimestamp()) } -func newTestReceiveV1Unmarshaller(t *testing.T) (*brokerTraceReceiveUnmarshallerV1, metadatatest.Telemetry) { - tt := metadatatest.SetupTelemetry() +func newTestReceiveV1Unmarshaller(t *testing.T) (*brokerTraceReceiveUnmarshallerV1, *componenttest.Telemetry) { + tt := componenttest.NewTelemetry() t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) telemetryBuilder, err := metadata.NewTelemetryBuilder(tt.NewTelemetrySettings()) require.NoError(t, err) - metricAttr := attribute.NewSet(attribute.String("receiver_name", tt.NewSettings().ID.Name())) + metricAttr := attribute.NewSet(attribute.String("receiver_name", "")) return &brokerTraceReceiveUnmarshallerV1{zap.NewNop(), telemetryBuilder, metricAttr}, tt }