Skip to content

Commit

Permalink
Deprecate funcs that repeate receiver in name (#11287)
Browse files Browse the repository at this point in the history
This change makes the names to be more "Go" friendly. Also it will not
become an issue that types will try to implement different Factory types
(receiver,processor) because that is forbidden because of our design.
This also makes the names consistent with connector.Factory.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 30, 2024
1 parent 42ec1f1 commit bce1040
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 161 deletions.
27 changes: 27 additions & 0 deletions .chloggen/deprecate-receiver-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 funcs that repeat "receiver" in name

# One or more tracking issues or pull requests related to the change
issues: [11287]

# (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: |
Factory.Create[Traces|Metrics|Logs|Profiles]Receiver -> Factory.Create[Traces|Metrics|Logs|Profiles]
Factory.[Traces|Metrics|Logs|Profiles]ReceiverStability -> Factory.[Traces|Metrics|Logs|Profiles]Stability
# 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]

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

2 changes: 1 addition & 1 deletion cmd/mdatagen/internal/samplereceiver/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGeneratedMetrics(t *testing.T) {
func TestComponentTelemetry(t *testing.T) {
tt := setupTestTelemetry()
factory := NewFactory()
receiver, err := factory.CreateMetricsReceiver(context.Background(), tt.NewSettings(), componenttest.NewNopHost(), new(consumertest.MetricsSink))
receiver, err := factory.CreateMetrics(context.Background(), tt.NewSettings(), componenttest.NewNopHost(), new(consumertest.MetricsSink))
require.NoError(t, err)
tt.assertMetrics(t, []metricdata.Metrics{
{
Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/internal/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,23 @@ func TestComponentLifecycle(t *testing.T) {
{
name: "logs",
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop())
return factory.CreateLogs(ctx, set, cfg, consumertest.NewNop())
},
},
{{ end }}
{{ if supportsMetrics }}
{
name: "metrics",
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateMetricsReceiver(ctx, set, cfg, consumertest.NewNop())
return factory.CreateMetrics(ctx, set, cfg, consumertest.NewNop())
},
},
{{ end }}
{{ if supportsTraces }}
{
name: "traces",
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) {
return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop())
return factory.CreateTraces(ctx, set, cfg, consumertest.NewNop())
},
},
{{ end }}
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 @@ -92,17 +92,17 @@ func checkConsumeContractScenario(t *testing.T, params CheckConsumeContractParam
mockConsumerInstance := newMockConsumer(decisionFunc)
switch params.Signal {
case pipeline.SignalLogs:
r, err := params.ReceiverFactory.CreateLogsReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance)
r, err := params.ReceiverFactory.CreateLogs(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 pipeline.SignalTraces:
r, err := params.ReceiverFactory.CreateTracesReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance)
r, err := params.ReceiverFactory.CreateTraces(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 pipeline.SignalMetrics:
r, err := params.ReceiverFactory.CreateMetricsReceiver(context.Background(), receivertest.NewNopSettings(), params.ReceiverConfig, &mockConsumerInstance)
r, err := params.ReceiverFactory.CreateMetrics(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 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.NewNopSettings(), cfg, next)
recv, err := factory.CreateTraces(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.NewNopSettings(), cfg, next)
recv, err := factory.CreateMetrics(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.NewNopSettings(), cfg, next)
recv, err := factory.CreateLogs(context.Background(), receivertest.NewNopSettings(), cfg, next)
require.NoError(t, err)
startAndCleanup(t, recv)
}
Expand Down
6 changes: 3 additions & 3 deletions otelcol/command_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
Name: rcv.Type(),
Module: factories.ReceiverModules[rcv.Type()],
Stability: map[string]string{
"logs": rcv.LogsReceiverStability().String(),
"metrics": rcv.MetricsReceiverStability().String(),
"traces": rcv.TracesReceiverStability().String(),
"logs": rcv.LogsStability().String(),
"metrics": rcv.MetricsStability().String(),
"traces": rcv.TracesStability().String(),
},
})
}
Expand Down
6 changes: 3 additions & 3 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_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ func TestNewNopFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &struct{}{}, cfg)

traces, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopSettings(), cfg, consumertest.NewNop())
traces, err := factory.CreateTraces(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.NewNopSettings(), cfg, consumertest.NewNop())
metrics, err := factory.CreateMetrics(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.NewNopSettings(), cfg, consumertest.NewNop())
logs, err := factory.CreateLogs(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()))
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func createProfiles(
}

