diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index 388cb786071..895ba83b2e3 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -125,16 +125,16 @@ func TestLogsExporter_WithRecordLogs_ReturnError(t *testing.T) { } func TestLogsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rCfg := DefaultRetrySettings() qCfg := DefaultQueueSettings() qCfg.NumConsumers = 1 qCfg.QueueSize = 2 wantErr := errors.New("some-error") - te, err := NewLogsExporter(&fakeLogsExporterConfig, componenttest.NewNopExporterCreateSettings(), newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg)) + te, err := NewLogsExporter(&fakeLogsExporterConfig, set.ToExporterCreateSettings(), newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NotNil(t, te) @@ -205,9 +205,9 @@ func newPushLogsData(retError error) consumerhelper.ConsumeLogsFunc { } func checkRecordedMetricsForLogsExporter(t *testing.T, le component.LogsExporter, wantError error) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) ld := testdata.GenerateLogsTwoLogRecordsSameResource() const numBatches = 7 diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index e7cfd9056f7..98377a4ee5b 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -124,16 +124,16 @@ func TestMetricsExporter_WithRecordMetrics_ReturnError(t *testing.T) { } func TestMetricsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rCfg := DefaultRetrySettings() qCfg := DefaultQueueSettings() qCfg.NumConsumers = 1 qCfg.QueueSize = 2 wantErr := errors.New("some-error") - te, err := NewMetricsExporter(&fakeMetricsExporterConfig, componenttest.NewNopExporterCreateSettings(), newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg)) + te, err := NewMetricsExporter(&fakeMetricsExporterConfig, set.ToExporterCreateSettings(), newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NotNil(t, te) @@ -206,9 +206,9 @@ func newPushMetricsData(retError error) consumerhelper.ConsumeMetricsFunc { } func checkRecordedMetricsForMetricsExporter(t *testing.T, me component.MetricsExporter, wantError error) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) md := testdata.GenerateMetricsTwoMetrics() const numBatches = 7 diff --git a/exporter/exporterhelper/obsreport_test.go b/exporter/exporterhelper/obsreport_test.go index 0021ac1ffff..7afdc7a8d18 100644 --- a/exporter/exporterhelper/obsreport_test.go +++ b/exporter/exporterhelper/obsreport_test.go @@ -24,7 +24,6 @@ import ( "go.opencensus.io/stats/view" "go.opencensus.io/tag" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/obsreport" @@ -32,16 +31,17 @@ import ( ) func TestExportEnqueueFailure(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) exporter := config.NewComponentID("fakeExporter") obsrep := newObsExporter(obsreport.ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: componenttest.NewNopExporterCreateSettings()}) + ExporterCreateSettings: set.ToExporterCreateSettings(), + }) logRecords := 7 obsrep.recordLogsEnqueueFailure(context.Background(), logRecords) diff --git a/exporter/exporterhelper/queued_retry_test.go b/exporter/exporterhelper/queued_retry_test.go index 63deffb6468..ad1f8ad4e6e 100644 --- a/exporter/exporterhelper/queued_retry_test.go +++ b/exporter/exporterhelper/queued_retry_test.go @@ -300,13 +300,13 @@ func TestQueuedRetry_DropOnFull(t *testing.T) { } func TestQueuedRetryHappyPath(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) qCfg := DefaultQueueSettings() rCfg := DefaultRetrySettings() - be := newBaseExporter(&defaultExporterCfg, componenttest.NewNopExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) + be := newBaseExporter(&defaultExporterCfg, set.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler()) ocs := newObservabilityConsumerSender(be.qrSender.consumerSender) be.qrSender.consumerSender = ocs require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index bf9366d9176..ad765e1ecb0 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -122,16 +122,16 @@ func TestTracesExporter_WithRecordMetrics_ReturnError(t *testing.T) { } func TestTracesExporter_WithRecordEnqueueFailedMetrics(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rCfg := DefaultRetrySettings() qCfg := DefaultQueueSettings() qCfg.NumConsumers = 1 qCfg.QueueSize = 2 wantErr := errors.New("some-error") - te, err := NewTracesExporter(&fakeTracesExporterConfig, componenttest.NewNopExporterCreateSettings(), newTraceDataPusher(wantErr), WithRetry(rCfg), WithQueue(qCfg)) + te, err := NewTracesExporter(&fakeTracesExporterConfig, set.ToExporterCreateSettings(), newTraceDataPusher(wantErr), WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NotNil(t, te) @@ -206,9 +206,9 @@ func newTraceDataPusher(retError error) consumerhelper.ConsumeTracesFunc { } func checkRecordedMetricsForTracesExporter(t *testing.T, te component.TracesExporter, wantError error) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) td := testdata.GenerateTracesTwoSpansSameResource() const numBatches = 7 diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index d8b3abc0fde..3bffcde04e0 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -24,11 +24,8 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/sdk/trace/tracetest" "go.opentelemetry.io/otel/trace" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics" @@ -57,16 +54,14 @@ type testParams struct { } func TestReceiveTraceDataOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) - sr := new(tracetest.SpanRecorder) - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + otel.SetTracerProvider(set.TracerProvider) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - parentCtx, parentSpan := tp.Tracer("test").Start(context.Background(), t.Name()) + parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() params := []testParams{ @@ -80,7 +75,7 @@ func TestReceiveTraceDataOp(t *testing.T) { rec.EndTracesOp(ctx, format, params[i].items, param.err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var acceptedSpans, refusedSpans int @@ -106,16 +101,14 @@ func TestReceiveTraceDataOp(t *testing.T) { } func TestReceiveLogsOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) - sr := new(tracetest.SpanRecorder) - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + otel.SetTracerProvider(set.TracerProvider) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - parentCtx, parentSpan := tp.Tracer("test").Start(context.Background(), t.Name()) + parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() params := []testParams{ @@ -129,7 +122,7 @@ func TestReceiveLogsOp(t *testing.T) { rec.EndLogsOp(ctx, format, params[i].items, param.err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var acceptedLogRecords, refusedLogRecords int @@ -155,16 +148,14 @@ func TestReceiveLogsOp(t *testing.T) { } func TestReceiveMetricsOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) - sr := new(tracetest.SpanRecorder) - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + otel.SetTracerProvider(set.TracerProvider) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - parentCtx, parentSpan := tp.Tracer("test").Start(context.Background(), t.Name()) + parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() params := []testParams{ @@ -178,7 +169,7 @@ func TestReceiveMetricsOp(t *testing.T) { rec.EndMetricsOp(ctx, format, params[i].items, param.err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var acceptedMetricPoints, refusedMetricPoints int @@ -205,16 +196,14 @@ func TestReceiveMetricsOp(t *testing.T) { } func TestScrapeMetricsDataOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) - sr := new(tracetest.SpanRecorder) - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + otel.SetTracerProvider(set.TracerProvider) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - parentCtx, parentSpan := tp.Tracer("test").Start(context.Background(), t.Name()) + parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() params := []testParams{ @@ -229,7 +218,7 @@ func TestScrapeMetricsDataOp(t *testing.T) { scrp.EndMetricsOp(ctx, params[i].items, params[i].err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var scrapedMetricPoints, erroredMetricPoints int @@ -264,13 +253,9 @@ func TestScrapeMetricsDataOp(t *testing.T) { } func TestExportTraceDataOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() - - set := componenttest.NewNopExporterCreateSettings() - sr := new(tracetest.SpanRecorder) - set.TracerProvider = sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + defer set.Shutdown(context.Background()) parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -278,7 +263,7 @@ func TestExportTraceDataOp(t *testing.T) { obsrep := NewExporter(ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: set, + ExporterCreateSettings: set.ToExporterCreateSettings(), }) params := []testParams{ @@ -291,7 +276,7 @@ func TestExportTraceDataOp(t *testing.T) { obsrep.EndTracesOp(ctx, params[i].items, params[i].err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var sentSpans, failedToSendSpans int @@ -318,13 +303,9 @@ func TestExportTraceDataOp(t *testing.T) { } func TestExportMetricsOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() - - set := componenttest.NewNopExporterCreateSettings() - sr := new(tracetest.SpanRecorder) - set.TracerProvider = sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + defer set.Shutdown(context.Background()) parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -332,7 +313,7 @@ func TestExportMetricsOp(t *testing.T) { obsrep := NewExporter(ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: set, + ExporterCreateSettings: set.ToExporterCreateSettings(), }) params := []testParams{ @@ -346,7 +327,7 @@ func TestExportMetricsOp(t *testing.T) { obsrep.EndMetricsOp(ctx, params[i].items, params[i].err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var sentMetricPoints, failedToSendMetricPoints int @@ -373,13 +354,9 @@ func TestExportMetricsOp(t *testing.T) { } func TestExportLogsOp(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() - - set := componenttest.NewNopExporterCreateSettings() - sr := new(tracetest.SpanRecorder) - set.TracerProvider = sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + defer set.Shutdown(context.Background()) parentCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() @@ -387,7 +364,7 @@ func TestExportLogsOp(t *testing.T) { obsrep := NewExporter(ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: set, + ExporterCreateSettings: set.ToExporterCreateSettings(), }) params := []testParams{ @@ -401,7 +378,7 @@ func TestExportLogsOp(t *testing.T) { obsrep.EndLogsOp(ctx, params[i].items, params[i].err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) var sentLogRecords, failedToSendLogRecords int @@ -428,12 +405,14 @@ func TestExportLogsOp(t *testing.T) { } func TestReceiveWithLongLivedCtx(t *testing.T) { - sr := new(tracetest.SpanRecorder) - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + set, err := obsreporttest.SetupRecordedMetricsTest() + require.NoError(t, err) + defer set.Shutdown(context.Background()) + + otel.SetTracerProvider(set.TracerProvider) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - longLivedCtx, parentSpan := tp.Tracer("test").Start(context.Background(), t.Name()) + longLivedCtx, parentSpan := set.TracerProvider.Tracer("test").Start(context.Background(), t.Name()) defer parentSpan.End() params := []testParams{ @@ -449,7 +428,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { rec.EndTracesOp(ctx, format, params[i].items, params[i].err) } - spans := sr.Ended() + spans := set.SpanRecorder.Ended() require.Equal(t, len(params), len(spans)) for i, span := range spans { @@ -477,9 +456,9 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { } func TestProcessorTraceData(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) const acceptedSpans = 27 const refusedSpans = 19 @@ -494,9 +473,9 @@ func TestProcessorTraceData(t *testing.T) { } func TestProcessorMetricsData(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) const acceptedPoints = 29 const refusedPoints = 11 @@ -533,9 +512,9 @@ func TestBuildProcessorCustomMetricName(t *testing.T) { } func TestProcessorLogRecords(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) const acceptedRecords = 29 const refusedRecords = 11 diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index 4a6145f9230..aa0292ac894 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -15,13 +15,18 @@ package obsreporttest import ( + "context" "fmt" "reflect" "sort" "go.opencensus.io/stats/view" "go.opencensus.io/tag" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/sdk/trace/tracetest" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/internal/obsreportconfig" @@ -41,19 +46,51 @@ var ( processorTag, _ = tag.NewKey("processor") ) +type TestTelemetrySettings struct { + component.TelemetrySettings + SpanRecorder *tracetest.SpanRecorder + views []*view.View +} + +// ToExporterCreateSettings returns ExporterCreateSettings with configured TelemetrySettings +func (tts *TestTelemetrySettings) ToExporterCreateSettings() component.ExporterCreateSettings { + exporterSettings := componenttest.NewNopExporterCreateSettings() + exporterSettings.TelemetrySettings = tts.TelemetrySettings + return exporterSettings +} + +// ToReceiverCreateSettings returns ReceiverCreateSettings with configured TelemetrySettings +func (tts *TestTelemetrySettings) ToReceiverCreateSettings() component.ReceiverCreateSettings { + receiverSettings := componenttest.NewNopReceiverCreateSettings() + receiverSettings.TelemetrySettings = tts.TelemetrySettings + return receiverSettings +} + +// Shutdown unregisters any views and shuts down the SpanRecorder +func (tts *TestTelemetrySettings) Shutdown(ctx context.Context) error { + view.Unregister(tts.views...) + return tts.SpanRecorder.Shutdown(ctx) +} + // SetupRecordedMetricsTest does setup the testing environment to check the metrics recorded by receivers, producers or exporters. -// The returned function should be deferred. -func SetupRecordedMetricsTest() (func(), error) { +// The caller should defer a call to Shutdown the returned TestTelemetrySettings. +func SetupRecordedMetricsTest() (TestTelemetrySettings, error) { + sr := new(tracetest.SpanRecorder) + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + + settings := TestTelemetrySettings{ + TelemetrySettings: componenttest.NewNopTelemetrySettings(), + SpanRecorder: sr, + } + settings.TracerProvider = tp obsMetrics := obsreportconfig.Configure(configtelemetry.LevelNormal) - views := obsMetrics.Views - err := view.Register(views...) + settings.views = obsMetrics.Views + err := view.Register(settings.views...) if err != nil { - return nil, err + return settings, err } - return func() { - view.Unregister(views...) - }, err + return settings, err } // CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values. diff --git a/obsreport/obsreporttest/obsreporttest_test.go b/obsreport/obsreporttest/obsreporttest_test.go index 8cac8fa3f79..ee0c50278d0 100644 --- a/obsreport/obsreporttest/obsreporttest_test.go +++ b/obsreport/obsreporttest/obsreporttest_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/obsreport" @@ -39,9 +38,9 @@ var ( ) func TestCheckReceiverTracesViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rec := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: receiver, Transport: transport}) ctx := rec.StartTracesOp(context.Background()) @@ -56,9 +55,9 @@ func TestCheckReceiverTracesViews(t *testing.T) { } func TestCheckReceiverMetricsViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rec := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: receiver, Transport: transport}) ctx := rec.StartMetricsOp(context.Background()) @@ -69,9 +68,9 @@ func TestCheckReceiverMetricsViews(t *testing.T) { } func TestCheckReceiverLogsViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) rec := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: receiver, Transport: transport}) ctx := rec.StartLogsOp(context.Background()) @@ -82,14 +81,14 @@ func TestCheckReceiverLogsViews(t *testing.T) { } func TestCheckExporterTracesViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: componenttest.NewNopExporterCreateSettings(), + ExporterCreateSettings: set.ToExporterCreateSettings(), }) ctx := obsrep.StartTracesOp(context.Background()) assert.NotNil(t, ctx) @@ -100,14 +99,14 @@ func TestCheckExporterTracesViews(t *testing.T) { } func TestCheckExporterMetricsViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: componenttest.NewNopExporterCreateSettings(), + ExporterCreateSettings: set.ToExporterCreateSettings(), }) ctx := obsrep.StartMetricsOp(context.Background()) assert.NotNil(t, ctx) @@ -118,14 +117,14 @@ func TestCheckExporterMetricsViews(t *testing.T) { } func TestCheckExporterLogsViews(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) obsrep := obsreport.NewExporter(obsreport.ExporterSettings{ Level: configtelemetry.LevelNormal, ExporterID: exporter, - ExporterCreateSettings: componenttest.NewNopExporterCreateSettings(), + ExporterCreateSettings: set.ToExporterCreateSettings(), }) ctx := obsrep.StartLogsOp(context.Background()) assert.NotNil(t, ctx) diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 9321cace150..b660f64b48b 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -506,9 +506,9 @@ func TestOTLPReceiverTrace_HandleNextConsumerResponse(t *testing.T) { for _, exporter := range exporters { for _, tt := range tests { t.Run(tt.name+"/"+exporter.receiverTag, func(t *testing.T) { - doneFn, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer doneFn() + defer set.Shutdown(context.Background()) sink := &internalconsumertest.ErrOrSinkConsumer{TracesSink: new(consumertest.TracesSink)} diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index e39958283cd..606397cd2ce 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -191,9 +191,9 @@ func TestScrapeController(t *testing.T) { otel.SetTracerProvider(tp) defer otel.SetTracerProvider(trace.NewNoopTracerProvider()) - done, err := obsreporttest.SetupRecordedMetricsTest() + set, err := obsreporttest.SetupRecordedMetricsTest() require.NoError(t, err) - defer done() + defer set.Shutdown(context.Background()) initializeChs := make([]chan bool, test.scrapers+test.resourceScrapers) scrapeMetricsChs := make([]chan int, test.scrapers)