Skip to content

Commit

Permalink
Standarize Settings instead of Params and Parameters
Browse files Browse the repository at this point in the history
Fixes open-telemetry#2650
Changes:
 Replace: ReceiverCreateParams, ProcessorCreateParams, ExtensionCreateParams and ExporterCreateParams with ComponentSettings struct
 Replace all dependencies in Extensions, Exporters, Processors and Receivers
 Replace Parameters and settings structs with new struct Settings
 Replace dependencies in service and main
 Update tests

Signed-off-by: Patryk Matyjasek <[email protected]>

# Conflicts:
#	exporter/kafkaexporter/factory.go
#	exporter/kafkaexporter/factory_test.go
#	exporter/kafkaexporter/kafka_exporter.go
#	exporter/kafkaexporter/kafka_exporter_test.go
#	exporter/prometheusexporter/factory.go
#	receiver/jaegerreceiver/jaeger_agent_test.go
#	receiver/jaegerreceiver/trace_receiver_test.go
#	receiver/kafkareceiver/factory.go
#	receiver/kafkareceiver/factory_test.go
#	receiver/kafkareceiver/kafka_receiver.go
#	receiver/kafkareceiver/kafka_receiver_test.go
  • Loading branch information
pmatyjasek-sumo committed Apr 23, 2021
1 parent d10b842 commit ee1079e
Show file tree
Hide file tree
Showing 131 changed files with 698 additions and 703 deletions.
8 changes: 6 additions & 2 deletions cmd/otelcol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ func main() {
GitHash: version.GitHash,
}

if err := run(service.Parameters{ApplicationStartInfo: info, Factories: factories}); err != nil {
componentSettings := component.ComponentSettings{
ApplicationStartInfo: info,
}

if err := run(service.Settings{ComponentSettings: componentSettings, Factories: factories}); err != nil {
log.Fatal(err)
}
}

