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

Add mechanism to report go module for each factory #10598

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
4 changes: 4 additions & 0 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ type Factory interface {
// 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the
// tests of any implementation of the Factory interface.
CreateDefaultConfig() Config

// GoModule reports the go module and version of the component.
// Example: "go.opentelemetry.io/collector/exporter/[email protected]"
GoModule() string
}

// CreateDefaultConfigFunc is the equivalent of Factory.CreateDefaultConfig().
Expand Down
14 changes: 14 additions & 0 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"errors"
"fmt"
"path"
"runtime"

"go.uber.org/zap"

Expand Down Expand Up @@ -311,6 +313,8 @@ type factory struct {
logsToTracesStabilityLevel component.StabilityLevel
logsToMetricsStabilityLevel component.StabilityLevel
logsToLogsStabilityLevel component.StabilityLevel

goModule string
}

// Type returns the type of component.
Expand Down Expand Up @@ -428,11 +432,21 @@ func (f factory) LogsToLogsStability() component.StabilityLevel {
return f.logsToLogsStabilityLevel
}

func (f factory) GoModule() string {
return f.goModule
}

// NewFactory returns a Factory.
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
goModule := "[email protected]"
_, caller, _, ok := runtime.Caller(1)
if ok {
goModule = path.Dir(caller)
}
f := &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
goModule: goModule,
}
for _, opt := range options {
opt.apply(f)
Expand Down
13 changes: 13 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package exporter // import "go.opentelemetry.io/collector/exporter"
import (
"context"
"fmt"
"path"
"runtime"

"go.uber.org/zap"

Expand Down Expand Up @@ -138,6 +140,7 @@ type factory struct {
metricsStabilityLevel component.StabilityLevel
CreateLogsFunc
logsStabilityLevel component.StabilityLevel
goModule string
}

func (f *factory) Type() component.Type {
Expand All @@ -158,6 +161,10 @@ func (f *factory) LogsExporterStability() component.StabilityLevel {
return f.logsStabilityLevel
}

func (f *factory) GoModule() string {
return f.goModule
}

// WithTraces overrides the default "error not supported" implementation for CreateTracesExporter and the default "undefined" stability level.
func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
Expand All @@ -184,9 +191,15 @@ func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOpt

// NewFactory returns a Factory.
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
goModule := "[email protected]"
_, caller, _, ok := runtime.Caller(1)
if ok {
goModule = path.Dir(caller)
}
f := &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
goModule: goModule,
}
for _, opt := range options {
opt.applyExporterFactoryOption(f)
Expand Down
13 changes: 13 additions & 0 deletions extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package extension // import "go.opentelemetry.io/collector/extension"
import (
"context"
"fmt"
"path"
"runtime"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
Expand Down Expand Up @@ -103,6 +105,7 @@ type factory struct {
component.CreateDefaultConfigFunc
CreateFunc
extensionStability component.StabilityLevel
goModule string
}

func (f *factory) Type() component.Type {
Expand All @@ -115,17 +118,27 @@ func (f *factory) ExtensionStability() component.StabilityLevel {
return f.extensionStability
}

func (f *factory) GoModule() string {
return f.goModule
}

// NewFactory returns a new Factory based on this configuration.
func NewFactory(
cfgType component.Type,
createDefaultConfig component.CreateDefaultConfigFunc,
createServiceExtension CreateFunc,
sl component.StabilityLevel) Factory {
goModule := "[email protected]"
_, caller, _, ok := runtime.Caller(1)
if ok {
goModule = path.Dir(caller)
}
return &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
CreateFunc: createServiceExtension,
extensionStability: sl,
goModule: goModule,
}
}

Expand Down
16 changes: 11 additions & 5 deletions otelcol/command_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type componentWithStability struct {
Name component.Type
Module string
Stability map[string]string
}

Expand Down Expand Up @@ -49,7 +50,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
components := componentsOutput{}
for _, con := range sortFactoriesByType[connector.Factory](factories.Connectors) {
components.Connectors = append(components.Connectors, componentWithStability{
Name: con.Type(),
Name: con.Type(),
Module: con.GoModule(),
Stability: map[string]string{
"logs-to-logs": con.LogsToLogsStability().String(),
"logs-to-metrics": con.LogsToMetricsStability().String(),
Expand All @@ -67,15 +69,17 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
}
for _, ext := range sortFactoriesByType[extension.Factory](factories.Extensions) {
components.Extensions = append(components.Extensions, componentWithStability{
Name: ext.Type(),
Name: ext.Type(),
Module: ext.GoModule(),
Stability: map[string]string{
"extension": ext.ExtensionStability().String(),
},
})
}
for _, prs := range sortFactoriesByType[processor.Factory](factories.Processors) {
components.Processors = append(components.Processors, componentWithStability{
Name: prs.Type(),
Name: prs.Type(),
Module: prs.GoModule(),
Stability: map[string]string{
"logs": prs.LogsProcessorStability().String(),
"metrics": prs.MetricsProcessorStability().String(),
Expand All @@ -85,7 +89,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
}
for _, rcv := range sortFactoriesByType[receiver.Factory](factories.Receivers) {
components.Receivers = append(components.Receivers, componentWithStability{
Name: rcv.Type(),
Name: rcv.Type(),
Module: rcv.GoModule(),
Stability: map[string]string{
"logs": rcv.LogsReceiverStability().String(),
"metrics": rcv.MetricsReceiverStability().String(),
Expand All @@ -95,7 +100,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
}
for _, exp := range sortFactoriesByType[exporter.Factory](factories.Exporters) {
components.Exporters = append(components.Exporters, componentWithStability{
Name: exp.Type(),
Name: exp.Type(),
Module: exp.GoModule(),
Stability: map[string]string{
"logs": exp.LogsExporterStability().String(),
"metrics": exp.MetricsExporterStability().String(),
Expand Down
13 changes: 13 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"errors"
"fmt"
"path"
"runtime"

"go.uber.org/zap"

Expand Down Expand Up @@ -157,6 +159,7 @@ type factory struct {
metricsStabilityLevel component.StabilityLevel
CreateLogsFunc
logsStabilityLevel component.StabilityLevel
goModule string
}

func (f *factory) Type() component.Type {
Expand All @@ -177,6 +180,10 @@ func (f factory) LogsProcessorStability() component.StabilityLevel {
return f.logsStabilityLevel
}

func (f factory) GoModule() string {
return f.goModule
}

// WithTraces overrides the default "error not supported" implementation for CreateTraces and the default "undefined" stability level.
func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
Expand All @@ -203,9 +210,15 @@ func WithLogs(createLogs CreateLogsFunc, sl component.StabilityLevel) FactoryOpt

// NewFactory returns a Factory.
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
goModule := "[email protected]"
_, caller, _, ok := runtime.Caller(1)
if ok {
goModule = path.Dir(caller)
}
f := &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
goModule: goModule,
}
for _, opt := range options {
opt.applyProcessorFactoryOption(f)
Expand Down
13 changes: 13 additions & 0 deletions receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"errors"
"fmt"
"path"
"runtime"

"go.uber.org/zap"

Expand Down Expand Up @@ -164,6 +166,7 @@ type factory struct {
metricsStabilityLevel component.StabilityLevel
CreateLogsFunc
logsStabilityLevel component.StabilityLevel
goModule string
}

func (f *factory) Type() component.Type {
Expand All @@ -184,6 +187,10 @@ func (f *factory) LogsReceiverStability() component.StabilityLevel {
return f.logsStabilityLevel
}

func (f *factory) GoModule() string {
return f.goModule
}

// WithTraces overrides the default "error not supported" implementation for CreateTracesReceiver and the default "undefined" stability level.
func WithTraces(createTracesReceiver CreateTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
Expand All @@ -210,9 +217,15 @@ func WithLogs(createLogsReceiver CreateLogsFunc, sl component.StabilityLevel) Fa

// NewFactory returns a Factory.
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
goModule := "[email protected]"
_, caller, _, ok := runtime.Caller(1)
if ok {
goModule = path.Dir(caller)
}
f := &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
goModule: goModule,
}
for _, opt := range options {
opt.applyOption(f)
Expand Down
Loading