Skip to content

Commit

Permalink
[receiver] deprecate CreateSettings -> Settings (open-telemetry#10333)
Browse files Browse the repository at this point in the history
This deprecates CreateSettings in favour of Settings.
NewNopCreateSettings is also being deprecated in favour of
NewNopSettings

Part of open-telemetry#9428

---------

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten authored Jun 5, 2024
1 parent d5dd7a6 commit 1e44a9c
Show file tree
Hide file tree
Showing 42 changed files with 194 additions and 143 deletions.
28 changes: 28 additions & 0 deletions .chloggen/codeboten_create-settings-receiver.yaml
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 3 additions & 3 deletions cmd/mdatagen/internal/samplereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions cmd/mdatagen/internal/samplereceiver/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/mdatagen/internal/samplereceiver/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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())
}

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{
{
Expand Down
11 changes: 11 additions & 0 deletions cmd/mdatagen/templates/component_telemetry_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +39,7 @@ func (tt *componentTestTelemetry) NewCreateSettings() {{ .Status.Class }}.Create
return settings
}

{{ end }}
func setupTestTelemetry() componentTestTelemetry {
reader := sdkmetric.NewManualReader()
return componentTestTelemetry{
Expand Down
14 changes: 7 additions & 7 deletions cmd/mdatagen/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,28 @@ 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())
},
},
{{ end }}
{{ 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())
},
},
{{ end }}
{{ 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())
},
},
Expand All @@ -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)
Expand All @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/metrics.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/metrics_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions exporter/exportertest/contract_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions exporter/exportertest/contract_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions internal/e2e/otlphttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,23 @@ 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)
}

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)
}

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)
}
Expand Down
14 changes: 7 additions & 7 deletions receiver/nopreceiver/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions receiver/nopreceiver/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit 1e44a9c

Please sign in to comment.