Documentation ¶
Overview ¶
Package config implements loading of configuration from Viper configuration. The implementation relies on registered factories that allow creating default configuration for each type of receiver/exporter/processor.
Index ¶
- func DecodeTypeAndName(key string) (typeStr configmodels.Type, fullName string, err error)
- func Load(v *viper.Viper, factories Factories) (*configmodels.Config, error)
- func LoadConfigFile(t *testing.T, fileName string, factories Factories) (*configmodels.Config, error)
- func LoadReceiver(componentConfig *viper.Viper, typeStr configmodels.Type, fullName string, ...) (configmodels.Receiver, error)
- func NewViper() *viper.Viper
- func ValidateConfig(cfg *configmodels.Config, logger *zap.Logger) error
- func ViperSub(v *viper.Viper, key string) *viper.Viper
- type ExampleExporter
- type ExampleExporterConsumer
- func (exp *ExampleExporterConsumer) ConsumeLogs(ctx context.Context, ld data.Logs) error
- func (exp *ExampleExporterConsumer) ConsumeMetricsData(ctx context.Context, md consumerdata.MetricsData) error
- func (exp *ExampleExporterConsumer) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error
- func (exp *ExampleExporterConsumer) Name() string
- func (exp *ExampleExporterConsumer) Shutdown(context.Context) error
- func (exp *ExampleExporterConsumer) Start(ctx context.Context, host component.Host) error
- type ExampleExporterFactory
- func (f *ExampleExporterFactory) CreateDefaultConfig() configmodels.Exporter
- func (f *ExampleExporterFactory) CreateLogExporter(ctx context.Context, params component.ExporterCreateParams, ...) (component.LogExporter, error)
- func (f *ExampleExporterFactory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.MetricsExporterOld, error)
- func (f *ExampleExporterFactory) CreateTraceExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.TraceExporterOld, error)
- func (f *ExampleExporterFactory) Type() configmodels.Type
- type ExampleExtension
- type ExampleExtensionCfg
- type ExampleExtensionFactory
- func (f *ExampleExtensionFactory) CreateDefaultConfig() configmodels.Extension
- func (f *ExampleExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.ServiceExtension, error)
- func (f *ExampleExtensionFactory) Type() configmodels.Type
- type ExampleProcessor
- func (ep *ExampleProcessor) ConsumeLogs(ctx context.Context, ld data.Logs) error
- func (ep *ExampleProcessor) GetCapabilities() component.ProcessorCapabilities
- func (ep *ExampleProcessor) Shutdown(ctx context.Context) error
- func (ep *ExampleProcessor) Start(ctx context.Context, host component.Host) error
- type ExampleProcessorCfg
- type ExampleProcessorFactory
- func (f *ExampleProcessorFactory) CreateDefaultConfig() configmodels.Processor
- func (f *ExampleProcessorFactory) CreateLogProcessor(ctx context.Context, params component.ProcessorCreateParams, ...) (component.LogProcessor, error)
- func (f *ExampleProcessorFactory) CreateMetricsProcessor(logger *zap.Logger, nextConsumer consumer.MetricsConsumerOld, ...) (component.MetricsProcessorOld, error)
- func (f *ExampleProcessorFactory) CreateTraceProcessor(logger *zap.Logger, nextConsumer consumer.TraceConsumerOld, ...) (component.TraceProcessorOld, error)
- func (f *ExampleProcessorFactory) Type() configmodels.Type
- type ExampleReceiver
- type ExampleReceiverFactory
- func (f *ExampleReceiverFactory) CreateDefaultConfig() configmodels.Receiver
- func (f *ExampleReceiverFactory) CreateLogReceiver(ctx context.Context, params component.ReceiverCreateParams, ...) (component.LogReceiver, error)
- func (f *ExampleReceiverFactory) CreateMetricsReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *ExampleReceiverFactory) CreateTraceReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, ...) (component.TraceReceiver, error)
- func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
- func (f *ExampleReceiverFactory) Type() configmodels.Type
- type ExampleReceiverProducer
- type Factories
- type MultiProtoReceiver
- type MultiProtoReceiverFactory
- func (f *MultiProtoReceiverFactory) CreateDefaultConfig() configmodels.Receiver
- func (f *MultiProtoReceiverFactory) CreateMetricsReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *MultiProtoReceiverFactory) CreateTraceReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, ...) (component.TraceReceiver, error)
- func (f *MultiProtoReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
- func (f *MultiProtoReceiverFactory) Type() configmodels.Type
- type MultiProtoReceiverOneCfg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeTypeAndName ¶
func DecodeTypeAndName(key string) (typeStr configmodels.Type, fullName string, err error)
DecodeTypeAndName decodes a key in type[/name] format into type and fullName. fullName is the key normalized such that type and name components have spaces trimmed. The "type" part must be present, the forward slash and "name" are optional. typeStr will be non-empty if err is nil.
func Load ¶
Load loads a Config from Viper. After loading the config, need to check if it is valid by calling `ValidateConfig`.
func LoadConfigFile ¶
func LoadConfigFile(t *testing.T, fileName string, factories Factories) (*configmodels.Config, error)
LoadConfigFile loads a config from file.
func LoadReceiver ¶
func LoadReceiver(componentConfig *viper.Viper, typeStr configmodels.Type, fullName string, factory component.ReceiverFactoryBase) (configmodels.Receiver, error)
LoadReceiver loads a receiver config from componentConfig using the provided factories.
func NewViper ¶
Creates a new Viper instance with a different key-delimitor "::" instead of the default ".". This way configs can have keys that contain ".".
func ValidateConfig ¶
func ValidateConfig(cfg *configmodels.Config, logger *zap.Logger) error
ValidateConfig validates config.
Types ¶
type ExampleExporter ¶
type ExampleExporter struct { configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct ExtraInt int32 `mapstructure:"extra_int"` ExtraSetting string `mapstructure:"extra"` ExtraMapSetting map[string]string `mapstructure:"extra_map"` ExtraListSetting []string `mapstructure:"extra_list"` }
ExampleExporter is for testing purposes. We are defining an example config and factory for "exampleexporter" exporter type.
type ExampleExporterConsumer ¶
type ExampleExporterConsumer struct { Traces []consumerdata.TraceData Metrics []consumerdata.MetricsData Logs []data.Logs ExporterStarted bool ExporterShutdown bool }
ExampleExporterConsumer stores consumed traces and metrics for testing purposes.
func (*ExampleExporterConsumer) ConsumeLogs ¶
func (*ExampleExporterConsumer) ConsumeMetricsData ¶
func (exp *ExampleExporterConsumer) ConsumeMetricsData(ctx context.Context, md consumerdata.MetricsData) error
ConsumeMetricsData receives consumerdata.MetricsData for processing by the MetricsConsumer.
func (*ExampleExporterConsumer) ConsumeTraceData ¶
func (exp *ExampleExporterConsumer) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error
ConsumeTraceData receives consumerdata.TraceData for processing by the TraceConsumer.
func (*ExampleExporterConsumer) Name ¶
func (exp *ExampleExporterConsumer) Name() string
Name returns the name of the exporter.
func (*ExampleExporterConsumer) Shutdown ¶
func (exp *ExampleExporterConsumer) Shutdown(context.Context) error
Shutdown is invoked during shutdown.
type ExampleExporterFactory ¶
type ExampleExporterFactory struct { }
ExampleExporterFactory is factory for ExampleExporter.
func (*ExampleExporterFactory) CreateDefaultConfig ¶
func (f *ExampleExporterFactory) CreateDefaultConfig() configmodels.Exporter
CreateDefaultConfig creates the default configuration for the Exporter.
func (*ExampleExporterFactory) CreateLogExporter ¶
func (f *ExampleExporterFactory) CreateLogExporter( ctx context.Context, params component.ExporterCreateParams, cfg configmodels.Exporter, ) (component.LogExporter, error)
func (*ExampleExporterFactory) CreateMetricsExporter ¶
func (f *ExampleExporterFactory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.MetricsExporterOld, error)
CreateMetricsExporter creates a metrics exporter based on this config.
func (*ExampleExporterFactory) CreateTraceExporter ¶
func (f *ExampleExporterFactory) CreateTraceExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.TraceExporterOld, error)
CreateTraceExporter creates a trace exporter based on this config.
func (*ExampleExporterFactory) Type ¶
func (f *ExampleExporterFactory) Type() configmodels.Type
Type gets the type of the Exporter config created by this factory.
type ExampleExtension ¶
type ExampleExtension struct { }
type ExampleExtensionCfg ¶
type ExampleExtensionCfg struct { configmodels.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct ExtraSetting string `mapstructure:"extra"` ExtraMapSetting map[string]string `mapstructure:"extra_map"` ExtraListSetting []string `mapstructure:"extra_list"` }
ExampleExtensionCfg is for testing purposes. We are defining an example config and factory for "exampleextension" extension type.
type ExampleExtensionFactory ¶
type ExampleExtensionFactory struct {
FailCreation bool
}
ExampleExtensionFactory is factory for ExampleExtensionCfg.
func (*ExampleExtensionFactory) CreateDefaultConfig ¶
func (f *ExampleExtensionFactory) CreateDefaultConfig() configmodels.Extension
CreateDefaultConfig creates the default configuration for the Extension.
func (*ExampleExtensionFactory) CreateExtension ¶
func (f *ExampleExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.ServiceExtension, error)
CreateExtension creates an Extension based on this config.
func (*ExampleExtensionFactory) Type ¶
func (f *ExampleExtensionFactory) Type() configmodels.Type
Type gets the type of the Extension config created by this factory.
type ExampleProcessor ¶
type ExampleProcessor struct {
// contains filtered or unexported fields
}
func (*ExampleProcessor) ConsumeLogs ¶
func (*ExampleProcessor) GetCapabilities ¶
func (ep *ExampleProcessor) GetCapabilities() component.ProcessorCapabilities
type ExampleProcessorCfg ¶
type ExampleProcessorCfg struct { configmodels.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct ExtraSetting string `mapstructure:"extra"` ExtraMapSetting map[string]string `mapstructure:"extra_map"` ExtraListSetting []string `mapstructure:"extra_list"` }
ExampleProcessorCfg is for testing purposes. We are defining an example config and factory for "exampleprocessor" processor type.
type ExampleProcessorFactory ¶
type ExampleProcessorFactory struct { }
ExampleProcessorFactory is factory for ExampleProcessor.
func (*ExampleProcessorFactory) CreateDefaultConfig ¶
func (f *ExampleProcessorFactory) CreateDefaultConfig() configmodels.Processor
CreateDefaultConfig creates the default configuration for the Processor.
func (*ExampleProcessorFactory) CreateLogProcessor ¶
func (f *ExampleProcessorFactory) CreateLogProcessor( ctx context.Context, params component.ProcessorCreateParams, cfg configmodels.Processor, nextConsumer consumer.LogConsumer, ) (component.LogProcessor, error)
func (*ExampleProcessorFactory) CreateMetricsProcessor ¶
func (f *ExampleProcessorFactory) CreateMetricsProcessor( logger *zap.Logger, nextConsumer consumer.MetricsConsumerOld, cfg configmodels.Processor, ) (component.MetricsProcessorOld, error)
CreateMetricsProcessor creates a metrics processor based on this config.
func (*ExampleProcessorFactory) CreateTraceProcessor ¶
func (f *ExampleProcessorFactory) CreateTraceProcessor( logger *zap.Logger, nextConsumer consumer.TraceConsumerOld, cfg configmodels.Processor, ) (component.TraceProcessorOld, error)
CreateTraceProcessor creates a trace processor based on this config.
func (*ExampleProcessorFactory) Type ¶
func (f *ExampleProcessorFactory) Type() configmodels.Type
Type gets the type of the Processor config created by this factory.
type ExampleReceiver ¶
type ExampleReceiver struct { configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // Configures the receiver server protocol. configprotocol.ProtocolServerSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct ExtraSetting string `mapstructure:"extra"` ExtraMapSetting map[string]string `mapstructure:"extra_map"` ExtraListSetting []string `mapstructure:"extra_list"` // FailTraceCreation causes CreateTraceReceiver to fail. Useful for testing. FailTraceCreation bool `mapstructure:"-"` // FailMetricsCreation causes CreateTraceReceiver to fail. Useful for testing. FailMetricsCreation bool `mapstructure:"-"` }
ExampleReceiver is for testing purposes. We are defining an example config and factory for "examplereceiver" receiver type.
type ExampleReceiverFactory ¶
type ExampleReceiverFactory struct { }
ExampleReceiverFactory is factory for ExampleReceiver.
func (*ExampleReceiverFactory) CreateDefaultConfig ¶
func (f *ExampleReceiverFactory) CreateDefaultConfig() configmodels.Receiver
CreateDefaultConfig creates the default configuration for the Receiver.
func (*ExampleReceiverFactory) CreateLogReceiver ¶
func (f *ExampleReceiverFactory) CreateLogReceiver( ctx context.Context, params component.ReceiverCreateParams, cfg configmodels.Receiver, nextConsumer consumer.LogConsumer, ) (component.LogReceiver, error)
func (*ExampleReceiverFactory) CreateMetricsReceiver ¶
func (f *ExampleReceiverFactory) CreateMetricsReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.MetricsConsumerOld) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*ExampleReceiverFactory) CreateTraceReceiver ¶
func (f *ExampleReceiverFactory) CreateTraceReceiver( ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.TraceConsumerOld, ) (component.TraceReceiver, error)
CreateTraceReceiver creates a trace receiver based on this config.
func (*ExampleReceiverFactory) CustomUnmarshaler ¶
func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
CustomUnmarshaler returns nil because we don't need custom unmarshaling for this factory.
func (*ExampleReceiverFactory) Type ¶
func (f *ExampleReceiverFactory) Type() configmodels.Type
Type gets the type of the Receiver config created by this factory.
type ExampleReceiverProducer ¶
type ExampleReceiverProducer struct { Started bool Stopped bool TraceConsumer consumer.TraceConsumerOld MetricsConsumer consumer.MetricsConsumerOld LogConsumer consumer.LogConsumer }
ExampleReceiverProducer allows producing traces and metrics for testing purposes.
type Factories ¶
type Factories struct { // Receivers maps receiver type names in the config to the respective factory. Receivers map[configmodels.Type]component.ReceiverFactoryBase // Processors maps processor type names in the config to the respective factory. Processors map[configmodels.Type]component.ProcessorFactoryBase // Exporters maps exporter type names in the config to the respective factory. Exporters map[configmodels.Type]component.ExporterFactoryBase // Extensions maps extension type names in the config to the respective factory. Extensions map[configmodels.Type]component.ExtensionFactory }
Factories struct holds in a single type all component factories that can be handled by the Config.
func ExampleComponents ¶
ExampleComponents registers example factories. This is only used by tests.
type MultiProtoReceiver ¶
type MultiProtoReceiver struct { TypeVal configmodels.Type `mapstructure:"-"` NameVal string `mapstructure:"-"` Protocols map[string]MultiProtoReceiverOneCfg `mapstructure:"protocols"` }
MultiProtoReceiver is for testing purposes. We are defining an example multi protocol config and factory for "multireceiver" receiver type.
func (*MultiProtoReceiver) Name ¶
func (rs *MultiProtoReceiver) Name() string
Name gets the exporter name.
func (*MultiProtoReceiver) SetName ¶
func (rs *MultiProtoReceiver) SetName(name string)
SetName sets the receiver name.
func (*MultiProtoReceiver) SetType ¶
func (rs *MultiProtoReceiver) SetType(typeStr configmodels.Type)
SetType sets the receiver type.
func (*MultiProtoReceiver) Type ¶
func (rs *MultiProtoReceiver) Type() configmodels.Type
Type sets the receiver type.
type MultiProtoReceiverFactory ¶
type MultiProtoReceiverFactory struct { }
MultiProtoReceiverFactory is factory for MultiProtoReceiver.
func (*MultiProtoReceiverFactory) CreateDefaultConfig ¶
func (f *MultiProtoReceiverFactory) CreateDefaultConfig() configmodels.Receiver
CreateDefaultConfig creates the default configuration for the Receiver.
func (*MultiProtoReceiverFactory) CreateMetricsReceiver ¶
func (f *MultiProtoReceiverFactory) CreateMetricsReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.MetricsConsumerOld) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*MultiProtoReceiverFactory) CreateTraceReceiver ¶
func (f *MultiProtoReceiverFactory) CreateTraceReceiver( ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.TraceConsumerOld, ) (component.TraceReceiver, error)
CreateTraceReceiver creates a trace receiver based on this config.
func (*MultiProtoReceiverFactory) CustomUnmarshaler ¶
func (f *MultiProtoReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
CustomUnmarshaler returns nil because we don't need custom unmarshaling for this factory.
func (*MultiProtoReceiverFactory) Type ¶
func (f *MultiProtoReceiverFactory) Type() configmodels.Type
Type gets the type of the Receiver config created by this factory.
type MultiProtoReceiverOneCfg ¶
type MultiProtoReceiverOneCfg struct { Endpoint string `mapstructure:"endpoint"` ExtraSetting string `mapstructure:"extra"` }
MultiProtoReceiverOneCfg is multi proto receiver config.
Directories ¶
Path | Synopsis |
---|---|
configauth
module
|
|
Package configcheck has checks to be applied to configuration objects implemented by factories of components used in the OpenTelemetry collector.
|
Package configcheck has checks to be applied to configuration objects implemented by factories of components used in the OpenTelemetry collector. |
configcompression
module
|
|
Package configerror contains the common errors caused by malformed configs.
|
Package configerror contains the common errors caused by malformed configs. |
Package configgrpc defines the gRPC configuration settings.
|
Package configgrpc defines the gRPC configuration settings. |
xconfighttp
Module
|
|
Package configmodels defines the data models for entities.
|
Package configmodels defines the data models for entities. |
configopaque
module
|
|
configretry
module
|
|
configtelemetry
module
|
|
internal
module
|