// This is the map of already created OTLP receivers for particular configurations.
// We maintain this map because the Factory is asked trace and metric receivers separately
// when it gets CreateTracesReceiver() and CreateMetricsReceiver() but they must not
// We maintain this map because the receiver.Factory is asked trace and metric receivers separately
// when it gets CreateTraces() and CreateMetrics() but they must not
// create separate objects, they must use one otlpReceiver object per configuration.
// When the receiver is shutdown it should be removed from this map so the same configuration
// can be recreated successfully.
Expand Down
24 changes: 12 additions & 12 deletions receiver/otlpreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ func TestCreateSameReceiver(t *testing.T) {
cfg.HTTP.Endpoint = testutil.GetAvailableLocalAddress(t)

creationSet := receivertest.NewNopSettings()
tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
tReceiver, err := factory.CreateTraces(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.NotNil(t, tReceiver)
require.NoError(t, err)

mReceiver, err := factory.CreateMetricsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
mReceiver, err := factory.CreateMetrics(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.NotNil(t, mReceiver)
require.NoError(t, err)

lReceiver, err := factory.CreateMetricsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
lReceiver, err := factory.CreateMetrics(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.NotNil(t, lReceiver)
require.NoError(t, err)

pReceiver, err := factory.(receiverprofiles.Factory).CreateProfilesReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
pReceiver, err := factory.(receiverprofiles.Factory).CreateProfiles(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.NotNil(t, pReceiver)
require.NoError(t, err)

Expand All @@ -57,7 +57,7 @@ func TestCreateSameReceiver(t *testing.T) {
assert.Same(t, tReceiver, pReceiver)
}

func TestCreateTracesReceiver(t *testing.T) {
func TestCreateTraces(t *testing.T) {
factory := NewFactory()
defaultGRPCSettings := &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestCreateTracesReceiver(t *testing.T) {
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)
tr, err := factory.CreateTraces(ctx, creationSet, tt.cfg, tt.sink)
if tt.wantErr {
assert.Error(t, err)
return
Expand All @@ -151,7 +151,7 @@ func TestCreateTracesReceiver(t *testing.T) {
}
}

func TestCreateMetricReceiver(t *testing.T) {
func TestCreateMetric(t *testing.T) {
factory := NewFactory()
defaultGRPCSettings := &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestCreateMetricReceiver(t *testing.T) {
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)
mr, err := factory.CreateMetrics(ctx, creationSet, tt.cfg, tt.sink)
if tt.wantErr {
assert.Error(t, err)
return
Expand All @@ -245,7 +245,7 @@ func TestCreateMetricReceiver(t *testing.T) {
}
}

func TestCreateLogReceiver(t *testing.T) {
func TestCreateLogs(t *testing.T) {
factory := NewFactory()
defaultGRPCSettings := &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestCreateLogReceiver(t *testing.T) {
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)
mr, err := factory.CreateLogs(ctx, creationSet, tt.cfg, tt.sink)
if tt.wantErr {
assert.Error(t, err)
return
Expand All @@ -339,7 +339,7 @@ func TestCreateLogReceiver(t *testing.T) {
}
}

func TestCreateProfilesReceiver(t *testing.T) {
func TestCreateProfiles(t *testing.T) {
factory := NewFactory()
defaultGRPCSettings := &configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestCreateProfilesReceiver(t *testing.T) {
creationSet := receivertest.NewNopSettings()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tr, err := factory.(receiverprofiles.Factory).CreateProfilesReceiver(ctx, creationSet, tt.cfg, tt.sink)
tr, err := factory.(receiverprofiles.Factory).CreateProfiles(ctx, creationSet, tt.cfg, tt.sink)
if tt.wantErr {
assert.Error(t, err)
return
Expand Down
6 changes: 3 additions & 3 deletions receiver/otlpreceiver/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/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func TestGRPCInvalidTLSCredentials(t *testing.T) {
},
}

r, err := NewFactory().CreateTracesReceiver(
r, err := NewFactory().CreateTraces(
context.Background(),
receivertest.NewNopSettings(),
cfg,
Expand Down Expand Up @@ -769,7 +769,7 @@ func TestHTTPInvalidTLSCredentials(t *testing.T) {
}

// TLS is resolved during Start for HTTP.
r, err := NewFactory().CreateTracesReceiver(
r, err := NewFactory().CreateTraces(
context.Background(),
receivertest.NewNopSettings(),
cfg,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ func TestShutdown(t *testing.T) {
cfg.HTTP.Endpoint = endpointHTTP
set := receivertest.NewNopSettings()
set.ID = otlpReceiverID
r, err := NewFactory().CreateTracesReceiver(
r, err := NewFactory().CreateTraces(
context.Background(),
set,
cfg,
Expand Down
Loading

0 comments on commit bce1040

Please sign in to comment.