Skip to content

Commit

Permalink
Deprecate component.Receiver* in favor of new receiver.* (#6687)
Browse files Browse the repository at this point in the history
* Deprecate component.Receiver* in favor of new receiver.*

* Update component/receiver.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

* Update component/receiver.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

* Update component/receiver.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

Co-authored-by: Bogdan Drutu <lazy@splunk.com>
  • Loading branch information
djaglowski and Bogdan Drutu authored Dec 8, 2022
1 parent 2b3ac4c commit a470d8a
Show file tree
Hide file tree
Showing 35 changed files with 301 additions and 180 deletions.
16 changes: 16 additions & 0 deletions .chloggen/mv-receiver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `Receiver` related structs and functions in favor of `receiver` package

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

# (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:
3 changes: 2 additions & 1 deletion cmd/builder/internal/builder/templates/components.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/receiver"
{{- range .Exporters}}
{{.Name}} "{{.Import}}"
{{- end}}
Expand Down Expand Up @@ -33,7 +34,7 @@ func components() (component.Factories, error) {
return component.Factories{}, err
}

factories.Receivers, err = component.MakeReceiverFactoryMap(
factories.Receivers, err = receiver.MakeFactoryMap(
{{- range .Receivers}}
{{.Name}}.NewFactory(),
{{- end}}
Expand Down
3 changes: 2 additions & 1 deletion cmd/otelcorecol/components.go

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

3 changes: 2 additions & 1 deletion component/componenttest/nop_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/receiver"
)

// NopFactories returns a component.Factories with all nop factories.
Expand All @@ -30,7 +31,7 @@ func NopFactories() (component.Factories, error) {
return component.Factories{}, err
}

if factories.Receivers, err = component.MakeReceiverFactoryMap(NewNopReceiverFactory()); err != nil {
if factories.Receivers, err = receiver.MakeFactoryMap(NewNopReceiverFactory()); err != nil {
return component.Factories{}, err
}

Expand Down
25 changes: 13 additions & 12 deletions component/componenttest/nop_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
)

// NewNopReceiverCreateSettings returns a new nop settings for Create*Receiver functions.
func NewNopReceiverCreateSettings() component.ReceiverCreateSettings {
return component.ReceiverCreateSettings{
// Deprecated: [v0.67.0] use receivertest.NewNopCreateSettings.
func NewNopReceiverCreateSettings() receiver.CreateSettings {
return receiver.CreateSettings{
TelemetrySettings: NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
Expand All @@ -34,29 +35,29 @@ type nopReceiverConfig struct {
config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
}

// NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers.
func NewNopReceiverFactory() component.ReceiverFactory {
return component.NewReceiverFactory(
// Deprecated: [v0.67.0] use receivertest.NewNopFactory
func NewNopReceiverFactory() receiver.Factory {
return receiver.NewFactory(
"nop",
func() component.Config {
return &nopReceiverConfig{
ReceiverSettings: config.NewReceiverSettings(component.NewID("nop")),
}
},
component.WithTracesReceiver(createTracesReceiver, component.StabilityLevelStable),
component.WithMetricsReceiver(createMetricsReceiver, component.StabilityLevelStable),
component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelStable))
receiver.WithTraces(createTraces, component.StabilityLevelStable),
receiver.WithMetrics(createMetrics, component.StabilityLevelStable),
receiver.WithLogs(createLogs, component.StabilityLevelStable))
}

func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Traces) (component.TracesReceiver, error) {
func createTraces(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) {
return nopReceiverInstance, nil
}

func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Metrics) (component.MetricsReceiver, error) {
func createMetrics(context.Context, receiver.CreateSettings, component.Config, consumer.Metrics) (receiver.Metrics, error) {
return nopReceiverInstance, nil
}

func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.Config, consumer.Logs) (component.LogsReceiver, error) {
func createLogs(context.Context, receiver.CreateSettings, component.Config, consumer.Logs) (receiver.Logs, error) {
return nopReceiverInstance, nil
}

Expand Down
4 changes: 1 addition & 3 deletions component/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ type Factories struct {
Extensions map[Type]ExtensionFactory
}

// MakeReceiverFactoryMap takes a list of receiver factories and returns a map
// with factory type as keys. It returns a non-nil error when more than one factories
// have the same type.
// Deprecated: [v0.67.0] use receiver.MakeFactoryMap
func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[Type]ReceiverFactory, error) {
fMap := map[Type]ReceiverFactory{}
for _, f := range factories {
Expand Down
4 changes: 2 additions & 2 deletions component/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Host interface {
// GetFactory of the specified kind. Returns the factory for a component type.
// This allows components to create other components. For example:
// func (r MyReceiver) Start(host component.Host) error {
// apacheFactory := host.GetFactory(KindReceiver,"apache").(component.ReceiverFactory)
// receiver, err := apacheFactory.CreateMetricsReceiver(...)
// apacheFactory := host.GetFactory(KindReceiver,"apache").(receiver.Factory)
// receiver, err := apacheFactory.CreateMetrics(...)
// ...
// }
//
Expand Down
41 changes: 13 additions & 28 deletions component/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,22 @@ type ReceiverConfig = Config
// Deprecated: [v0.67.0] use UnmarshalConfig.
var UnmarshalReceiverConfig = UnmarshalConfig

// A TracesReceiver receives traces.
// Its purpose is to translate data from any format to the collector's internal trace format.
// TracesReceiver feeds a consumer.Traces with data.
//
// For example it could be Zipkin data source which translates Zipkin spans into ptrace.Traces.
// Deprecated: [v0.67.0] use receiver.Traces.
type TracesReceiver interface {
Component
}

// A MetricsReceiver receives metrics.
// Its purpose is to translate data from any format to the collector's internal metrics format.
// MetricsReceiver feeds a consumer.Metrics with data.
//
// For example it could be Prometheus data source which translates Prometheus metrics into pmetric.Metrics.
// Deprecated: [v0.67.0] use receiver.Metrics.
type MetricsReceiver interface {
Component
}

// A LogsReceiver receives logs.
// Its purpose is to translate data from any format to the collector's internal logs data format.
// LogsReceiver feeds a consumer.Logs with data.
//
// For example a LogsReceiver can read syslogs and convert them into plog.Logs.
// Deprecated: [v0.67.0] use receiver.Logs.
type LogsReceiver interface {
Component
}

// ReceiverCreateSettings configures Receiver creators.
// Deprecated: [v0.67.0] use receiver.CreateSettings.
type ReceiverCreateSettings struct {
// ID returns the ID of the component that will be created.
ID ID
Expand All @@ -64,10 +52,7 @@ type ReceiverCreateSettings struct {
BuildInfo BuildInfo
}

// ReceiverFactory is factory interface for receivers.
//
// This interface cannot be directly implemented. Implementations must
// use the NewReceiverFactory to implement it.
// Deprecated: [v0.67.0] use receivrer.Factory.
type ReceiverFactory interface {
Factory

Expand Down Expand Up @@ -96,7 +81,7 @@ type ReceiverFactory interface {
LogsReceiverStability() StabilityLevel
}

// ReceiverFactoryOption apply changes to ReceiverOptions.
// Deprecated: [v0.67.0] use receiver.FactoryOption.
type ReceiverFactoryOption interface {
// applyReceiverFactoryOption applies the option.
applyReceiverFactoryOption(o *receiverFactory)
Expand All @@ -114,7 +99,7 @@ func (f receiverFactoryOptionFunc) applyReceiverFactoryOption(o *receiverFactory
// Deprecated: [v0.67.0] use CreateDefaultConfigFunc.
type ReceiverCreateDefaultConfigFunc = CreateDefaultConfigFunc

// CreateTracesReceiverFunc is the equivalent of ReceiverFactory.CreateTracesReceiver().
// Deprecated: [v0.67.0] use receiver.CreateTracesFunc.
type CreateTracesReceiverFunc func(context.Context, ReceiverCreateSettings, Config, consumer.Traces) (TracesReceiver, error)

// CreateTracesReceiver implements ReceiverFactory.CreateTracesReceiver().
Expand All @@ -129,7 +114,7 @@ func (f CreateTracesReceiverFunc) CreateTracesReceiver(
return f(ctx, set, cfg, nextConsumer)
}

// CreateMetricsReceiverFunc is the equivalent of ReceiverFactory.CreateMetricsReceiver().
// Deprecated: [v0.67.0] use receiver.CreateMetricsFunc.
type CreateMetricsReceiverFunc func(context.Context, ReceiverCreateSettings, Config, consumer.Metrics) (MetricsReceiver, error)

// CreateMetricsReceiver implements ReceiverFactory.CreateMetricsReceiver().
Expand All @@ -145,7 +130,7 @@ func (f CreateMetricsReceiverFunc) CreateMetricsReceiver(
return f(ctx, set, cfg, nextConsumer)
}

// CreateLogsReceiverFunc is the equivalent of ReceiverFactory.CreateLogsReceiver().
// Deprecated: [v0.67.0] use receiver.CreateLogsFunc.
type CreateLogsReceiverFunc func(context.Context, ReceiverCreateSettings, Config, consumer.Logs) (LogsReceiver, error)

// CreateLogsReceiver implements ReceiverFactory.CreateLogsReceiver().
Expand Down Expand Up @@ -183,31 +168,31 @@ func (r receiverFactory) LogsReceiverStability() StabilityLevel {
return r.logsStabilityLevel
}

// WithTracesReceiver overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level.
// Deprecated: [v0.67.0] use receiver.WithTraces.
func WithTracesReceiver(createTracesReceiver CreateTracesReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.tracesStabilityLevel = sl
o.CreateTracesReceiverFunc = createTracesReceiver
})
}

// WithMetricsReceiver overrides the default "error not supported" implementation for CreateMetricsReceiver and the default "undefined" stability level.
// Deprecated: [v0.67.0] use receiver.WithMetrics.
func WithMetricsReceiver(createMetricsReceiver CreateMetricsReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.metricsStabilityLevel = sl
o.CreateMetricsReceiverFunc = createMetricsReceiver
})
}

// WithLogsReceiver overrides the default "error not supported" implementation for CreateLogsReceiver and the default "undefined" stability level.
// Deprecated: [v0.67.0] use receiver.WithLogs.
func WithLogsReceiver(createLogsReceiver CreateLogsReceiverFunc, sl StabilityLevel) ReceiverFactoryOption {
return receiverFactoryOptionFunc(func(o *receiverFactory) {
o.logsStabilityLevel = sl
o.CreateLogsReceiverFunc = createLogsReceiver
})
}

// NewReceiverFactory returns a ReceiverFactory.
// Deprecated: [v0.67.0] use receiver.NewFactory.
func NewReceiverFactory(cfgType Type, createDefaultConfig CreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory {
f := &receiverFactory{
baseFactory: baseFactory{
Expand Down
2 changes: 1 addition & 1 deletion config/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.opentelemetry.io/collector/component"
)

// ReceiverSettings defines common settings for a component.Receiver configuration.
// ReceiverSettings defines common settings for a receiver.Receiver configuration.
// Specific receivers can embed this struct and extend it with more fields if needed.
//
// When embedded in the receiver config it must be with `mapstructure:",squash"` tag.
Expand Down
7 changes: 4 additions & 3 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
"go.opentelemetry.io/collector/receiver/otlpreceiver"
"go.opentelemetry.io/collector/receiver/receivertest"
)

func TestInvalidConfig(t *testing.T) {
Expand Down Expand Up @@ -345,23 +346,23 @@ func createExporterConfig(baseURL string, defaultCfg component.Config) *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(), componenttest.NewNopReceiverCreateSettings(), cfg, next)
recv, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), 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(), componenttest.NewNopReceiverCreateSettings(), cfg, next)
recv, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), 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(), componenttest.NewNopReceiverCreateSettings(), cfg, next)
recv, err := factory.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, next)
require.NoError(t, err)
startAndCleanup(t, recv)
}
Expand Down
5 changes: 3 additions & 2 deletions obsreport/obsreport_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/receiver"
)

const (
Expand All @@ -41,7 +42,7 @@ const (
receiverScope = scopeName + nameSep + receiverName
)

// Receiver is a helper to add observability to a component.Receiver.
// Receiver is a helper to add observability to a receiver.Receiver.
type Receiver struct {
level configtelemetry.Level
spanNamePrefix string
Expand Down Expand Up @@ -73,7 +74,7 @@ type ReceiverSettings 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 component.ReceiverCreateSettings
ReceiverCreateSettings receiver.CreateSettings
}

// NewReceiver creates a new Receiver.
Expand Down
3 changes: 2 additions & 1 deletion obsreport/obsreport_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scrapererror"
)

Expand Down Expand Up @@ -61,7 +62,7 @@ type Scraper struct {
type ScraperSettings struct {
ReceiverID component.ID
Scraper component.ID
ReceiverCreateSettings component.ReceiverCreateSettings
ReceiverCreateSettings receiver.CreateSettings
}

// NewScraper creates a new Scraper.
Expand Down
6 changes: 4 additions & 2 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"
)

const (
Expand Down Expand Up @@ -77,8 +79,8 @@ func (tts *TestTelemetry) ToProcessorCreateSettings() component.ProcessorCreateS
}

// ToReceiverCreateSettings returns ReceiverCreateSettings with configured TelemetrySettings
func (tts *TestTelemetry) ToReceiverCreateSettings() component.ReceiverCreateSettings {
set := componenttest.NewNopReceiverCreateSettings()
func (tts *TestTelemetry) ToReceiverCreateSettings() receiver.CreateSettings {
set := receivertest.NewNopCreateSettings()
set.TelemetrySettings = tts.TelemetrySettings
set.ID = tts.id
return set
Expand Down
3 changes: 2 additions & 1 deletion otelcol/config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import (
"go.opentelemetry.io/collector/confmap/provider/yamlprovider"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/extension/extensiontest"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/telemetry"
)

var configNop = &Config{
Receivers: map[component.ID]component.Config{component.NewID("nop"): componenttest.NewNopReceiverFactory().CreateDefaultConfig()},
Receivers: map[component.ID]component.Config{component.NewID("nop"): receivertest.NewNopFactory().CreateDefaultConfig()},
Processors: map[component.ID]component.Config{component.NewID("nop"): componenttest.NewNopProcessorFactory().CreateDefaultConfig()},
Exporters: map[component.ID]component.Config{component.NewID("nop"): exportertest.NewNopFactory().CreateDefaultConfig()},
Extensions: map[component.ID]component.Config{component.NewID("nop"): extensiontest.NewNopFactory().CreateDefaultConfig()},
Expand Down
Loading

0 comments on commit a470d8a

Please sign in to comment.