func runInteractive(params service.Parameters) error {
func runInteractive(params service.Settings) error {
app, err := service.New(params)
if err != nil {
return fmt.Errorf("failed to construct the application: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcol/main_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package main

import "go.opentelemetry.io/collector/service"

func run(params service.Parameters) error {
func run(params service.Settings) error {
return runInteractive(params)
}
11 changes: 11 additions & 0 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"

"go.opentelemetry.io/collector/config"
"go.uber.org/zap"
)

// Component is either a receiver, exporter, processor or extension.
Expand Down Expand Up @@ -60,6 +61,16 @@ type Component interface {
Shutdown(ctx context.Context) error
}

// ComponentSettings is passed to ReceiverFactory.Create* functions.
type ComponentSettings 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

// ApplicationStartInfo can be used by components for informational purposes
ApplicationStartInfo ApplicationStartInfo
}

// Kind specified one of the 4 components kinds, see consts below.
type Kind int

Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *nopExporterFactory) CreateDefaultConfig() config.Exporter {
// CreateTracesExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateTracesExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ComponentSettings,
_ config.Exporter,
) (component.TracesExporter, error) {
return nopExporterInstance, nil
Expand All @@ -57,7 +57,7 @@ func (f *nopExporterFactory) CreateTracesExporter(
// CreateMetricsExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateMetricsExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ComponentSettings,
_ config.Exporter,
) (component.MetricsExporter, error) {
return nopExporterInstance, nil
Expand All @@ -66,7 +66,7 @@ func (f *nopExporterFactory) CreateMetricsExporter(
// CreateLogsExporter implements component.ExporterFactory interface.
func (f *nopExporterFactory) CreateLogsExporter(
_ context.Context,
_ component.ExporterCreateParams,
_ component.ComponentSettings,
_ config.Exporter,
) (component.LogsExporter, error) {
return nopExporterInstance, nil
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ func TestNewNopExporterFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &config.ExporterSettings{TypeVal: factory.Type()}, cfg)

traces, err := factory.CreateTracesExporter(context.Background(), component.ExporterCreateParams{}, cfg)
traces, err := factory.CreateTracesExporter(context.Background(), component.ComponentSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.ConsumeTraces(context.Background(), pdata.NewTraces()))
assert.NoError(t, traces.Shutdown(context.Background()))

metrics, err := factory.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, cfg)
metrics, err := factory.CreateMetricsExporter(context.Background(), component.ComponentSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, metrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pdata.NewMetrics()))
assert.NoError(t, metrics.Shutdown(context.Background()))

logs, err := factory.CreateLogsExporter(context.Background(), component.ExporterCreateParams{}, cfg)
logs, err := factory.CreateLogsExporter(context.Background(), component.ComponentSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
assert.NoError(t, logs.ConsumeLogs(context.Background(), pdata.NewLogs()))
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (f *nopExtensionFactory) CreateDefaultConfig() config.Extension {
// CreateExtension implements component.ExtensionFactory interface.
func (f *nopExtensionFactory) CreateExtension(
_ context.Context,
_ component.ExtensionCreateParams,
_ component.ComponentSettings,
_ config.Extension,
) (component.Extension, error) {
return nopExtensionInstance, nil
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/nop_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewNopExtensionFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &config.ExtensionSettings{TypeVal: factory.Type()}, cfg)

traces, err := factory.CreateExtension(context.Background(), component.ExtensionCreateParams{}, cfg)
traces, err := factory.CreateExtension(context.Background(), component.ComponentSettings{}, cfg)
require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.Shutdown(context.Background()))
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (f *nopProcessorFactory) CreateDefaultConfig() config.Processor {
// CreateTracesProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateTracesProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Traces,
) (component.TracesProcessor, error) {
Expand All @@ -61,7 +61,7 @@ func (f *nopProcessorFactory) CreateTracesProcessor(
// CreateMetricsProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateMetricsProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Metrics,
) (component.MetricsProcessor, error) {
Expand All @@ -71,7 +71,7 @@ func (f *nopProcessorFactory) CreateMetricsProcessor(
// CreateLogsProcessor implements component.ProcessorFactory interface.
func (f *nopProcessorFactory) CreateLogsProcessor(
_ context.Context,
_ component.ProcessorCreateParams,
_ component.ComponentSettings,
_ config.Processor,
_ consumer.Logs,
) (component.LogsProcessor, error) {
Expand Down
6 changes: 3 additions & 3 deletions component/componenttest/nop_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ func TestNewNopProcessorFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &config.ProcessorSettings{TypeVal: factory.Type()}, cfg)

traces, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
traces, err := factory.CreateTracesProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, component.ProcessorCapabilities{MutatesConsumedData: false}, traces.GetCapabilities())
assert.NoError(t, traces.Start(context.Background(), NewNopHost()))
assert.NoError(t, traces.ConsumeTraces(context.Background(), pdata.NewTraces()))
assert.NoError(t, traces.Shutdown(context.Background()))

metrics, err := factory.CreateMetricsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
metrics, err := factory.CreateMetricsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, component.ProcessorCapabilities{MutatesConsumedData: false}, metrics.GetCapabilities())
assert.NoError(t, metrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pdata.NewMetrics()))
assert.NoError(t, metrics.Shutdown(context.Background()))

logs, err := factory.CreateLogsProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewNop())
logs, err := factory.CreateLogsProcessor(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.Equal(t, component.ProcessorCapabilities{MutatesConsumedData: false}, logs.GetCapabilities())
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
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 @@ -48,7 +48,7 @@ func (f *nopReceiverFactory) CreateDefaultConfig() config.Receiver {
// CreateTracesReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateTracesReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ComponentSettings,
_ config.Receiver,
_ consumer.Traces,
) (component.TracesReceiver, error) {
Expand All @@ -58,7 +58,7 @@ func (f *nopReceiverFactory) CreateTracesReceiver(
// CreateMetricsReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateMetricsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ComponentSettings,
_ config.Receiver,
_ consumer.Metrics,
) (component.MetricsReceiver, error) {
Expand All @@ -68,7 +68,7 @@ func (f *nopReceiverFactory) CreateMetricsReceiver(
// CreateLogsReceiver implements component.ReceiverFactory interface.
func (f *nopReceiverFactory) CreateLogsReceiver(
_ context.Context,
_ component.ReceiverCreateParams,
_ component.ComponentSettings,
_ 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, &config.ReceiverSettings{TypeVal: factory.Type()}, cfg)

traces, err := factory.CreateTracesReceiver(context.Background(), component.ReceiverCreateParams{}, cfg, consumertest.NewNop())
traces, err := factory.CreateTracesReceiver(context.Background(), component.ComponentSettings{}, cfg, consumertest.NewNop())
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.ComponentSettings{}, 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.ComponentSettings{}, cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, logs.Start(context.Background(), NewNopHost()))
assert.NoError(t, logs.Shutdown(context.Background()))
Expand Down
2 changes: 1 addition & 1 deletion component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
nextSink := new(consumertest.TracesSink)
processor, err := factory.CreateTracesProcessor(
context.Background(),
component.ProcessorCreateParams{Logger: zap.NewNop()},
component.ComponentSettings{Logger: zap.NewNop()},
cfg,
nextSink,
)
Expand Down
18 changes: 3 additions & 15 deletions component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package component
import (
"context"

"go.uber.org/zap"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
)
Expand Down Expand Up @@ -46,16 +44,6 @@ type LogsExporter interface {
consumer.Logs
}

// ExporterCreateParams is passed to Create*Exporter functions.
type ExporterCreateParams 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

// ApplicationStartInfo can be used by components for informational purposes
ApplicationStartInfo ApplicationStartInfo
}

// ExporterFactory can create TracesExporter and MetricsExporter. This is the
// new factory type that can create new style exporters.
type ExporterFactory interface {
Expand All @@ -75,7 +63,7 @@ type ExporterFactory interface {
// error will be returned instead.
CreateTracesExporter(
ctx context.Context,
params ExporterCreateParams,
settings ComponentSettings,
cfg config.Exporter,
) (TracesExporter, error)

Expand All @@ -84,7 +72,7 @@ type ExporterFactory interface {
// error will be returned instead.
CreateMetricsExporter(
ctx context.Context,
params ExporterCreateParams,
settings ComponentSettings,
cfg config.Exporter,
) (MetricsExporter, error)

Expand All @@ -93,7 +81,7 @@ type ExporterFactory interface {
// error will be returned instead.
CreateLogsExporter(
ctx context.Context,
params ExporterCreateParams,
settings ComponentSettings,
cfg config.Exporter,
) (LogsExporter, error)
}
6 changes: 3 additions & 3 deletions component/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ func (f *TestExporterFactory) CreateDefaultConfig() config.Exporter {
}

// CreateTracesExporter creates a trace exporter based on this config.
func (f *TestExporterFactory) CreateTracesExporter(context.Context, ExporterCreateParams, config.Exporter) (TracesExporter, error) {
func (f *TestExporterFactory) CreateTracesExporter(context.Context, ComponentSettings, config.Exporter) (TracesExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a metrics exporter based on this config.
func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ExporterCreateParams, config.Exporter) (MetricsExporter, error) {
func (f *TestExporterFactory) CreateMetricsExporter(context.Context, ComponentSettings, config.Exporter) (MetricsExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

// CreateMetricsExporter creates a logs exporter based on this config.
func (f *TestExporterFactory) CreateLogsExporter(context.Context, ExporterCreateParams, config.Exporter) (LogsExporter, error) {
func (f *TestExporterFactory) CreateLogsExporter(context.Context, ComponentSettings, config.Exporter) (LogsExporter, error) {
return nil, componenterror.ErrDataTypeIsNotSupported
}

Expand Down
18 changes: 5 additions & 13 deletions component/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package component
import (
"context"

"go.uber.org/zap"

"go.opentelemetry.io/collector/config"
)

Expand Down Expand Up @@ -46,16 +44,6 @@ type PipelineWatcher interface {
NotReady() error
}

// ExtensionCreateParams is passed to ExtensionFactory.Create* functions.
type ExtensionCreateParams 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

// ApplicationStartInfo can be used by components for informational purposes
ApplicationStartInfo ApplicationStartInfo
}

// ExtensionFactory is a factory interface for extensions to the service.
type ExtensionFactory interface {
Factory
Expand All @@ -70,5 +58,9 @@ type ExtensionFactory interface {
CreateDefaultConfig() config.Extension

// CreateExtension creates a service extension based on the given config.
CreateExtension(ctx context.Context, params ExtensionCreateParams, cfg config.Extension) (Extension, error)
CreateExtension(
ctx context.Context,
settings ComponentSettings,
cfg config.Extension,
) (Extension, error)
}
Loading

0 comments on commit ee1079e

Please sign in to comment.