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

Draft changes to show how we can split component #6552

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ There isn't a valid core binary for this release. Use v0.57.2 instead.
- Deprecated `exporterhelper.WithTraces` in favour of `component.WithTracesExporter`
- Deprecated `exporterhelper.WithMetrics` in favour of `component.WithMetricsExporter`
- Deprecated `exporterhelper.WithLogs` in favour of `component.WithLogsExporter`
- Deprecated `exporterhelper.NewFactory` in favour of `component.NewExporterFactory`
- Deprecated `exporterhelper.NewFactory` in favour of `component.NewFactory`
- Move helpers from receiverhelper to component (#4891)
- Deprecated `receiverhelper.CreateDefaultConfig` in favour of `component.ReceiverDefaultConfigFunc`
- Deprecated `receiverhelper.WithTraces` in favour of `component.WithTracesReceiver`
Expand Down
38 changes: 19 additions & 19 deletions cmd/otelcorecol/components.go

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

4 changes: 1 addition & 3 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,13 @@ func (sl StabilityLevel) LogMessage() string {
type Factory interface {
// Type gets the type of the component created by this factory.
Type() Type

unexportedFactoryFunc()
}

type baseFactory struct {
cfgType Type
}

func (baseFactory) unexportedFactoryFunc() {}
func (baseFactory) unexportedFunc() {}

func (bf baseFactory) Type() Type {
return bf.cfgType
Expand Down
2 changes: 1 addition & 1 deletion component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import (

func TestBaseInternal(t *testing.T) {
base := baseFactory{}
assert.NotPanics(t, base.unexportedFactoryFunc)
assert.NotPanics(t, base.unexportedFunc)
}
23 changes: 12 additions & 11 deletions component/componenttest/nop_exporter.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/consumertest"
"go.opentelemetry.io/collector/exporter"
)

// NewNopExporterCreateSettings returns a new nop settings for Create*Exporter functions.
func NewNopExporterCreateSettings() component.ExporterCreateSettings {
return component.ExporterCreateSettings{
func NewNopExporterCreateSettings() exporter.CreateSettings {
return exporter.CreateSettings{
TelemetrySettings: NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
Expand All @@ -35,29 +36,29 @@ type nopExporterConfig struct {
}

// NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters.
func NewNopExporterFactory() component.ExporterFactory {
return component.NewExporterFactory(
func NewNopExporterFactory() exporter.Factory {
return exporter.NewFactory(
"nop",
func() component.ExporterConfig {
func() exporter.Config {
return &nopExporterConfig{
ExporterSettings: config.NewExporterSettings(component.NewID("nop")),
}
},
component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
component.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable),
component.WithLogsExporter(createLogsExporter, component.StabilityLevelStable),
exporter.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
exporter.WithMetricsExporter(createMetricsExporter, component.StabilityLevelStable),
exporter.WithLogsExporter(createLogsExporter, component.StabilityLevelStable),
)
}

func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) {
func createTracesExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.TracesExporter, error) {
return nopExporterInstance, nil
}

func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) {
func createMetricsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.MetricsExporter, error) {
return nopExporterInstance, nil
}

func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) {
func createLogsExporter(context.Context, exporter.CreateSettings, exporter.Config) (exporter.LogsExporter, error) {
return nopExporterInstance, nil
}

Expand Down
15 changes: 8 additions & 7 deletions component/componenttest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (

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

// NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions.
func NewNopExtensionCreateSettings() component.ExtensionCreateSettings {
return component.ExtensionCreateSettings{
func NewNopExtensionCreateSettings() extension.CreateSettings {
return extension.CreateSettings{
TelemetrySettings: NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
Expand All @@ -33,16 +34,16 @@ type nopExtensionConfig struct {
config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
}

// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions.
func NewNopExtensionFactory() component.ExtensionFactory {
return component.NewExtensionFactory(
// NewNopExtensionFactory returns a component.Factory that constructs nop extensions.
func NewNopExtensionFactory() extension.Factory {
return extension.NewExtensionFactory(
"nop",
func() component.ExtensionConfig {
func() extension.Config {
return &nopExtensionConfig{
ExtensionSettings: config.NewExtensionSettings(component.NewID("nop")),
}
},
func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) {
func(context.Context, extension.CreateSettings, extension.Config) (extension.Extension, error) {
return nopExtensionInstance, nil
},
component.StabilityLevelStable)
Expand Down
22 changes: 11 additions & 11 deletions component/componenttest/nop_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
package componenttest // import "go.opentelemetry.io/collector/component/componenttest"

import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/service"
)

// NopFactories returns a component.Factories with all nop factories.
func NopFactories() (component.Factories, error) {
var factories component.Factories
func NopFactories() (service.Factories, error) {
var factories service.Factories
var err error

if factories.Extensions, err = component.MakeExtensionFactoryMap(NewNopExtensionFactory()); err != nil {
return component.Factories{}, err
if factories.Extensions, err = service.MakeExtensionFactoryMap(NewNopExtensionFactory()); err != nil {
return service.Factories{}, err
}

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

if factories.Exporters, err = component.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil {
return component.Factories{}, err
if factories.Exporters, err = service.MakeExporterFactoryMap(NewNopExporterFactory()); err != nil {
return service.Factories{}, err
}

if factories.Processors, err = component.MakeProcessorFactoryMap(NewNopProcessorFactory()); err != nil {
return component.Factories{}, err
if factories.Processors, err = service.MakeProcessorFactoryMap(NewNopProcessorFactory()); err != nil {
return service.Factories{}, err
}

return factories, err
Expand Down
8 changes: 5 additions & 3 deletions component/componenttest/nop_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package componenttest // import "go.opentelemetry.io/collector/component/compone

import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
)

// nopHost mocks a receiver.ReceiverHost for test purposes.
Expand All @@ -32,10 +34,10 @@ func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Fact
return nil
}

func (nh *nopHost) GetExtensions() map[component.ID]component.Extension {
func (nh *nopHost) GetExtensions() map[component.ID]extension.Extension {
return nil
}

func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter {
return nil
func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]exporter. {
return nil
}
24 changes: 16 additions & 8 deletions component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ import (
// Type is the component type as it is used in the config.
type Type string

type Config interface {
identifiable
validatable
}

// UnmarshalConfig helper function to unmarshal a Config.
// It checks if the config implements confmap.Unmarshaler and uses that if available,
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
func UnmarshalConfig(conf *confmap.Conf, cfg Config) error {
if cu, ok := cfg.(confmap.Unmarshaler); ok {
return cu.Unmarshal(conf)
}

return conf.Unmarshal(cfg, confmap.WithErrorUnused())
}

// validatable defines the interface for the configuration validation.
type validatable interface {
// Validate validates the configuration and returns an error if invalid.
Expand All @@ -42,11 +58,3 @@ const (
// DataTypeLogs is the data type tag for logs.
DataTypeLogs DataType = "logs"
)

func unmarshal(componentSection *confmap.Conf, intoCfg interface{}) error {
if cu, ok := intoCfg.(confmap.Unmarshaler); ok {
return cu.Unmarshal(componentSection)
}

return componentSection.Unmarshal(intoCfg, confmap.WithErrorUnused())
}
Loading