Documentation ¶
Overview ¶
Package componenttest define types and functions used to help test packages implementing the component package interfaces.
Index ¶
- func CheckDocs(projectPath string, relativeComponentsPath string, projectGoModule string) error
- func ExampleComponents() (factories component.Factories, err error)
- func NewNopHost() component.Host
- type ErrorWaitingHost
- func (ews *ErrorWaitingHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter
- func (ews *ErrorWaitingHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension
- func (ews *ErrorWaitingHost) GetFactory(_ component.Kind, _ configmodels.Type) component.Factory
- func (ews *ErrorWaitingHost) ReportFatalError(err error)
- func (ews *ErrorWaitingHost) WaitForFatalError(timeout time.Duration) (receivedError bool, err error)
- type ExampleExporter
- type ExampleExporterConsumer
- func (exp *ExampleExporterConsumer) ConsumeLogs(_ context.Context, ld data.Logs) error
- func (exp *ExampleExporterConsumer) ConsumeMetricsData(_ context.Context, md consumerdata.MetricsData) error
- func (exp *ExampleExporterConsumer) ConsumeTraceData(_ context.Context, td consumerdata.TraceData) error
- func (exp *ExampleExporterConsumer) Name() string
- func (exp *ExampleExporterConsumer) Shutdown(context.Context) error
- func (exp *ExampleExporterConsumer) Start(_ context.Context, _ component.Host) error
- type ExampleExporterFactory
- func (f *ExampleExporterFactory) CreateDefaultConfig() configmodels.Exporter
- func (f *ExampleExporterFactory) CreateLogsExporter(_ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter) (component.LogsExporter, error)
- func (f *ExampleExporterFactory) CreateMetricsExporter(_ *zap.Logger, _ configmodels.Exporter) (component.MetricsExporterOld, error)
- func (f *ExampleExporterFactory) CreateTraceExporter(_ *zap.Logger, _ 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
- type ExampleProcessorCfg
- type ExampleProcessorFactory
- func (f *ExampleProcessorFactory) CreateDefaultConfig() configmodels.Processor
- func (f *ExampleProcessorFactory) CreateLogsProcessor(_ context.Context, _ component.ProcessorCreateParams, _ configmodels.Processor, ...) (component.LogsProcessor, error)
- func (f *ExampleProcessorFactory) CreateMetricsProcessor(_ *zap.Logger, _ consumer.MetricsConsumerOld, _ configmodels.Processor) (component.MetricsProcessorOld, error)
- func (f *ExampleProcessorFactory) CreateTraceProcessor(_ *zap.Logger, _ consumer.TraceConsumerOld, _ configmodels.Processor) (component.TraceProcessorOld, error)
- func (f *ExampleProcessorFactory) Type() configmodels.Type
- type ExampleReceiver
- type ExampleReceiverFactory
- func (f *ExampleReceiverFactory) CreateDefaultConfig() configmodels.Receiver
- func (f *ExampleReceiverFactory) CreateLogsReceiver(_ context.Context, _ component.ReceiverCreateParams, cfg configmodels.Receiver, ...) (component.LogsReceiver, error)
- func (f *ExampleReceiverFactory) CreateMetricsReceiver(_ context.Context, _ *zap.Logger, cfg configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *ExampleReceiverFactory) CreateTraceReceiver(_ context.Context, _ *zap.Logger, cfg configmodels.Receiver, ...) (component.TraceReceiver, error)
- func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
- func (f *ExampleReceiverFactory) Type() configmodels.Type
- type ExampleReceiverProducer
- type MultiProtoReceiver
- type MultiProtoReceiverFactory
- func (f *MultiProtoReceiverFactory) CreateDefaultConfig() configmodels.Receiver
- func (f *MultiProtoReceiverFactory) CreateMetricsReceiver(_ context.Context, _ *zap.Logger, _ configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *MultiProtoReceiverFactory) CreateTraceReceiver(_ context.Context, _ *zap.Logger, _ configmodels.Receiver, ...) (component.TraceReceiver, error)
- func (f *MultiProtoReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
- func (f *MultiProtoReceiverFactory) Type() configmodels.Type
- type MultiProtoReceiverOneCfg
- type NopHost
- func (nh *NopHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter
- func (nh *NopHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension
- func (nh *NopHost) GetFactory(_ component.Kind, _ configmodels.Type) component.Factory
- func (nh *NopHost) ReportFatalError(_ error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDocs ¶ added in v0.5.0
CheckDocs returns an error if README.md for at least one enabled component is missing. "projectPath" is the absolute path to the root of the project to which the components belong. "defaultComponentsFilePath" is the path to the file that contains imports to all required components, "goModule" is the Go module to which the imports belong. This method is intended to be used only to verify documentation in Opentelemetry core and contrib repositories. Examples, 1) Usage in the core repo:
componenttest.CheckDocs(
"path/to/project", "service/defaultcomponents/defaults.go", "go.opentelemetry.io/collector", )
2) Usage in the contrib repo: componenttest.CheckDocs(
"path/to/project", "cmd/otelcontrib/components.go", "github.com/open-telemetry/opentelemetry-collector-contrib", ).
func ExampleComponents ¶ added in v0.7.0
ExampleComponents registers example factories. This is only used by tests.
func NewNopHost ¶
NewNopHost returns a new instance of NopHost with proper defaults for most tests.
Types ¶
type ErrorWaitingHost ¶
type ErrorWaitingHost struct {
// contains filtered or unexported fields
}
ErrorWaitingHost mocks an component.Host for test purposes.
func NewErrorWaitingHost ¶
func NewErrorWaitingHost() *ErrorWaitingHost
NewErrorWaitingHost returns a new instance of ErrorWaitingHost with proper defaults for most tests.
func (*ErrorWaitingHost) GetExporters ¶
func (ews *ErrorWaitingHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter
func (*ErrorWaitingHost) GetExtensions ¶
func (ews *ErrorWaitingHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension
func (*ErrorWaitingHost) GetFactory ¶
func (ews *ErrorWaitingHost) GetFactory(_ component.Kind, _ configmodels.Type) component.Factory
GetFactory of the specified kind. Returns the factory for a component type.
func (*ErrorWaitingHost) ReportFatalError ¶
func (ews *ErrorWaitingHost) ReportFatalError(err error)
ReportFatalError is used to report to the host that the extension encountered a fatal error (i.e.: an error that the instance can't recover from) after its start function has already returned.
func (*ErrorWaitingHost) WaitForFatalError ¶
func (ews *ErrorWaitingHost) WaitForFatalError(timeout time.Duration) (receivedError bool, err error)
WaitForFatalError waits the given amount of time until an error is reported via ReportFatalError. It returns the error, if any, and a bool to indicated if an error was received before the time out.
type ExampleExporter ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
func (*ExampleExporterConsumer) ConsumeMetricsData ¶ added in v0.7.0
func (exp *ExampleExporterConsumer) ConsumeMetricsData(_ context.Context, md consumerdata.MetricsData) error
ConsumeMetricsData receives consumerdata.MetricsData for processing by the MetricsConsumer.
func (*ExampleExporterConsumer) ConsumeTraceData ¶ added in v0.7.0
func (exp *ExampleExporterConsumer) ConsumeTraceData(_ context.Context, td consumerdata.TraceData) error
ConsumeTraceData receives consumerdata.TraceData for processing by the TraceConsumer.
func (*ExampleExporterConsumer) Name ¶ added in v0.7.0
func (exp *ExampleExporterConsumer) Name() string
Name returns the name of the exporter.
func (*ExampleExporterConsumer) Shutdown ¶ added in v0.7.0
func (exp *ExampleExporterConsumer) Shutdown(context.Context) error
Shutdown is invoked during shutdown.
type ExampleExporterFactory ¶ added in v0.7.0
type ExampleExporterFactory struct { }
ExampleExporterFactory is factory for ExampleExporter.
func (*ExampleExporterFactory) CreateDefaultConfig ¶ added in v0.7.0
func (f *ExampleExporterFactory) CreateDefaultConfig() configmodels.Exporter
CreateDefaultConfig creates the default configuration for the Exporter.
func (*ExampleExporterFactory) CreateLogsExporter ¶ added in v0.7.0
func (f *ExampleExporterFactory) CreateLogsExporter( _ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter, ) (component.LogsExporter, error)
func (*ExampleExporterFactory) CreateMetricsExporter ¶ added in v0.7.0
func (f *ExampleExporterFactory) CreateMetricsExporter(_ *zap.Logger, _ configmodels.Exporter) (component.MetricsExporterOld, error)
CreateMetricsExporter creates a metrics exporter based on this config.
func (*ExampleExporterFactory) CreateTraceExporter ¶ added in v0.7.0
func (f *ExampleExporterFactory) CreateTraceExporter(_ *zap.Logger, _ configmodels.Exporter) (component.TraceExporterOld, error)
CreateTraceExporter creates a trace exporter based on this config.
func (*ExampleExporterFactory) Type ¶ added in v0.7.0
func (f *ExampleExporterFactory) Type() configmodels.Type
Type gets the type of the Exporter config created by this factory.
type ExampleExtension ¶ added in v0.7.0
type ExampleExtension struct { }
type ExampleExtensionCfg ¶ added in v0.7.0
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 ¶ added in v0.7.0
type ExampleExtensionFactory struct {
FailCreation bool
}
ExampleExtensionFactory is factory for ExampleExtensionCfg.
func (*ExampleExtensionFactory) CreateDefaultConfig ¶ added in v0.7.0
func (f *ExampleExtensionFactory) CreateDefaultConfig() configmodels.Extension
CreateDefaultConfig creates the default configuration for the Extension.
func (*ExampleExtensionFactory) CreateExtension ¶ added in v0.7.0
func (f *ExampleExtensionFactory) CreateExtension(_ context.Context, _ component.ExtensionCreateParams, _ configmodels.Extension) (component.ServiceExtension, error)
CreateExtension creates an Extension based on this config.
func (*ExampleExtensionFactory) Type ¶ added in v0.7.0
func (f *ExampleExtensionFactory) Type() configmodels.Type
Type gets the type of the Extension config created by this factory.
type ExampleProcessor ¶ added in v0.7.0
type ExampleProcessor struct {
// contains filtered or unexported fields
}
func (*ExampleProcessor) ConsumeLogs ¶ added in v0.7.0
func (*ExampleProcessor) GetCapabilities ¶ added in v0.7.0
func (ep *ExampleProcessor) GetCapabilities() component.ProcessorCapabilities
type ExampleProcessorCfg ¶ added in v0.7.0
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 ¶ added in v0.7.0
type ExampleProcessorFactory struct { }
ExampleProcessorFactory is factory for ExampleProcessor.
func (*ExampleProcessorFactory) CreateDefaultConfig ¶ added in v0.7.0
func (f *ExampleProcessorFactory) CreateDefaultConfig() configmodels.Processor
CreateDefaultConfig creates the default configuration for the Processor.
func (*ExampleProcessorFactory) CreateLogsProcessor ¶ added in v0.7.0
func (f *ExampleProcessorFactory) CreateLogsProcessor( _ context.Context, _ component.ProcessorCreateParams, _ configmodels.Processor, nextConsumer consumer.LogsConsumer, ) (component.LogsProcessor, error)
func (*ExampleProcessorFactory) CreateMetricsProcessor ¶ added in v0.7.0
func (f *ExampleProcessorFactory) CreateMetricsProcessor( _ *zap.Logger, _ consumer.MetricsConsumerOld, _ configmodels.Processor, ) (component.MetricsProcessorOld, error)
CreateMetricsProcessor creates a metrics processor based on this config.
func (*ExampleProcessorFactory) CreateTraceProcessor ¶ added in v0.7.0
func (f *ExampleProcessorFactory) CreateTraceProcessor( _ *zap.Logger, _ consumer.TraceConsumerOld, _ configmodels.Processor, ) (component.TraceProcessorOld, error)
CreateTraceProcessor creates a trace processor based on this config.
func (*ExampleProcessorFactory) Type ¶ added in v0.7.0
func (f *ExampleProcessorFactory) Type() configmodels.Type
Type gets the type of the Processor config created by this factory.
type ExampleReceiver ¶ added in v0.7.0
type ExampleReceiver struct { configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // Configures the receiver server protocol. confignet.TCPAddr `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 ¶ added in v0.7.0
type ExampleReceiverFactory struct { }
ExampleReceiverFactory is factory for ExampleReceiver.
func (*ExampleReceiverFactory) CreateDefaultConfig ¶ added in v0.7.0
func (f *ExampleReceiverFactory) CreateDefaultConfig() configmodels.Receiver
CreateDefaultConfig creates the default configuration for the Receiver.
func (*ExampleReceiverFactory) CreateLogsReceiver ¶ added in v0.7.0
func (f *ExampleReceiverFactory) CreateLogsReceiver( _ context.Context, _ component.ReceiverCreateParams, cfg configmodels.Receiver, nextConsumer consumer.LogsConsumer, ) (component.LogsReceiver, error)
func (*ExampleReceiverFactory) CreateMetricsReceiver ¶ added in v0.7.0
func (f *ExampleReceiverFactory) CreateMetricsReceiver(_ context.Context, _ *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.MetricsConsumerOld) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*ExampleReceiverFactory) CreateTraceReceiver ¶ added in v0.7.0
func (f *ExampleReceiverFactory) CreateTraceReceiver( _ context.Context, _ *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.TraceConsumerOld, ) (component.TraceReceiver, error)
CreateTraceReceiver creates a trace receiver based on this config.
func (*ExampleReceiverFactory) CustomUnmarshaler ¶ added in v0.7.0
func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
CustomUnmarshaler returns nil because we don't need custom unmarshaling for this factory.
func (*ExampleReceiverFactory) Type ¶ added in v0.7.0
func (f *ExampleReceiverFactory) Type() configmodels.Type
Type gets the type of the Receiver config created by this factory.
type ExampleReceiverProducer ¶ added in v0.7.0
type ExampleReceiverProducer struct { Started bool Stopped bool TraceConsumer consumer.TraceConsumerOld MetricsConsumer consumer.MetricsConsumerOld LogConsumer consumer.LogsConsumer }
ExampleReceiverProducer allows producing traces and metrics for testing purposes.
type MultiProtoReceiver ¶ added in v0.7.0
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 ¶ added in v0.7.0
func (rs *MultiProtoReceiver) Name() string
Name gets the exporter name.
func (*MultiProtoReceiver) SetName ¶ added in v0.7.0
func (rs *MultiProtoReceiver) SetName(name string)
SetName sets the receiver name.
func (*MultiProtoReceiver) SetType ¶ added in v0.7.0
func (rs *MultiProtoReceiver) SetType(typeStr configmodels.Type)
SetType sets the receiver type.
func (*MultiProtoReceiver) Type ¶ added in v0.7.0
func (rs *MultiProtoReceiver) Type() configmodels.Type
Type sets the receiver type.
type MultiProtoReceiverFactory ¶ added in v0.7.0
type MultiProtoReceiverFactory struct { }
MultiProtoReceiverFactory is factory for MultiProtoReceiver.
func (*MultiProtoReceiverFactory) CreateDefaultConfig ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) CreateDefaultConfig() configmodels.Receiver
CreateDefaultConfig creates the default configuration for the Receiver.
func (*MultiProtoReceiverFactory) CreateMetricsReceiver ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) CreateMetricsReceiver(_ context.Context, _ *zap.Logger, _ configmodels.Receiver, _ consumer.MetricsConsumerOld) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*MultiProtoReceiverFactory) CreateTraceReceiver ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) CreateTraceReceiver( _ context.Context, _ *zap.Logger, _ configmodels.Receiver, _ consumer.TraceConsumerOld, ) (component.TraceReceiver, error)
CreateTraceReceiver creates a trace receiver based on this config.
func (*MultiProtoReceiverFactory) CustomUnmarshaler ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler
CustomUnmarshaler returns nil because we don't need custom unmarshaling for this factory.
func (*MultiProtoReceiverFactory) Type ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) Type() configmodels.Type
Type gets the type of the Receiver config created by this factory.
type MultiProtoReceiverOneCfg ¶ added in v0.7.0
type MultiProtoReceiverOneCfg struct { Endpoint string `mapstructure:"endpoint"` ExtraSetting string `mapstructure:"extra"` }
MultiProtoReceiverOneCfg is multi proto receiver config.
type NopHost ¶
type NopHost struct { }
NopHost mocks a receiver.ReceiverHost for test purposes.
func (*NopHost) GetExporters ¶
func (nh *NopHost) GetExporters() map[configmodels.DataType]map[configmodels.Exporter]component.Exporter
func (*NopHost) GetExtensions ¶
func (nh *NopHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension
func (*NopHost) GetFactory ¶
GetFactory of the specified kind. Returns the factory for a component type.
func (*NopHost) ReportFatalError ¶
ReportFatalError is used to report to the host that the receiver encountered a fatal error (i.e.: an error that the instance can't recover from) after its start function has already returned.