diff --git a/component/componenttest/obsreporttest.go b/component/componenttest/obsreporttest.go index 7c2875aa0dc..fcdc42c73ae 100644 --- a/component/componenttest/obsreporttest.go +++ b/component/componenttest/obsreporttest.go @@ -40,13 +40,11 @@ type TestTelemetry struct { } // CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckExporterTraces(sentSpans, sendFailedSpans int64) error { return checkExporterTraces(tts.reader, tts.id, sentSpans, sendFailedSpans) } // CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckExporterMetrics(sentMetricsPoints, sendFailedMetricsPoints int64) error { return checkExporterMetrics(tts.reader, tts.id, sentMetricsPoints, sendFailedMetricsPoints) } @@ -64,7 +62,6 @@ func (tts *TestTelemetry) CheckExporterEnqueueFailedLogs(enqueueFailed int64) er } // CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckExporterLogs(sentLogRecords, sendFailedLogRecords int64) error { return checkExporterLogs(tts.reader, tts.id, sentLogRecords, sendFailedLogRecords) } @@ -75,25 +72,21 @@ func (tts *TestTelemetry) CheckExporterMetricGauge(metric string, val int64, ext } // CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckReceiverTraces(protocol string, acceptedSpans, droppedSpans int64) error { return checkReceiverTraces(tts.reader, tts.id, protocol, acceptedSpans, droppedSpans) } // CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckReceiverLogs(protocol string, acceptedLogRecords, droppedLogRecords int64) error { return checkReceiverLogs(tts.reader, tts.id, protocol, acceptedLogRecords, droppedLogRecords) } // CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckReceiverMetrics(protocol string, acceptedMetricPoints, droppedMetricPoints int64) error { return checkReceiverMetrics(tts.reader, tts.id, protocol, acceptedMetricPoints, droppedMetricPoints) } // CheckScraperMetrics checks that for the current exported values for metrics scraper metrics match given values. -// Note: SetupTelemetry must be called before this function. func (tts *TestTelemetry) CheckScraperMetrics(receiver component.ID, scraper component.ID, scrapedMetricPoints, erroredMetricPoints int64) error { return checkScraperMetrics(tts.reader, receiver, scraper, scrapedMetricPoints, erroredMetricPoints) } diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index 248077d32db..e979b7a1f49 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -92,32 +92,23 @@ func TestNewDefaultServerConfig(t *testing.T) { } var ( - componentID = component.MustNewID("component") testAuthID = component.MustNewID("testauth") mockID = component.MustNewID("mock") doesntExistID = component.MustNewID("doesntexist") ) func TestDefaultGrpcClientSettings(t *testing.T) { - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - gcs := &ClientConfig{ TLSSetting: configtls.ClientConfig{ Insecure: true, }, } - opts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings(), []ToClientConnOption{}) + opts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), []ToClientConnOption{}) require.NoError(t, err) assert.Len(t, opts, 2) } func TestGrpcClientExtraOption(t *testing.T) { - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - gcs := &ClientConfig{ TLSSetting: configtls.ClientConfig{ Insecure: true, @@ -127,7 +118,7 @@ func TestGrpcClientExtraOption(t *testing.T) { opts, err := gcs.getGrpcDialOptions( context.Background(), componenttest.NewNopHost(), - tt.TelemetrySettings(), + componenttest.NewNopTelemetrySettings(), []ToClientConnOption{WithGrpcDialOption(extraOpt)}, ) require.NoError(t, err) @@ -136,10 +127,6 @@ func TestGrpcClientExtraOption(t *testing.T) { } func TestAllGrpcClientSettings(t *testing.T) { - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - tests := []struct { settings ClientConfig name string @@ -235,7 +222,7 @@ func TestAllGrpcClientSettings(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - opts, err := test.settings.getGrpcDialOptions(context.Background(), test.host, tt.TelemetrySettings(), []ToClientConnOption{}) + opts, err := test.settings.getGrpcDialOptions(context.Background(), test.host, componenttest.NewNopTelemetrySettings(), []ToClientConnOption{}) require.NoError(t, err) assert.Len(t, opts, 9) }) @@ -496,10 +483,6 @@ func TestGRPCClientSettingsError(t *testing.T) { } func TestUseSecure(t *testing.T) { - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - gcs := &ClientConfig{ Headers: nil, Endpoint: "", @@ -507,7 +490,7 @@ func TestUseSecure(t *testing.T) { TLSSetting: configtls.ClientConfig{}, Keepalive: nil, } - dialOpts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings(), []ToClientConnOption{}) + dialOpts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), []ToClientConnOption{}) require.NoError(t, err) assert.Len(t, dialOpts, 2) } @@ -578,10 +561,6 @@ func TestGRPCServerSettings_ToListener_Error(t *testing.T) { } func TestHttpReception(t *testing.T) { - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) - tests := []struct { name string tlsServerCreds *configtls.ServerConfig @@ -709,7 +688,7 @@ func TestHttpReception(t *testing.T) { Endpoint: ln.Addr().String(), TLSSetting: *test.tlsClientCreds, } - grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) + grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) require.NoError(t, errClient) defer func() { assert.NoError(t, grpcClientConn.Close()) }() c := ptraceotlp.NewGRPCClient(grpcClientConn) @@ -731,9 +710,6 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping test on windows") } - tt, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) socketName := tempSocketName(t) gss := &ServerConfig{ @@ -758,7 +734,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { Insecure: true, }, } - grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) + grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) require.NoError(t, errClient) defer func() { assert.NoError(t, grpcClientConn.Close()) }() c := ptraceotlp.NewGRPCClient(grpcClientConn) @@ -961,13 +937,7 @@ func TestClientInfoInterceptors(t *testing.T) { }, } - tel, err := componenttest.SetupTelemetry(componentID) - require.NoError(t, err) - defer func() { - require.NoError(t, tel.Shutdown(context.Background())) - }() - - grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tel.TelemetrySettings()) + grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) require.NoError(t, errClient) defer func() { assert.NoError(t, grpcClientConn.Close()) }() diff --git a/scraper/scraperhelper/scrapercontroller_test.go b/scraper/scraperhelper/scrapercontroller_test.go index 24285912143..5f6ec4ebbca 100644 --- a/scraper/scraperhelper/scrapercontroller_test.go +++ b/scraper/scraperhelper/scrapercontroller_test.go @@ -117,8 +117,7 @@ func TestScrapeController(t *testing.T) { }, } - for _, tt := range testCases { - test := tt + for _, test := range testCases { t.Run(test.name, func(t *testing.T) { receiverID := component.MustNewID("receiver") tt, err := componenttest.SetupTelemetry(receiverID) @@ -179,9 +178,9 @@ func TestScrapeController(t *testing.T) { spans := tt.SpanRecorder.Ended() assertReceiverSpan(t, spans) - assertReceiverViews(t, tt, sink) + assertReceiverMetrics(t, tt, sink) assertScraperSpan(t, test.scrapeErr, spans) - assertScraperViews(t, tt, test.scrapeErr, sink) + assertScraperMetrics(t, tt, test.scrapeErr, sink) } err = mr.Shutdown(context.Background()) @@ -263,7 +262,7 @@ func assertReceiverSpan(t *testing.T, spans []sdktrace.ReadOnlySpan) { assert.True(t, receiverSpan) } -func assertReceiverViews(t *testing.T, tt componenttest.TestTelemetry, sink *consumertest.MetricsSink) { +func assertReceiverMetrics(t *testing.T, tt componenttest.TestTelemetry, sink *consumertest.MetricsSink) { dataPointCount := 0 for _, md := range sink.AllMetrics() { dataPointCount += md.DataPointCount() @@ -291,7 +290,7 @@ func assertScraperSpan(t *testing.T, expectedErr error, spans []sdktrace.ReadOnl assert.True(t, scraperSpan) } -func assertScraperViews(t *testing.T, tt componenttest.TestTelemetry, expectedErr error, sink *consumertest.MetricsSink) { +func assertScraperMetrics(t *testing.T, tt componenttest.TestTelemetry, expectedErr error, sink *consumertest.MetricsSink) { expectedScraped := int64(sink.DataPointCount()) expectedErrored := int64(0) if expectedErr != nil {