diff --git a/.chloggen/codeboten_create-settings-receiver.yaml b/.chloggen/codeboten_create-settings-receiver.yaml new file mode 100644 index 00000000000..9afcb42c231 --- /dev/null +++ b/.chloggen/codeboten_create-settings-receiver.yaml @@ -0,0 +1,28 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: receiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate CreateSettings and NewNopCreateSettings + +# One or more tracking issues or pull requests related to the change +issues: [9428] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + The following methods are being renamed: + - receiver.CreateSettings -> receiver.Settings + - receiver.NewNopCreateSettings -> receiver.NewNopSettings + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/cmd/mdatagen/internal/samplereceiver/factory.go b/cmd/mdatagen/internal/samplereceiver/factory.go index 565305d540c..f4e425c4c5e 100644 --- a/cmd/mdatagen/internal/samplereceiver/factory.go +++ b/cmd/mdatagen/internal/samplereceiver/factory.go @@ -22,11 +22,11 @@ func NewFactory() receiver.Factory { receiver.WithLogs(createLogs, metadata.LogsStability)) } -func createTraces(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) { +func createTraces(context.Context, receiver.Settings, component.Config, consumer.Traces) (receiver.Traces, error) { return nopInstance, nil } -func createMetrics(ctx context.Context, set receiver.CreateSettings, _ component.Config, _ consumer.Metrics) (receiver.Metrics, error) { +func createMetrics(ctx context.Context, set receiver.Settings, _ component.Config, _ consumer.Metrics) (receiver.Metrics, error) { telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings, metadata.WithProcessRuntimeTotalAllocBytesCallback(func() int64 { return 2 })) if err != nil { return nil, err @@ -35,7 +35,7 @@ func createMetrics(ctx context.Context, set receiver.CreateSettings, _ component return nopInstance, nil } -func createLogs(context.Context, receiver.CreateSettings, component.Config, consumer.Logs) (receiver.Logs, error) { +func createLogs(context.Context, receiver.Settings, component.Config, consumer.Logs) (receiver.Logs, error) { return nopInstance, nil } diff --git a/cmd/mdatagen/internal/samplereceiver/generated_component_telemetry_test.go b/cmd/mdatagen/internal/samplereceiver/generated_component_telemetry_test.go index e8cf2fe05e9..e0a3e1cb559 100644 --- a/cmd/mdatagen/internal/samplereceiver/generated_component_telemetry_test.go +++ b/cmd/mdatagen/internal/samplereceiver/generated_component_telemetry_test.go @@ -21,8 +21,8 @@ type componentTestTelemetry struct { meterProvider *sdkmetric.MeterProvider } -func (tt *componentTestTelemetry) NewCreateSettings() receiver.CreateSettings { - settings := receivertest.NewNopCreateSettings() +func (tt *componentTestTelemetry) NewSettings() receiver.Settings { + settings := receivertest.NewNopSettings() settings.MeterProvider = tt.meterProvider settings.ID = component.NewID(component.MustNewType("sample")) diff --git a/cmd/mdatagen/internal/samplereceiver/generated_component_test.go b/cmd/mdatagen/internal/samplereceiver/generated_component_test.go index d20ac9b6b4f..46616a207e5 100644 --- a/cmd/mdatagen/internal/samplereceiver/generated_component_test.go +++ b/cmd/mdatagen/internal/samplereceiver/generated_component_test.go @@ -30,26 +30,26 @@ func TestComponentLifecycle(t *testing.T) { tests := []struct { name string - createFn func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) + createFn func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) }{ { name: "logs", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "metrics", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateMetricsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "traces", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -64,19 +64,19 @@ func TestComponentLifecycle(t *testing.T) { for _, test := range tests { t.Run(test.name+"-shutdown", func(t *testing.T) { - c, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + c, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) err = c.Shutdown(context.Background()) require.NoError(t, err) }) t.Run(test.name+"-lifecycle", func(t *testing.T) { - firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) host := componenttest.NewNopHost() require.NoError(t, err) require.NoError(t, firstRcvr.Start(context.Background(), host)) require.NoError(t, firstRcvr.Shutdown(context.Background())) - secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) require.NoError(t, secondRcvr.Start(context.Background(), host)) require.NoError(t, secondRcvr.Shutdown(context.Background())) diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go index 344599e2c40..b05bf39206d 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go @@ -341,7 +341,7 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { } } -func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { +func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...metricBuilderOption) *MetricsBuilder { if !mbc.Metrics.DefaultMetric.enabledSetByUser { settings.Logger.Warn("[WARNING] Please set `enabled` field explicitly for `default.metric`: This metric will be disabled by default soon.") } diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go index b6214e5d894..657e400408b 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go @@ -58,7 +58,7 @@ func TestMetricsBuilder(t *testing.T) { start := pcommon.Timestamp(1_000_000_000) ts := pcommon.Timestamp(1_000_001_000) observedZapCore, observedLogs := observer.New(zap.WarnLevel) - settings := receivertest.NewNopCreateSettings() + settings := receivertest.NewNopSettings() settings.Logger = zap.New(observedZapCore) mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) diff --git a/cmd/mdatagen/internal/samplereceiver/metrics_test.go b/cmd/mdatagen/internal/samplereceiver/metrics_test.go index 2c3dd5675a5..3055b1dea31 100644 --- a/cmd/mdatagen/internal/samplereceiver/metrics_test.go +++ b/cmd/mdatagen/internal/samplereceiver/metrics_test.go @@ -18,7 +18,7 @@ import ( // TestGeneratedMetrics verifies that the internal/metadata API is generated correctly. func TestGeneratedMetrics(t *testing.T) { - mb := metadata.NewMetricsBuilder(metadata.DefaultMetricsBuilderConfig(), receivertest.NewNopCreateSettings()) + mb := metadata.NewMetricsBuilder(metadata.DefaultMetricsBuilderConfig(), receivertest.NewNopSettings()) m := mb.Emit() require.Equal(t, 0, m.ResourceMetrics().Len()) } @@ -26,7 +26,7 @@ func TestGeneratedMetrics(t *testing.T) { func TestComponentTelemetry(t *testing.T) { tt := setupTestTelemetry() factory := NewFactory() - _, err := factory.CreateMetricsReceiver(context.Background(), tt.NewCreateSettings(), componenttest.NewNopHost(), new(consumertest.MetricsSink)) + _, err := factory.CreateMetricsReceiver(context.Background(), tt.NewSettings(), componenttest.NewNopHost(), new(consumertest.MetricsSink)) require.NoError(t, err) tt.assertMetrics(t, []metricdata.Metrics{ { diff --git a/cmd/mdatagen/templates/component_telemetry_test.go.tmpl b/cmd/mdatagen/templates/component_telemetry_test.go.tmpl index adba6355149..03a702acd00 100644 --- a/cmd/mdatagen/templates/component_telemetry_test.go.tmpl +++ b/cmd/mdatagen/templates/component_telemetry_test.go.tmpl @@ -21,6 +21,16 @@ type componentTestTelemetry struct { meterProvider *sdkmetric.MeterProvider } +{{- if isReceiver }} +func (tt *componentTestTelemetry) NewSettings() {{ .Status.Class }}.Settings { + settings := {{ .Status.Class }}test.NewNopSettings() + settings.MeterProvider = tt.meterProvider + settings.ID = component.NewID(component.MustNewType("{{ .Type }}")) + + return settings +} + +{{ else }} func (tt *componentTestTelemetry) NewCreateSettings() {{ .Status.Class }}.CreateSettings { settings := {{ .Status.Class }}test.NewNopCreateSettings() settings.MeterProvider = tt.meterProvider @@ -29,6 +39,7 @@ func (tt *componentTestTelemetry) NewCreateSettings() {{ .Status.Class }}.Create return settings } +{{ end }} func setupTestTelemetry() componentTestTelemetry { reader := sdkmetric.NewManualReader() return componentTestTelemetry{ diff --git a/cmd/mdatagen/templates/component_test.go.tmpl b/cmd/mdatagen/templates/component_test.go.tmpl index f44efb7310c..fe6a1786936 100644 --- a/cmd/mdatagen/templates/component_test.go.tmpl +++ b/cmd/mdatagen/templates/component_test.go.tmpl @@ -261,12 +261,12 @@ func TestComponentLifecycle(t *testing.T) { tests := []struct{ name string - createFn func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) + createFn func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) }{ {{ if supportsLogs }} { name: "logs", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -274,7 +274,7 @@ func TestComponentLifecycle(t *testing.T) { {{ if supportsMetrics }} { name: "metrics", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateMetricsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -282,7 +282,7 @@ func TestComponentLifecycle(t *testing.T) { {{ if supportsTraces }} { name: "traces", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -299,7 +299,7 @@ func TestComponentLifecycle(t *testing.T) { for _, test := range tests { {{- if not .Tests.SkipShutdown }} t.Run(test.name + "-shutdown", func(t *testing.T) { - c, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + c, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) err = c.Shutdown(context.Background()) require.NoError(t, err) @@ -308,13 +308,13 @@ func TestComponentLifecycle(t *testing.T) { {{- if not .Tests.SkipLifecycle }} t.Run(test.name + "-lifecycle", func(t *testing.T) { - firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) host := componenttest.NewNopHost() require.NoError(t, err) require.NoError(t, firstRcvr.Start(context.Background(), host)) require.NoError(t, firstRcvr.Shutdown(context.Background())) - secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) require.NoError(t, secondRcvr.Start(context.Background(), host)) require.NoError(t, secondRcvr.Shutdown(context.Background())) diff --git a/cmd/mdatagen/templates/metrics.go.tmpl b/cmd/mdatagen/templates/metrics.go.tmpl index 14428451c1e..a084d847ee8 100644 --- a/cmd/mdatagen/templates/metrics.go.tmpl +++ b/cmd/mdatagen/templates/metrics.go.tmpl @@ -154,7 +154,7 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { } } -func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { +func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...metricBuilderOption) *MetricsBuilder { {{- range $name, $metric := .Metrics }} {{- if $metric.Warnings.IfEnabled }} if mbc.Metrics.{{ $name.Render }}.Enabled { diff --git a/cmd/mdatagen/templates/metrics_test.go.tmpl b/cmd/mdatagen/templates/metrics_test.go.tmpl index 13342842eab..f97e8ef8110 100644 --- a/cmd/mdatagen/templates/metrics_test.go.tmpl +++ b/cmd/mdatagen/templates/metrics_test.go.tmpl @@ -60,7 +60,7 @@ func TestMetricsBuilder(t *testing.T) { start := pcommon.Timestamp(1_000_000_000) ts := pcommon.Timestamp(1_000_001_000) observedZapCore, observedLogs := observer.New(zap.WarnLevel) - settings := receivertest.NewNopCreateSettings() + settings := receivertest.NewNopSettings() settings.Logger = zap.New(observedZapCore) mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) diff --git a/exporter/exportertest/contract_checker.go b/exporter/exportertest/contract_checker.go index 7b3f55c1902..cf9eec1dbb4 100644 --- a/exporter/exportertest/contract_checker.go +++ b/exporter/exportertest/contract_checker.go @@ -86,17 +86,17 @@ func checkConsumeContractScenario(t *testing.T, params CheckConsumeContractParam mockConsumerInstance := newMockConsumer(decisionFunc) switch params.DataType { case component.DataTypeLogs: - r, err := params.ReceiverFactory.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), params.ReceiverConfig, &mockConsumerInstance) + r, err := params.ReceiverFactory.CreateLogsReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance) require.NoError(t, err) require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) checkLogs(t, params, r, &mockConsumerInstance, checkIfTestPassed) case component.DataTypeTraces: - r, err := params.ReceiverFactory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), params.ReceiverConfig, &mockConsumerInstance) + r, err := params.ReceiverFactory.CreateTracesReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance) require.NoError(t, err) require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) checkTraces(t, params, r, &mockConsumerInstance, checkIfTestPassed) case component.DataTypeMetrics: - r, err := params.ReceiverFactory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), params.ReceiverConfig, &mockConsumerInstance) + r, err := params.ReceiverFactory.CreateMetricsReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance) require.NoError(t, err) require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) checkMetrics(t, params, r, &mockConsumerInstance, checkIfTestPassed) diff --git a/exporter/exportertest/contract_checker_test.go b/exporter/exportertest/contract_checker_test.go index 7b0a6d5abb3..97135bbb2c5 100644 --- a/exporter/exportertest/contract_checker_test.go +++ b/exporter/exportertest/contract_checker_test.go @@ -89,15 +89,15 @@ func newMockExporterFactory(mr *mockReceiver) exporter.Factory { func newMockReceiverFactory(mr *mockReceiver) receiver.Factory { return receiver.NewFactory(component.MustNewType("pass_through_receiver"), func() component.Config { return &nopConfig{} }, - receiver.WithTraces(func(_ context.Context, _ receiver.CreateSettings, _ component.Config, c consumer.Traces) (receiver.Traces, error) { + receiver.WithTraces(func(_ context.Context, _ receiver.Settings, _ component.Config, c consumer.Traces) (receiver.Traces, error) { mr.Traces = c return mr, nil }, component.StabilityLevelStable), - receiver.WithMetrics(func(_ context.Context, _ receiver.CreateSettings, _ component.Config, c consumer.Metrics) (receiver.Metrics, error) { + receiver.WithMetrics(func(_ context.Context, _ receiver.Settings, _ component.Config, c consumer.Metrics) (receiver.Metrics, error) { mr.Metrics = c return mr, nil }, component.StabilityLevelStable), - receiver.WithLogs(func(_ context.Context, _ receiver.CreateSettings, _ component.Config, c consumer.Logs) (receiver.Logs, error) { + receiver.WithLogs(func(_ context.Context, _ receiver.Settings, _ component.Config, c consumer.Logs) (receiver.Logs, error) { mr.Logs = c return mr, nil }, component.StabilityLevelStable), diff --git a/internal/e2e/otlphttp_test.go b/internal/e2e/otlphttp_test.go index b173dcf59d7..3c2f41ffc15 100644 --- a/internal/e2e/otlphttp_test.go +++ b/internal/e2e/otlphttp_test.go @@ -328,7 +328,7 @@ func createExporterConfig(baseURL string, defaultCfg component.Config) *otlphttp func startTracesReceiver(t *testing.T, addr string, next consumer.Traces) { factory := otlpreceiver.NewFactory() cfg := createReceiverConfig(addr, factory.CreateDefaultConfig()) - recv, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, next) + recv, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopSettings(), cfg, next) require.NoError(t, err) startAndCleanup(t, recv) } @@ -336,7 +336,7 @@ func startTracesReceiver(t *testing.T, addr string, next consumer.Traces) { func startMetricsReceiver(t *testing.T, addr string, next consumer.Metrics) { factory := otlpreceiver.NewFactory() cfg := createReceiverConfig(addr, factory.CreateDefaultConfig()) - recv, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, next) + recv, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopSettings(), cfg, next) require.NoError(t, err) startAndCleanup(t, recv) } @@ -344,7 +344,7 @@ func startMetricsReceiver(t *testing.T, addr string, next consumer.Metrics) { func startLogsReceiver(t *testing.T, addr string, next consumer.Logs) { factory := otlpreceiver.NewFactory() cfg := createReceiverConfig(addr, factory.CreateDefaultConfig()) - recv, err := factory.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, next) + recv, err := factory.CreateLogsReceiver(context.Background(), receivertest.NewNopSettings(), cfg, next) require.NoError(t, err) startAndCleanup(t, recv) } diff --git a/receiver/nopreceiver/generated_component_test.go b/receiver/nopreceiver/generated_component_test.go index 92e563ad645..9f4d59328e2 100644 --- a/receiver/nopreceiver/generated_component_test.go +++ b/receiver/nopreceiver/generated_component_test.go @@ -29,26 +29,26 @@ func TestComponentLifecycle(t *testing.T) { tests := []struct { name string - createFn func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) + createFn func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) }{ { name: "logs", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "metrics", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateMetricsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "traces", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -63,19 +63,19 @@ func TestComponentLifecycle(t *testing.T) { for _, test := range tests { t.Run(test.name+"-shutdown", func(t *testing.T) { - c, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + c, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) err = c.Shutdown(context.Background()) require.NoError(t, err) }) t.Run(test.name+"-lifecycle", func(t *testing.T) { - firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) host := componenttest.NewNopHost() require.NoError(t, err) require.NoError(t, firstRcvr.Start(context.Background(), host)) require.NoError(t, firstRcvr.Shutdown(context.Background())) - secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) require.NoError(t, secondRcvr.Start(context.Background(), host)) require.NoError(t, secondRcvr.Shutdown(context.Background())) diff --git a/receiver/nopreceiver/nop_receiver.go b/receiver/nopreceiver/nop_receiver.go index 2463a89ef65..6d989daffc9 100644 --- a/receiver/nopreceiver/nop_receiver.go +++ b/receiver/nopreceiver/nop_receiver.go @@ -22,15 +22,15 @@ func NewFactory() receiver.Factory { receiver.WithLogs(createLogs, metadata.LogsStability)) } -func createTraces(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) { +func createTraces(context.Context, receiver.Settings, component.Config, consumer.Traces) (receiver.Traces, error) { return nopInstance, nil } -func createMetrics(context.Context, receiver.CreateSettings, component.Config, consumer.Metrics) (receiver.Metrics, error) { +func createMetrics(context.Context, receiver.Settings, component.Config, consumer.Metrics) (receiver.Metrics, error) { return nopInstance, nil } -func createLogs(context.Context, receiver.CreateSettings, component.Config, consumer.Logs) (receiver.Logs, error) { +func createLogs(context.Context, receiver.Settings, component.Config, consumer.Logs) (receiver.Logs, error) { return nopInstance, nil } diff --git a/receiver/nopreceiver/nop_receiver_test.go b/receiver/nopreceiver/nop_receiver_test.go index 31f78e10756..85518f47a49 100644 --- a/receiver/nopreceiver/nop_receiver_test.go +++ b/receiver/nopreceiver/nop_receiver_test.go @@ -23,17 +23,17 @@ func TestNewNopFactory(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.Equal(t, &struct{}{}, cfg) - traces, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop()) + traces, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, traces.Shutdown(context.Background())) - metrics, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop()) + metrics, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, metrics.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, metrics.Shutdown(context.Background())) - logs, err := factory.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop()) + logs, err := factory.CreateLogsReceiver(context.Background(), receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, logs.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, logs.Shutdown(context.Background())) diff --git a/receiver/otlpreceiver/factory.go b/receiver/otlpreceiver/factory.go index 4b148c40be3..22181929879 100644 --- a/receiver/otlpreceiver/factory.go +++ b/receiver/otlpreceiver/factory.go @@ -64,7 +64,7 @@ func createDefaultConfig() component.Config { // createTraces creates a trace receiver based on provided config. func createTraces( _ context.Context, - set receiver.CreateSettings, + set receiver.Settings, cfg component.Config, nextConsumer consumer.Traces, ) (receiver.Traces, error) { @@ -87,7 +87,7 @@ func createTraces( // createMetrics creates a metrics receiver based on provided config. func createMetrics( _ context.Context, - set receiver.CreateSettings, + set receiver.Settings, cfg component.Config, consumer consumer.Metrics, ) (receiver.Metrics, error) { @@ -110,7 +110,7 @@ func createMetrics( // createLog creates a log receiver based on provided config. func createLog( _ context.Context, - set receiver.CreateSettings, + set receiver.Settings, cfg component.Config, consumer consumer.Logs, ) (receiver.Logs, error) { diff --git a/receiver/otlpreceiver/factory_test.go b/receiver/otlpreceiver/factory_test.go index d844760947f..4a4477f38c4 100644 --- a/receiver/otlpreceiver/factory_test.go +++ b/receiver/otlpreceiver/factory_test.go @@ -33,7 +33,7 @@ func TestCreateSameReceiver(t *testing.T) { cfg.GRPC.NetAddr.Endpoint = testutil.GetAvailableLocalAddress(t) cfg.HTTP.Endpoint = testutil.GetAvailableLocalAddress(t) - creationSet := receivertest.NewNopCreateSettings() + creationSet := receivertest.NewNopSettings() tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationSet, cfg, consumertest.NewNop()) assert.NotNil(t, tReceiver) assert.NoError(t, err) @@ -125,7 +125,7 @@ func TestCreateTracesReceiver(t *testing.T) { }, } ctx := context.Background() - creationSet := receivertest.NewNopCreateSettings() + creationSet := receivertest.NewNopSettings() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tr, err := factory.CreateTracesReceiver(ctx, creationSet, tt.cfg, tt.sink) @@ -219,7 +219,7 @@ func TestCreateMetricReceiver(t *testing.T) { }, } ctx := context.Background() - creationSet := receivertest.NewNopCreateSettings() + creationSet := receivertest.NewNopSettings() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mr, err := factory.CreateMetricsReceiver(ctx, creationSet, tt.cfg, tt.sink) @@ -313,7 +313,7 @@ func TestCreateLogReceiver(t *testing.T) { }, } ctx := context.Background() - creationSet := receivertest.NewNopCreateSettings() + creationSet := receivertest.NewNopSettings() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mr, err := factory.CreateLogsReceiver(ctx, creationSet, tt.cfg, tt.sink) diff --git a/receiver/otlpreceiver/generated_component_test.go b/receiver/otlpreceiver/generated_component_test.go index 0f54074cff2..6a4de81c668 100644 --- a/receiver/otlpreceiver/generated_component_test.go +++ b/receiver/otlpreceiver/generated_component_test.go @@ -29,26 +29,26 @@ func TestComponentLifecycle(t *testing.T) { tests := []struct { name string - createFn func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) + createFn func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) }{ { name: "logs", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "metrics", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateMetricsReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, { name: "traces", - createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop()) }, }, @@ -63,19 +63,19 @@ func TestComponentLifecycle(t *testing.T) { for _, test := range tests { t.Run(test.name+"-shutdown", func(t *testing.T) { - c, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + c, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) err = c.Shutdown(context.Background()) require.NoError(t, err) }) t.Run(test.name+"-lifecycle", func(t *testing.T) { - firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) host := componenttest.NewNopHost() require.NoError(t, err) require.NoError(t, firstRcvr.Start(context.Background(), host)) require.NoError(t, firstRcvr.Shutdown(context.Background())) - secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopSettings(), cfg) require.NoError(t, err) require.NoError(t, secondRcvr.Start(context.Background(), host)) require.NoError(t, secondRcvr.Shutdown(context.Background())) diff --git a/receiver/otlpreceiver/internal/logs/otlp_test.go b/receiver/otlpreceiver/internal/logs/otlp_test.go index 645be7e946e..4523f6eb36a 100644 --- a/receiver/otlpreceiver/internal/logs/otlp_test.go +++ b/receiver/otlpreceiver/internal/logs/otlp_test.go @@ -91,7 +91,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, lc consumer.Logs) net.Addr { require.NoError(t, ln.Close()) }) - set := receivertest.NewNopCreateSettings() + set := receivertest.NewNopSettings() set.ID = component.MustNewIDWithName("otlp", "log") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, diff --git a/receiver/otlpreceiver/internal/metrics/otlp_test.go b/receiver/otlpreceiver/internal/metrics/otlp_test.go index 3a87b34b724..f71be5d17ab 100644 --- a/receiver/otlpreceiver/internal/metrics/otlp_test.go +++ b/receiver/otlpreceiver/internal/metrics/otlp_test.go @@ -92,7 +92,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, mc consumer.Metrics) net.Addr { require.NoError(t, ln.Close()) }) - set := receivertest.NewNopCreateSettings() + set := receivertest.NewNopSettings() set.ID = component.MustNewIDWithName("otlp", "metrics") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, diff --git a/receiver/otlpreceiver/internal/trace/otlp_test.go b/receiver/otlpreceiver/internal/trace/otlp_test.go index ab538923729..c573471845d 100644 --- a/receiver/otlpreceiver/internal/trace/otlp_test.go +++ b/receiver/otlpreceiver/internal/trace/otlp_test.go @@ -88,7 +88,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, tc consumer.Traces) net.Addr { require.NoError(t, ln.Close()) }) - set := receivertest.NewNopCreateSettings() + set := receivertest.NewNopSettings() set.ID = component.MustNewIDWithName("otlp", "trace") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 43eed9b821a..95d782b880e 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -40,13 +40,13 @@ type otlpReceiver struct { obsrepGRPC *receiverhelper.ObsReport obsrepHTTP *receiverhelper.ObsReport - settings *receiver.CreateSettings + settings *receiver.Settings } // newOtlpReceiver just creates the OpenTelemetry receiver services. It is the caller's // responsibility to invoke the respective Start*Reception methods as well // as the various Stop*Reception methods to end it. -func newOtlpReceiver(cfg *Config, set *receiver.CreateSettings) (*otlpReceiver, error) { +func newOtlpReceiver(cfg *Config, set *receiver.Settings) (*otlpReceiver, error) { r := &otlpReceiver{ cfg: cfg, nextTraces: nil, diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 14eecbcdac1..ef5db33765b 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -701,7 +701,7 @@ func TestGRPCInvalidTLSCredentials(t *testing.T) { r, err := NewFactory().CreateTracesReceiver( context.Background(), - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) @@ -770,7 +770,7 @@ func TestHTTPInvalidTLSCredentials(t *testing.T) { // TLS is resolved during Start for HTTP. r, err := NewFactory().CreateTracesReceiver( context.Background(), - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) @@ -836,7 +836,7 @@ func newHTTPReceiver(t *testing.T, settings component.TelemetrySettings, endpoin } func newReceiver(t *testing.T, settings component.TelemetrySettings, cfg *Config, id component.ID, c consumertest.Consumer) component.Component { - set := receivertest.NewNopCreateSettings() + set := receivertest.NewNopSettings() set.TelemetrySettings = settings set.ID = id r, err := newOtlpReceiver(cfg, &set) @@ -998,7 +998,7 @@ func TestShutdown(t *testing.T) { cfg := factory.CreateDefaultConfig().(*Config) cfg.GRPC.NetAddr.Endpoint = endpointGrpc cfg.HTTP.Endpoint = endpointHTTP - set := receivertest.NewNopCreateSettings() + set := receivertest.NewNopSettings() set.ID = otlpReceiverID r, err := NewFactory().CreateTracesReceiver( context.Background(), diff --git a/receiver/receiver.go b/receiver/receiver.go index 3b0f0ac8371..3122f6bcd6d 100644 --- a/receiver/receiver.go +++ b/receiver/receiver.go @@ -46,7 +46,12 @@ type Logs interface { } // CreateSettings configures Receiver creators. -type CreateSettings struct { +// +// Deprecated: [v0.103.0] Use receiver.Settings instead. +type CreateSettings = Settings + +// Settings configures Receiver creators. +type Settings struct { // ID returns the ID of the component that will be created. ID component.ID @@ -66,7 +71,7 @@ type Factory interface { // CreateTracesReceiver creates a TracesReceiver based on this config. // If the receiver type does not support tracing or if the config is not valid // an error will be returned instead. `nextConsumer` is never nil. - CreateTracesReceiver(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (Traces, error) + CreateTracesReceiver(ctx context.Context, set Settings, cfg component.Config, nextConsumer consumer.Traces) (Traces, error) // TracesReceiverStability gets the stability level of the TracesReceiver. TracesReceiverStability() component.StabilityLevel @@ -74,7 +79,7 @@ type Factory interface { // CreateMetricsReceiver creates a MetricsReceiver based on this config. // If the receiver type does not support metrics or if the config is not valid // an error will be returned instead. `nextConsumer` is never nil. - CreateMetricsReceiver(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (Metrics, error) + CreateMetricsReceiver(ctx context.Context, set Settings, cfg component.Config, nextConsumer consumer.Metrics) (Metrics, error) // MetricsReceiverStability gets the stability level of the MetricsReceiver. MetricsReceiverStability() component.StabilityLevel @@ -82,7 +87,7 @@ type Factory interface { // CreateLogsReceiver creates a LogsReceiver based on this config. // If the receiver type does not support the data type or if the config is not valid // an error will be returned instead. `nextConsumer` is never nil. - CreateLogsReceiver(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Logs) (Logs, error) + CreateLogsReceiver(ctx context.Context, set Settings, cfg component.Config, nextConsumer consumer.Logs) (Logs, error) // LogsReceiverStability gets the stability level of the LogsReceiver. LogsReceiverStability() component.StabilityLevel @@ -104,12 +109,12 @@ func (f factoryOptionFunc) applyOption(o *factory) { } // CreateTracesFunc is the equivalent of Factory.CreateTraces. -type CreateTracesFunc func(context.Context, CreateSettings, component.Config, consumer.Traces) (Traces, error) +type CreateTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) // CreateTracesReceiver implements Factory.CreateTracesReceiver(). func (f CreateTracesFunc) CreateTracesReceiver( ctx context.Context, - set CreateSettings, + set Settings, cfg component.Config, nextConsumer consumer.Traces) (Traces, error) { if f == nil { @@ -119,12 +124,12 @@ func (f CreateTracesFunc) CreateTracesReceiver( } // CreateMetricsFunc is the equivalent of Factory.CreateMetrics. -type CreateMetricsFunc func(context.Context, CreateSettings, component.Config, consumer.Metrics) (Metrics, error) +type CreateMetricsFunc func(context.Context, Settings, component.Config, consumer.Metrics) (Metrics, error) // CreateMetricsReceiver implements Factory.CreateMetricsReceiver(). func (f CreateMetricsFunc) CreateMetricsReceiver( ctx context.Context, - set CreateSettings, + set Settings, cfg component.Config, nextConsumer consumer.Metrics, ) (Metrics, error) { @@ -135,12 +140,12 @@ func (f CreateMetricsFunc) CreateMetricsReceiver( } // CreateLogsFunc is the equivalent of ReceiverFactory.CreateLogsReceiver(). -type CreateLogsFunc func(context.Context, CreateSettings, component.Config, consumer.Logs) (Logs, error) +type CreateLogsFunc func(context.Context, Settings, component.Config, consumer.Logs) (Logs, error) // CreateLogsReceiver implements Factory.CreateLogsReceiver(). func (f CreateLogsFunc) CreateLogsReceiver( ctx context.Context, - set CreateSettings, + set Settings, cfg component.Config, nextConsumer consumer.Logs, ) (Logs, error) { @@ -240,7 +245,7 @@ func NewBuilder(cfgs map[component.ID]component.Config, factories map[component. } // CreateTraces creates a Traces receiver based on the settings and config. -func (b *Builder) CreateTraces(ctx context.Context, set CreateSettings, next consumer.Traces) (Traces, error) { +func (b *Builder) CreateTraces(ctx context.Context, set Settings, next consumer.Traces) (Traces, error) { if next == nil { return nil, errNilNextConsumer } @@ -259,7 +264,7 @@ func (b *Builder) CreateTraces(ctx context.Context, set CreateSettings, next con } // CreateMetrics creates a Metrics receiver based on the settings and config. -func (b *Builder) CreateMetrics(ctx context.Context, set CreateSettings, next consumer.Metrics) (Metrics, error) { +func (b *Builder) CreateMetrics(ctx context.Context, set Settings, next consumer.Metrics) (Metrics, error) { if next == nil { return nil, errNilNextConsumer } @@ -278,7 +283,7 @@ func (b *Builder) CreateMetrics(ctx context.Context, set CreateSettings, next co } // CreateLogs creates a Logs receiver based on the settings and config. -func (b *Builder) CreateLogs(ctx context.Context, set CreateSettings, next consumer.Logs) (Logs, error) { +func (b *Builder) CreateLogs(ctx context.Context, set Settings, next consumer.Logs) (Logs, error) { if next == nil { return nil, errNilNextConsumer } diff --git a/receiver/receiver_test.go b/receiver/receiver_test.go index 00b93dba549..6004d83d3b3 100644 --- a/receiver/receiver_test.go +++ b/receiver/receiver_test.go @@ -24,11 +24,11 @@ func TestNewFactory(t *testing.T) { func() component.Config { return &defaultCfg }) assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - _, err := factory.CreateTracesReceiver(context.Background(), CreateSettings{}, &defaultCfg, consumertest.NewNop()) + _, err := factory.CreateTracesReceiver(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) assert.Error(t, err) - _, err = factory.CreateMetricsReceiver(context.Background(), CreateSettings{}, &defaultCfg, consumertest.NewNop()) + _, err = factory.CreateMetricsReceiver(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) assert.Error(t, err) - _, err = factory.CreateLogsReceiver(context.Background(), CreateSettings{}, &defaultCfg, consumertest.NewNop()) + _, err = factory.CreateLogsReceiver(context.Background(), Settings{}, &defaultCfg, consumertest.NewNop()) assert.Error(t, err) } @@ -45,15 +45,15 @@ func TestNewFactoryWithOptions(t *testing.T) { assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelDeprecated, factory.TracesReceiverStability()) - _, err := factory.CreateTracesReceiver(context.Background(), CreateSettings{}, &defaultCfg, nil) + _, err := factory.CreateTracesReceiver(context.Background(), Settings{}, &defaultCfg, nil) assert.NoError(t, err) assert.Equal(t, component.StabilityLevelAlpha, factory.MetricsReceiverStability()) - _, err = factory.CreateMetricsReceiver(context.Background(), CreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateMetricsReceiver(context.Background(), Settings{}, &defaultCfg, nil) assert.NoError(t, err) assert.Equal(t, component.StabilityLevelStable, factory.LogsReceiverStability()) - _, err = factory.CreateLogsReceiver(context.Background(), CreateSettings{}, &defaultCfg, nil) + _, err = factory.CreateLogsReceiver(context.Background(), Settings{}, &defaultCfg, nil) assert.NoError(t, err) } @@ -162,7 +162,7 @@ func TestBuilder(t *testing.T) { cfgs := map[component.ID]component.Config{tt.id: defaultCfg} b := NewBuilder(cfgs, factories) - te, err := b.CreateTraces(context.Background(), createSettings(tt.id), tt.nextTraces) + te, err := b.CreateTraces(context.Background(), settings(tt.id), tt.nextTraces) if tt.err != "" { assert.EqualError(t, err, tt.err) assert.Nil(t, te) @@ -171,7 +171,7 @@ func TestBuilder(t *testing.T) { assert.Equal(t, nopInstance, te) } - me, err := b.CreateMetrics(context.Background(), createSettings(tt.id), tt.nextMetrics) + me, err := b.CreateMetrics(context.Background(), settings(tt.id), tt.nextMetrics) if tt.err != "" { assert.EqualError(t, err, tt.err) assert.Nil(t, me) @@ -180,7 +180,7 @@ func TestBuilder(t *testing.T) { assert.Equal(t, nopInstance, me) } - le, err := b.CreateLogs(context.Background(), createSettings(tt.id), tt.nextLogs) + le, err := b.CreateLogs(context.Background(), settings(tt.id), tt.nextLogs) if tt.err != "" { assert.EqualError(t, err, tt.err) assert.Nil(t, le) @@ -209,15 +209,15 @@ func TestBuilderMissingConfig(t *testing.T) { bErr := NewBuilder(map[component.ID]component.Config{}, factories) missingID := component.MustNewIDWithName("all", "missing") - te, err := bErr.CreateTraces(context.Background(), createSettings(missingID), consumertest.NewNop()) + te, err := bErr.CreateTraces(context.Background(), settings(missingID), consumertest.NewNop()) assert.EqualError(t, err, "receiver \"all/missing\" is not configured") assert.Nil(t, te) - me, err := bErr.CreateMetrics(context.Background(), createSettings(missingID), consumertest.NewNop()) + me, err := bErr.CreateMetrics(context.Background(), settings(missingID), consumertest.NewNop()) assert.EqualError(t, err, "receiver \"all/missing\" is not configured") assert.Nil(t, me) - le, err := bErr.CreateLogs(context.Background(), createSettings(missingID), consumertest.NewNop()) + le, err := bErr.CreateLogs(context.Background(), settings(missingID), consumertest.NewNop()) assert.EqualError(t, err, "receiver \"all/missing\" is not configured") assert.Nil(t, le) } @@ -244,20 +244,20 @@ type nopReceiver struct { consumertest.Consumer } -func createTraces(context.Context, CreateSettings, component.Config, consumer.Traces) (Traces, error) { +func createTraces(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) { return nopInstance, nil } -func createMetrics(context.Context, CreateSettings, component.Config, consumer.Metrics) (Metrics, error) { +func createMetrics(context.Context, Settings, component.Config, consumer.Metrics) (Metrics, error) { return nopInstance, nil } -func createLogs(context.Context, CreateSettings, component.Config, consumer.Logs) (Logs, error) { +func createLogs(context.Context, Settings, component.Config, consumer.Logs) (Logs, error) { return nopInstance, nil } -func createSettings(id component.ID) CreateSettings { - return CreateSettings{ +func settings(id component.ID) Settings { + return Settings{ ID: id, TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), diff --git a/receiver/receiverhelper/generated_component_telemetry_test.go b/receiver/receiverhelper/generated_component_telemetry_test.go index 41d3c0bf81f..e858cbac476 100644 --- a/receiver/receiverhelper/generated_component_telemetry_test.go +++ b/receiver/receiverhelper/generated_component_telemetry_test.go @@ -21,8 +21,8 @@ type componentTestTelemetry struct { meterProvider *sdkmetric.MeterProvider } -func (tt *componentTestTelemetry) NewCreateSettings() receiver.CreateSettings { - settings := receivertest.NewNopCreateSettings() +func (tt *componentTestTelemetry) NewSettings() receiver.Settings { + settings := receivertest.NewNopSettings() settings.MeterProvider = tt.meterProvider settings.ID = component.NewID(component.MustNewType("receiverhelper")) diff --git a/receiver/receiverhelper/obsreport.go b/receiver/receiverhelper/obsreport.go index 18ff7556454..e5d6fd9b0b7 100644 --- a/receiver/receiverhelper/obsreport.go +++ b/receiver/receiverhelper/obsreport.go @@ -44,7 +44,7 @@ type ObsReportSettings struct { // eg.: a gRPC stream, for which many batches of data are received in individual // operations without a corresponding new context per operation. LongLivedCtx bool - ReceiverCreateSettings receiver.CreateSettings + ReceiverCreateSettings receiver.Settings } // NewObsReport creates a new ObsReport. diff --git a/receiver/receiverhelper/obsreport_test.go b/receiver/receiverhelper/obsreport_test.go index b6d52f9bed0..2400d02672a 100644 --- a/receiver/receiverhelper/obsreport_test.go +++ b/receiver/receiverhelper/obsreport_test.go @@ -48,7 +48,7 @@ func TestReceiveTraceDataOp(t *testing.T) { rec, err := newReceiver(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := rec.StartTracesOp(parentCtx) @@ -95,7 +95,7 @@ func TestReceiveLogsOp(t *testing.T) { rec, err := newReceiver(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) @@ -143,7 +143,7 @@ func TestReceiveMetricsOp(t *testing.T) { rec, err := newReceiver(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) @@ -198,7 +198,7 @@ func TestReceiveWithLongLivedCtx(t *testing.T) { ReceiverID: receiverID, Transport: transport, LongLivedCtx: true, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, rerr) ctx := rec.StartTracesOp(longLivedCtx) @@ -241,7 +241,7 @@ func TestCheckReceiverTracesViews(t *testing.T) { rec, err := NewObsReport(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := rec.StartTracesOp(context.Background()) @@ -262,7 +262,7 @@ func TestCheckReceiverMetricsViews(t *testing.T) { rec, err := NewObsReport(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := rec.StartMetricsOp(context.Background()) @@ -283,7 +283,7 @@ func TestCheckReceiverLogsViews(t *testing.T) { rec, err := NewObsReport(ObsReportSettings{ ReceiverID: receiverID, Transport: transport, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := rec.StartLogsOp(context.Background()) diff --git a/receiver/receivertest/contract_checker.go b/receiver/receivertest/contract_checker.go index 6951b5f41f4..d52e1d3a60f 100644 --- a/receiver/receivertest/contract_checker.go +++ b/receiver/receivertest/contract_checker.go @@ -113,11 +113,11 @@ func checkConsumeContractScenario(params CheckConsumeContractParams, decisionFun var err error switch params.DataType { case component.DataTypeLogs: - receiver, err = params.Factory.CreateLogsReceiver(ctx, NewNopCreateSettings(), params.Config, consumer) + receiver, err = params.Factory.CreateLogsReceiver(ctx, NewNopSettings(), params.Config, consumer) case component.DataTypeTraces: - receiver, err = params.Factory.CreateTracesReceiver(ctx, NewNopCreateSettings(), params.Config, consumer) + receiver, err = params.Factory.CreateTracesReceiver(ctx, NewNopSettings(), params.Config, consumer) case component.DataTypeMetrics: - receiver, err = params.Factory.CreateMetricsReceiver(ctx, NewNopCreateSettings(), params.Config, consumer) + receiver, err = params.Factory.CreateMetricsReceiver(ctx, NewNopSettings(), params.Config, consumer) default: require.FailNow(params.T, "must specify a valid DataType to test for") } diff --git a/receiver/receivertest/contract_checker_test.go b/receiver/receivertest/contract_checker_test.go index 57906308400..9a646dde06f 100644 --- a/receiver/receivertest/contract_checker_test.go +++ b/receiver/receivertest/contract_checker_test.go @@ -203,13 +203,13 @@ func newExampleFactory() receiver.Factory { ) } -func createTrace(_ context.Context, _ receiver.CreateSettings, cfg component.Config, consumer consumer.Traces) (receiver.Traces, error) { +func createTrace(_ context.Context, _ receiver.Settings, cfg component.Config, consumer consumer.Traces) (receiver.Traces, error) { rcv := &exampleReceiver{nextTracesConsumer: consumer} cfg.(*exampleReceiverConfig).generator.(*exampleTraceGenerator).receiver = rcv return rcv, nil } -func createMetric(_ context.Context, _ receiver.CreateSettings, cfg component.Config, consumer consumer.Metrics) (receiver.Metrics, error) { +func createMetric(_ context.Context, _ receiver.Settings, cfg component.Config, consumer consumer.Metrics) (receiver.Metrics, error) { rcv := &exampleReceiver{nextMetricsConsumer: consumer} cfg.(*exampleReceiverConfig).generator.(*exampleMetricGenerator).receiver = rcv return rcv, nil @@ -217,7 +217,7 @@ func createMetric(_ context.Context, _ receiver.CreateSettings, cfg component.Co func createLog( _ context.Context, - _ receiver.CreateSettings, + _ receiver.Settings, cfg component.Config, consumer consumer.Logs, ) (receiver.Logs, error) { diff --git a/receiver/receivertest/nop_receiver.go b/receiver/receivertest/nop_receiver.go index e9cec06ca1b..0b07398a9ee 100644 --- a/receiver/receivertest/nop_receiver.go +++ b/receiver/receivertest/nop_receiver.go @@ -17,8 +17,15 @@ import ( var defaultComponentType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for Create*Receiver functions. -func NewNopCreateSettings() receiver.CreateSettings { - return receiver.CreateSettings{ +// +// Deprecated: [v0.103.0] Use receivertest.NewNopSettings instead. +func NewNopCreateSettings() receiver.Settings { + return NewNopSettings() +} + +// NewNopSettings returns a new nop settings for Create*Receiver functions. +func NewNopSettings() receiver.Settings { + return receiver.Settings{ ID: component.NewIDWithName(defaultComponentType, uuid.NewString()), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), @@ -56,15 +63,15 @@ func NewNopFactoryForType(dataType component.DataType) receiver.Factory { type nopConfig struct{} -func createTraces(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) { +func createTraces(context.Context, receiver.Settings, component.Config, consumer.Traces) (receiver.Traces, error) { return nopInstance, nil } -func createMetrics(context.Context, receiver.CreateSettings, component.Config, consumer.Metrics) (receiver.Metrics, error) { +func createMetrics(context.Context, receiver.Settings, component.Config, consumer.Metrics) (receiver.Metrics, error) { return nopInstance, nil } -func createLogs(context.Context, receiver.CreateSettings, component.Config, consumer.Logs) (receiver.Logs, error) { +func createLogs(context.Context, receiver.Settings, component.Config, consumer.Logs) (receiver.Logs, error) { return nopInstance, nil } diff --git a/receiver/receivertest/nop_receiver_test.go b/receiver/receivertest/nop_receiver_test.go index d384e6b1fb7..345eef005ff 100644 --- a/receiver/receivertest/nop_receiver_test.go +++ b/receiver/receivertest/nop_receiver_test.go @@ -24,17 +24,17 @@ func TestNewNopFactory(t *testing.T) { cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) - traces, err := factory.CreateTracesReceiver(context.Background(), NewNopCreateSettings(), cfg, consumertest.NewNop()) + traces, err := factory.CreateTracesReceiver(context.Background(), NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, traces.Shutdown(context.Background())) - metrics, err := factory.CreateMetricsReceiver(context.Background(), NewNopCreateSettings(), cfg, consumertest.NewNop()) + metrics, err := factory.CreateMetricsReceiver(context.Background(), NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, metrics.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, metrics.Shutdown(context.Background())) - logs, err := factory.CreateLogsReceiver(context.Background(), NewNopCreateSettings(), cfg, consumertest.NewNop()) + logs, err := factory.CreateLogsReceiver(context.Background(), NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) assert.NoError(t, logs.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, logs.Shutdown(context.Background())) @@ -46,7 +46,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() - set := NewNopCreateSettings() + set := NewNopSettings() set.ID = component.NewID(nopType) traces, err := factory.CreateTracesReceiver(context.Background(), set, cfg, consumertest.NewNop()) diff --git a/receiver/scraperhelper/generated_component_telemetry_test.go b/receiver/scraperhelper/generated_component_telemetry_test.go index 7eeed50b953..d0e9d175ff9 100644 --- a/receiver/scraperhelper/generated_component_telemetry_test.go +++ b/receiver/scraperhelper/generated_component_telemetry_test.go @@ -21,8 +21,8 @@ type componentTestTelemetry struct { meterProvider *sdkmetric.MeterProvider } -func (tt *componentTestTelemetry) NewCreateSettings() receiver.CreateSettings { - settings := receivertest.NewNopCreateSettings() +func (tt *componentTestTelemetry) NewSettings() receiver.Settings { + settings := receivertest.NewNopSettings() settings.MeterProvider = tt.meterProvider settings.ID = component.NewID(component.MustNewType("scraperhelper")) diff --git a/receiver/scraperhelper/obsreport.go b/receiver/scraperhelper/obsreport.go index 9c10f7002a8..c7cb1b1dbeb 100644 --- a/receiver/scraperhelper/obsreport.go +++ b/receiver/scraperhelper/obsreport.go @@ -38,7 +38,7 @@ type ObsReport struct { type ObsReportSettings struct { ReceiverID component.ID Scraper component.ID - ReceiverCreateSettings receiver.CreateSettings + ReceiverCreateSettings receiver.Settings } // NewObsReport creates a new ObsReport. diff --git a/receiver/scraperhelper/obsreport_test.go b/receiver/scraperhelper/obsreport_test.go index 5e807962f0d..94d58f18d97 100644 --- a/receiver/scraperhelper/obsreport_test.go +++ b/receiver/scraperhelper/obsreport_test.go @@ -47,7 +47,7 @@ func TestScrapeMetricsDataOp(t *testing.T) { scrp, err := newScraper(ObsReportSettings{ ReceiverID: receiverID, Scraper: scraperID, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := scrp.StartMetricsOp(parentCtx) @@ -98,7 +98,7 @@ func TestCheckScraperMetricsViews(t *testing.T) { s, err := NewObsReport(ObsReportSettings{ ReceiverID: receiverID, Scraper: scraperID, - ReceiverCreateSettings: receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, + ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, }) require.NoError(t, err) ctx := s.StartMetricsOp(context.Background()) diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index eb13ee66cc4..eed33fd2193 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -60,13 +60,13 @@ type controller struct { terminated chan struct{} obsrecv *receiverhelper.ObsReport - recvSettings receiver.CreateSettings + recvSettings receiver.Settings } // NewScraperControllerReceiver creates a Receiver with the configured options, that can control multiple scrapers. func NewScraperControllerReceiver( cfg *ControllerConfig, - set receiver.CreateSettings, + set receiver.Settings, nextConsumer consumer.Metrics, options ...ScraperControllerOption, ) (component.Component, error) { diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index 1c41258ff18..f056a7eb8d2 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -145,7 +145,7 @@ func TestScrapeController(t *testing.T) { cfg = test.scraperControllerSettings } - mr, err := NewScraperControllerReceiver(cfg, receiver.CreateSettings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, sink, options...) + mr, err := NewScraperControllerReceiver(cfg, receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()}, sink, options...) if test.expectedNewErr != "" { assert.EqualError(t, err, test.expectedNewErr) return @@ -330,7 +330,7 @@ func TestSingleScrapePerInterval(t *testing.T) { receiver, err := NewScraperControllerReceiver( cfg, - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), new(consumertest.MetricsSink), AddScraper(scp), WithTickerChannel(tickerCh), @@ -375,7 +375,7 @@ func TestScrapeControllerStartsOnInit(t *testing.T) { CollectionInterval: time.Hour, InitialDelay: 0, }, - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), new(consumertest.MetricsSink), AddScraper(scp), ) @@ -411,7 +411,7 @@ func TestScrapeControllerInitialDelay(t *testing.T) { r, err := NewScraperControllerReceiver( &cfg, - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), new(consumertest.MetricsSink), AddScraper(scp), ) diff --git a/service/internal/graph/graph_test.go b/service/internal/graph/graph_test.go index 343f752b888..c93a0db5771 100644 --- a/service/internal/graph/graph_test.go +++ b/service/internal/graph/graph_test.go @@ -2456,13 +2456,13 @@ func newBadConnectorFactory() connector.Factory { func newErrReceiverFactory() receiver.Factory { return receiver.NewFactory(component.MustNewType("err"), func() component.Config { return &struct{}{} }, - receiver.WithTraces(func(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) { + receiver.WithTraces(func(context.Context, receiver.Settings, component.Config, consumer.Traces) (receiver.Traces, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - receiver.WithLogs(func(context.Context, receiver.CreateSettings, component.Config, consumer.Logs) (receiver.Logs, error) { + receiver.WithLogs(func(context.Context, receiver.Settings, component.Config, consumer.Logs) (receiver.Logs, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), - receiver.WithMetrics(func(context.Context, receiver.CreateSettings, component.Config, consumer.Metrics) (receiver.Metrics, error) { + receiver.WithMetrics(func(context.Context, receiver.Settings, component.Config, consumer.Metrics) (receiver.Metrics, error) { return &errComponent{}, nil }, component.StabilityLevelUndefined), ) diff --git a/service/internal/graph/nodes.go b/service/internal/graph/nodes.go index 238bbf3b287..757e52c09bc 100644 --- a/service/internal/graph/nodes.go +++ b/service/internal/graph/nodes.go @@ -73,7 +73,7 @@ func (n *receiverNode) buildComponent(ctx context.Context, builder *receiver.Builder, nexts []baseConsumer, ) error { - set := receiver.CreateSettings{ID: n.componentID, TelemetrySettings: tel, BuildInfo: info} + set := receiver.Settings{ID: n.componentID, TelemetrySettings: tel, BuildInfo: info} set.TelemetrySettings.Logger = components.ReceiverLogger(tel.Logger, n.componentID, n.pipelineType) var err error switch n.pipelineType { diff --git a/service/internal/testcomponents/example_receiver.go b/service/internal/testcomponents/example_receiver.go index 34b0372b03b..b1287babc58 100644 --- a/service/internal/testcomponents/example_receiver.go +++ b/service/internal/testcomponents/example_receiver.go @@ -28,7 +28,7 @@ func createReceiverDefaultConfig() component.Config { // createTracesReceiver creates a trace receiver based on this config. func createTracesReceiver( _ context.Context, - _ receiver.CreateSettings, + _ receiver.Settings, cfg component.Config, nextConsumer consumer.Traces, ) (receiver.Traces, error) { @@ -40,7 +40,7 @@ func createTracesReceiver( // createMetricsReceiver creates a metrics receiver based on this config. func createMetricsReceiver( _ context.Context, - _ receiver.CreateSettings, + _ receiver.Settings, cfg component.Config, nextConsumer consumer.Metrics, ) (receiver.Metrics, error) { @@ -51,7 +51,7 @@ func createMetricsReceiver( func createLogsReceiver( _ context.Context, - _ receiver.CreateSettings, + _ receiver.Settings, cfg component.Config, nextConsumer consumer.Logs, ) (receiver.Logs, error) {