Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standarize Settings, Params and Parameters in Receiver #3167

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Rename `configtest.LoadConfigFile` to `configtest.LoadConfigAndValidate` (#3306)
- Replace `ExtensionCreateParams` with `ExtensionCreateSettings` (#3294)
- Replace `ExporterCreateParams` with `ExporterCreateSettings` (#3164)
- Replace `ReceiverCreateParams` with `ReceiverCreateSettings`. (#3167)

## 💡 Enhancements 💡

Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (f *nopReceiverFactory) CreateDefaultConfig() config.Receiver {
// CreateTracesReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateTracesReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
_ config.Receiver,
_ consumer.Traces,
) (component.TracesReceiver, error) {
Expand All @@ -62,7 +62,7 @@ func (f *nopReceiverFactory) CreateTracesReceiver(
// CreateMetricsReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateMetricsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
_ config.Receiver,
_ consumer.Metrics,
) (component.MetricsReceiver, error) {
Expand All @@ -72,7 +72,7 @@ func (f *nopReceiverFactory) CreateMetricsReceiver(
// CreateLogsReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateLogsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
_ config.Receiver,
_ consumer.Logs,
) (component.LogsReceiver, error) {
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func TestNewNopReceiverFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(config.NewID("nop"))}, cfg)

traces, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateParams{}, cfg, consumertest.NewNop())
traces, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateSettings{}, cfg, consumertest.NewNop())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as the other test, it may be useful to have a nop instance. Not a biggie though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I didn't want to change any logic there. Only refactor the code

require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.Shutdown(context.Background()))

metrics, err := factory.CreateMetricsReceiver(context.Background(), component.ReceiverCreateParams{}, cfg, consumertest.NewNop())
metrics, err := factory.CreateMetricsReceiver(context.Background(), component.ReceiverCreateSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, metrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metrics.Shutdown(context.Background()))

logs, err := factory.CreateLogsReceiver(context.Background(), component.ReceiverCreateParams{}, cfg, consumertest.NewNop())
logs, err := factory.CreateLogsReceiver(context.Background(), component.ReceiverCreateSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
assert.NoError(t, logs.Shutdown(context.Background()))
Expand Down
10 changes: 5 additions & 5 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type LogsReceiver interface {
Receiver
}

// ReceiverCreateParams configures Receiver creators.
type ReceiverCreateParams struct {
// ReceiverCreateSettings configures Receiver creators.
type ReceiverCreateSettings struct {
// Logger that the factory can use during creation and can pass to the created
// component to be used later as well.
Logger *zap.Logger
Expand All @@ -82,18 +82,18 @@ type ReceiverFactory interface {
// CreateTracesReceiver creates a trace receiver 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.
CreateTracesReceiver(ctx context.Context, params ReceiverCreateParams,
CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error)

// CreateMetricsReceiver creates a metrics receiver 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.
CreateMetricsReceiver(ctx context.Context, params ReceiverCreateParams,
CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Metrics) (MetricsReceiver, error)

// CreateLogsReceiver creates a log receiver 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.
CreateLogsReceiver(ctx context.Context, params ReceiverCreateParams,
CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings,
cfg config.Receiver, nextConsumer consumer.Logs) (LogsReceiver, error)
}
6 changes: 3 additions & 3 deletions component/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ func (f *TestReceiverFactory) CreateDefaultConfig() config.Receiver {
}

// CreateTracesReceiver creates a trace receiver based on this config.
func (f *TestReceiverFactory) CreateTracesReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Traces) (TracesReceiver, error) {
func (f *TestReceiverFactory) CreateTracesReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a metrics receiver based on this config.
func (f *TestReceiverFactory) CreateMetricsReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Metrics) (MetricsReceiver, error) {
func (f *TestReceiverFactory) CreateMetricsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Metrics) (MetricsReceiver, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a metrics receiver based on this config.
func (f *TestReceiverFactory) CreateLogsReceiver(context.Context, ReceiverCreateParams, config.Receiver, consumer.Logs) (LogsReceiver, error) {
func (f *TestReceiverFactory) CreateLogsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Logs) (LogsReceiver, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

Expand Down
4 changes: 2 additions & 2 deletions exporter/opencensusexporter/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestSendTraces(t *testing.T) {
rCfg := rFactory.CreateDefaultConfig().(*opencensusreceiver.Config)
endpoint := testutil.GetAvailableLocalAddress(t)
rCfg.GRPCServerSettings.NetAddr.Endpoint = endpoint
set := component.ReceiverCreateParams{Logger: zap.NewNop()}
set := component.ReceiverCreateSettings{Logger: zap.NewNop()}
recv, err := rFactory.CreateTracesReceiver(context.Background(), set, rCfg, sink)
assert.NoError(t, err)
assert.NoError(t, recv.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestSendMetrics(t *testing.T) {
rCfg := rFactory.CreateDefaultConfig().(*opencensusreceiver.Config)
endpoint := testutil.GetAvailableLocalAddress(t)
rCfg.GRPCServerSettings.NetAddr.Endpoint = endpoint
set := component.ReceiverCreateParams{Logger: zap.NewNop()}
set := component.ReceiverCreateSettings{Logger: zap.NewNop()}
recv, err := rFactory.CreateMetricsReceiver(context.Background(), set, rCfg, sink)
assert.NoError(t, err)
assert.NoError(t, recv.Start(context.Background(), componenttest.NewNopHost()))
Expand Down
6 changes: 3 additions & 3 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,23 @@ func createExporterConfig(baseURL string, defaultCfg config.Exporter) *Config {
func startTracesReceiver(t *testing.T, addr string, next consumer.Traces) {
factory := otlpreceiver.NewFactory()
cfg := createReceiverConfig(addr, factory.CreateDefaultConfig())
recv, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateParams{Logger: zap.NewNop()}, cfg, next)
recv, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateSettings{Logger: zap.NewNop()}, 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(), component.ReceiverCreateParams{Logger: zap.NewNop()}, cfg, next)
recv, err := factory.CreateMetricsReceiver(context.Background(), component.ReceiverCreateSettings{Logger: zap.NewNop()}, 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(), component.ReceiverCreateParams{Logger: zap.NewNop()}, cfg, next)
recv, err := factory.CreateLogsReceiver(context.Background(), component.ReceiverCreateSettings{Logger: zap.NewNop()}, cfg, next)
require.NoError(t, err)
startAndCleanup(t, recv)
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/prometheusexporter/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ func TestEndToEndSummarySupport(t *testing.T) {
}

receiverFactory := prometheusreceiver.NewFactory()
receiverCreateSettings := component.ReceiverCreateParams{
receiverCreateSet := component.ReceiverCreateSettings{
Logger: zap.NewNop(),
}
rcvCfg := &prometheusreceiver.Config{
PrometheusConfig: receiverConfig,
ReceiverSettings: config.NewReceiverSettings(config.NewID("prometheus")),
}
// 3.5 Create the Prometheus receiver and pass in the preivously created Prometheus exporter.
prometheusReceiver, err := receiverFactory.CreateMetricsReceiver(ctx, receiverCreateSettings, rcvCfg, exporter)
prometheusReceiver, err := receiverFactory.CreateMetricsReceiver(ctx, receiverCreateSet, rcvCfg, exporter)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/testcomponents/example_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func createReceiverDefaultConfig() config.Receiver {
// CreateTracesReceiver creates a trace receiver based on this config.
func createTracesReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Traces,
) (component.TracesReceiver, error) {
Expand All @@ -73,7 +73,7 @@ func createTracesReceiver(
// CreateMetricsReceiver creates a metrics receiver based on this config.
func createMetricsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Metrics,
) (component.MetricsReceiver, error) {
Expand All @@ -84,7 +84,7 @@ func createMetricsReceiver(

func createLogsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Logs,
) (component.LogsReceiver, error) {
Expand Down
6 changes: 3 additions & 3 deletions receiver/hostmetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ func createDefaultConfig() config.Receiver {
// createMetricsReceiver creates a metrics receiver based on provided config.
func createMetricsReceiver(
ctx context.Context,
params component.ReceiverCreateParams,
set component.ReceiverCreateSettings,
cfg config.Receiver,
consumer consumer.Metrics,
) (component.MetricsReceiver, error) {
oCfg := cfg.(*Config)

addScraperOptions, err := createAddScraperOptions(ctx, params.Logger, oCfg, scraperFactories, resourceScraperFactories)
addScraperOptions, err := createAddScraperOptions(ctx, set.Logger, oCfg, scraperFactories, resourceScraperFactories)
if err != nil {
return nil, err
}

return scraperhelper.NewScraperControllerReceiver(
&oCfg.ScraperControllerSettings,
params.Logger,
set.Logger,
consumer,
addScraperOptions...,
)
Expand Down
10 changes: 5 additions & 5 deletions receiver/hostmetricsreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal"
)

var creationParams = component.ReceiverCreateParams{Logger: zap.NewNop()}
var creationSet = component.ReceiverCreateSettings{Logger: zap.NewNop()}

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
Expand All @@ -42,15 +42,15 @@ func TestCreateReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, tReceiver)

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

tLogs, err := factory.CreateLogsReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
tLogs, err := factory.CreateLogsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.Equal(t, err, componenterror.ErrDataTypeIsNotSupported)
assert.Nil(t, tLogs)
}
Expand All @@ -61,6 +61,6 @@ func TestCreateReceiver_ScraperKeyConfigError(t *testing.T) {
factory := NewFactory()
cfg := &Config{Scrapers: map[string]internal.Config{errorKey: &mockConfig{}}}

_, err := factory.CreateMetricsReceiver(context.Background(), creationParams, cfg, consumertest.NewNop())
_, err := factory.CreateMetricsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
assert.EqualError(t, err, fmt.Sprintf("host metrics scraper factory not found for key: %q", errorKey))
}
8 changes: 4 additions & 4 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestGatherMetrics_EndToEnd(t *testing.T) {
cfg.Scrapers[processscraper.TypeStr] = &processscraper.Config{}
}

receiver, err := NewFactory().CreateMetricsReceiver(context.Background(), creationParams, cfg, sink)
receiver, err := NewFactory().CreateMetricsReceiver(context.Background(), creationSet, cfg, sink)

require.NoError(t, err, "Failed to create metrics receiver: %v", err)

Expand Down Expand Up @@ -247,7 +247,7 @@ func TestGatherMetrics_ScraperKeyConfigError(t *testing.T) {

sink := new(consumertest.MetricsSink)
cfg := &Config{Scrapers: map[string]internal.Config{"error": &mockConfig{}}}
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationParams, cfg, sink)
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationSet, cfg, sink)
require.Error(t, err)
}

Expand All @@ -259,7 +259,7 @@ func TestGatherMetrics_CreateMetricsScraperError(t *testing.T) {

sink := new(consumertest.MetricsSink)
cfg := &Config{Scrapers: map[string]internal.Config{mockTypeStr: &mockConfig{}}}
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationParams, cfg, sink)
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationSet, cfg, sink)
require.Error(t, err)
}

Expand All @@ -271,7 +271,7 @@ func TestGatherMetrics_CreateMetricsResourceScraperError(t *testing.T) {

sink := new(consumertest.MetricsSink)
cfg := &Config{Scrapers: map[string]internal.Config{mockResourceTypeStr: &mockConfig{}}}
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationParams, cfg, sink)
_, err := NewFactory().CreateMetricsReceiver(context.Background(), creationSet, cfg, sink)
require.Error(t, err)
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/jaegerreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func createDefaultConfig() config.Receiver {
// createTracesReceiver creates a trace receiver based on provided config.
func createTracesReceiver(
_ context.Context,
params component.ReceiverCreateParams,
set component.ReceiverCreateSettings,
cfg config.Receiver,
nextConsumer consumer.Traces,
) (component.TracesReceiver, error) {
Expand Down Expand Up @@ -174,7 +174,7 @@ func createTracesReceiver(
}

// Create the receiver.
return newJaegerReceiver(rCfg.ID(), &config, nextConsumer, params), nil
return newJaegerReceiver(rCfg.ID(), &config, nextConsumer, set), nil
}

// extract the port number from string in "address:port" format. If the
Expand Down
Loading