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 New funcs for extension, exporter, processor config settings #2872

Merged
merged 1 commit into from
Mar 31, 2021
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
6 changes: 6 additions & 0 deletions config/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ type Exporters map[string]Exporter

// ExporterSettings defines common settings for an exporter configuration.
// Specific exporters can embed this struct and extend it with more fields if needed.
// When embedded in the exporter config it must be with `mapstructure:"-"` tag.
type ExporterSettings struct {
TypeVal Type `mapstructure:"-"`
NameVal string `mapstructure:"-"`
}

// NewExporterSettings return a new ExporterSettings with the given type.
func NewExporterSettings(typeVal Type) *ExporterSettings {
return &ExporterSettings{TypeVal: typeVal, NameVal: string(typeVal)}
}

var _ Exporter = (*ExporterSettings)(nil)

// Name gets the exporter name.
Expand Down
8 changes: 7 additions & 1 deletion config/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ type Extension interface {
// Extensions is a map of names to extensions.
type Extensions map[string]Extension

// ExtensionSettings defines common settings for a service extension configuration.
// ExtensionSettings defines common settings for a extension configuration.
// Specific extensions can embed this struct and extend it with more fields if needed.
// When embedded in the extension config it must be with `mapstructure:"-"` tag.
type ExtensionSettings struct {
TypeVal Type `mapstructure:"-"`
NameVal string `mapstructure:"-"`
}

// NewExtensionSettings return a new ExtensionSettings with the given type.
func NewExtensionSettings(typeVal Type) *ExtensionSettings {
return &ExtensionSettings{TypeVal: typeVal, NameVal: string(typeVal)}
}

var _ Extension = (*ExtensionSettings)(nil)

// Name gets the extension name.
Expand Down
6 changes: 6 additions & 0 deletions config/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ type Processors map[string]Processor

// ProcessorSettings defines common settings for a processor configuration.
// Specific processors can embed this struct and extend it with more fields if needed.
// When embedded in the processor config it must be with `mapstructure:"-"` tag.
type ProcessorSettings struct {
TypeVal Type `mapstructure:"-"`
NameVal string `mapstructure:"-"`
}

// NewProcessorSettings return a new ProcessorSettings with the given type.
func NewProcessorSettings(typeVal Type) *ProcessorSettings {
return &ProcessorSettings{TypeVal: typeVal, NameVal: string(typeVal)}
}

var _ Processor = (*ProcessorSettings)(nil)

// Name gets the processor name.
Expand Down
1 change: 1 addition & 0 deletions config/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Receivers map[string]Receiver
// ReceiverSettings defines common settings for a receiver configuration.
// Specific receivers can embed this struct and extend it with more fields if needed.
// It is highly recommended to "override" the Validate() function.
// When embedded in the processor config it must be with `mapstructure:"-"` tag.
type ReceiverSettings struct {
TypeVal Type `mapstructure:"-"`
NameVal string `mapstructure:"-"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/fileexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

// Config defines configuration for file exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
*config.ExporterSettings `mapstructure:"-"`

// Path of the file to write to. Path is relative to current directory.
Path string `mapstructure:"path"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/fileexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestLoadConfig(t *testing.T) {
e1 := cfg.Exporters["file/2"]
assert.Equal(t, e1,
&Config{
ExporterSettings: config.ExporterSettings{
ExporterSettings: &config.ExporterSettings{
NameVal: "file/2",
TypeVal: "file",
},
Expand Down
5 changes: 1 addition & 4 deletions exporter/fileexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ func NewFactory() component.ExporterFactory {

func createDefaultConfig() config.Exporter {
return &Config{
ExporterSettings: config.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
ExporterSettings: config.NewExporterSettings(typeStr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/jaegerexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Config defines configuration for Jaeger gRPC exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
*config.ExporterSettings `mapstructure:"-"`
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/jaegerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestLoadConfig(t *testing.T) {
e1 := cfg.Exporters["jaeger/2"]
assert.Equal(t, e1,
&Config{
ExporterSettings: config.ExporterSettings{
ExporterSettings: &config.ExporterSettings{
NameVal: "jaeger/2",
TypeVal: "jaeger",
},
Expand Down
7 changes: 7 additions & 0 deletions exporter/jaegerexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/pdata"
Expand All @@ -52,6 +53,7 @@ func TestNew(t *testing.T) {
name: "createExporter",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: nil,
Endpoint: "foo.bar",
Expand All @@ -68,6 +70,7 @@ func TestNew(t *testing.T) {
name: "createExporterWithHeaders",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{"extra-header": "header-value"},
Endpoint: "foo.bar",
Expand All @@ -81,6 +84,7 @@ func TestNew(t *testing.T) {
name: "createBasicSecureExporter",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: nil,
Endpoint: "foo.bar",
Expand All @@ -94,6 +98,7 @@ func TestNew(t *testing.T) {
name: "createSecureExporterWithClientTLS",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: nil,
Endpoint: "foo.bar",
Expand All @@ -113,6 +118,7 @@ func TestNew(t *testing.T) {
name: "createSecureExporterWithKeepAlive",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: nil,
Endpoint: "foo.bar",
Expand All @@ -137,6 +143,7 @@ func TestNew(t *testing.T) {
name: "createSecureExporterWithMissingFile",
args: args{
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: nil,
Endpoint: "foo.bar",
Expand Down
11 changes: 4 additions & 7 deletions exporter/jaegerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ func NewFactory() component.ExporterFactory {

func createDefaultConfig() config.Exporter {
return &Config{
ExporterSettings: config.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
TimeoutSettings: exporterhelper.DefaultTimeoutSettings(),
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
ExporterSettings: config.NewExporterSettings(typeStr),
TimeoutSettings: exporterhelper.DefaultTimeoutSettings(),
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
GRPCClientSettings: configgrpc.GRPCClientSettings{
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
Expand Down
2 changes: 1 addition & 1 deletion exporter/kafkaexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// Config defines configuration for Kafka exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"`
*config.ExporterSettings `mapstructure:"-"`
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
Expand Down
5 changes: 1 addition & 4 deletions exporter/kafkaexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ func TestLoadConfig(t *testing.T) {

c := cfg.Exporters[typeStr].(*Config)
assert.Equal(t, &Config{
ExporterSettings: config.ExporterSettings{
NameVal: typeStr,
TypeVal: typeStr,
},
ExporterSettings: config.NewExporterSettings(typeStr),
TimeoutSettings: exporterhelper.TimeoutSettings{
Timeout: 10 * time.Second,
},
Expand Down
13 changes: 5 additions & 8 deletions exporter/kafkaexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ func NewFactory(options ...FactoryOption) component.ExporterFactory {

func createDefaultConfig() config.Exporter {
return &Config{
ExporterSettings: config.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
TimeoutSettings: exporterhelper.DefaultTimeoutSettings(),
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
Brokers: []string{defaultBroker},
ExporterSettings: config.NewExporterSettings(typeStr),
TimeoutSettings: exporterhelper.DefaultTimeoutSettings(),
RetrySettings: exporterhelper.DefaultRetrySettings(),
QueueSettings: exporterhelper.DefaultQueueSettings(),
Brokers: []string{defaultBroker},
// using an empty topic to track when it has not been set by user, default is based on traces or metrics.
Topic: "",
Encoding: defaultEncoding,
Expand Down
2 changes: 1 addition & 1 deletion exporter/loggingexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

// Config defines configuration for logging exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
*config.ExporterSettings `mapstructure:"-"`

// LogLevel defines log level of the logging exporter; options are debug, info, warn, error.
LogLevel string `mapstructure:"loglevel"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/loggingexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestLoadConfig(t *testing.T) {
e1 := cfg.Exporters["logging/2"]
assert.Equal(t, e1,
&Config{
ExporterSettings: config.ExporterSettings{
ExporterSettings: &config.ExporterSettings{
NameVal: "logging/2",
TypeVal: "logging",
},
Expand Down
5 changes: 1 addition & 4 deletions exporter/loggingexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ func NewFactory() component.ExporterFactory {

func createDefaultConfig() config.Exporter {
return &Config{
ExporterSettings: config.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
ExporterSettings: config.NewExporterSettings(typeStr),
LogLevel: "info",
SamplingInitial: defaultSamplingInitial,
SamplingThereafter: defaultSamplingThereafter,
Expand Down
2 changes: 1 addition & 1 deletion exporter/opencensusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Config defines configuration for OpenCensus exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
*config.ExporterSettings `mapstructure:"-"`
configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/opencensusexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestLoadConfig(t *testing.T) {
e1 := cfg.Exporters["opencensus/2"]
assert.Equal(t, e1,
&Config{
ExporterSettings: config.ExporterSettings{
ExporterSettings: &config.ExporterSettings{
NameVal: "opencensus/2",
TypeVal: "opencensus",
},
Expand Down
5 changes: 1 addition & 4 deletions exporter/opencensusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ func NewFactory() component.ExporterFactory {

func createDefaultConfig() config.Exporter {
return &Config{
ExporterSettings: config.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{},
// We almost read 0 bytes, so no need to tune ReadBufferSize.
Expand Down
10 changes: 10 additions & 0 deletions exporter/opencensusexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/configtls"
Expand All @@ -46,6 +47,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "NoEndpoint",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: "",
},
Expand All @@ -56,6 +58,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "ZeroNumWorkers",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
Expand All @@ -69,6 +72,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "UseSecure",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
Expand All @@ -81,6 +85,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "Keepalive",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Keepalive: &configgrpc.KeepaliveClientConfig{
Expand All @@ -95,6 +100,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "Compression",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configgrpc.CompressionGzip,
Expand All @@ -105,6 +111,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "Headers",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Headers: map[string]string{
Expand All @@ -118,6 +125,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "CompressionError",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: "unknown compression",
Expand All @@ -129,6 +137,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "CaCert",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
Expand All @@ -143,6 +152,7 @@ func TestCreateTraceExporter(t *testing.T) {
{
name: "CertPemFileError",
config: Config{
ExporterSettings: config.NewExporterSettings(typeStr),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
TLSSetting: configtls.TLSClientSetting{
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Config defines configuration for OpenCensus exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
*config.ExporterSettings `mapstructure:"-"`
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestLoadConfig(t *testing.T) {
e1 := cfg.Exporters["otlp/2"]
assert.Equal(t, e1,
&Config{
ExporterSettings: config.ExporterSettings{
ExporterSettings: &config.ExporterSettings{
NameVal: "otlp/2",
TypeVal: "otlp",
},
Expand Down
Loading