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
- func TestApplicationStartInfo() component.ApplicationStartInfo
- 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 pdata.Logs) error
- func (exp *ExampleExporterConsumer) ConsumeMetrics(_ context.Context, md pdata.Metrics) error
- func (exp *ExampleExporterConsumer) ConsumeTraces(_ context.Context, td pdata.Traces) error
- 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(_ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter) (component.MetricsExporter, error)
- func (f *ExampleExporterFactory) CreateTracesExporter(_ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter) (component.TracesExporter, error)
- func (f *ExampleExporterFactory) CustomUnmarshaler() component.CustomUnmarshaler
- 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 pdata.Logs) error
- func (ep *ExampleProcessor) ConsumeMetrics(ctx context.Context, md pdata.Metrics) error
- func (ep *ExampleProcessor) ConsumeTraces(ctx context.Context, td pdata.Traces) error
- func (ep *ExampleProcessor) GetCapabilities() component.ProcessorCapabilities
- func (ep *ExampleProcessor) Shutdown(_ context.Context) error
- func (ep *ExampleProcessor) Start(_ context.Context, _ component.Host) error
- 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(ctx context.Context, params component.ProcessorCreateParams, ...) (component.MetricsProcessor, error)
- func (f *ExampleProcessorFactory) CreateTracesProcessor(ctx context.Context, params component.ProcessorCreateParams, ...) (component.TracesProcessor, 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, _ component.ReceiverCreateParams, cfg configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *ExampleReceiverFactory) CreateTracesReceiver(_ context.Context, _ component.ReceiverCreateParams, cfg configmodels.Receiver, ...) (component.TracesReceiver, 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) CreateLogsReceiver(_ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, ...) (component.LogsReceiver, error)
- func (f *MultiProtoReceiverFactory) CreateMetricsReceiver(_ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, ...) (component.MetricsReceiver, error)
- func (f *MultiProtoReceiverFactory) CreateTracesReceiver(_ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, ...) (component.TracesReceiver, error)
- func (f *MultiProtoReceiverFactory) Type() configmodels.Type
- func (f *MultiProtoReceiverFactory) Unmarshal(componentViperSection *viper.Viper, intoCfg interface{}) error
- 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.
func TestApplicationStartInfo ¶ added in v0.9.0
func TestApplicationStartInfo() component.ApplicationStartInfo
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 []pdata.Traces Metrics []pdata.Metrics Logs []pdata.Logs ExporterStarted bool ExporterShutdown bool }
ExampleExporterConsumer stores consumed traces and metrics for testing purposes.
func (*ExampleExporterConsumer) ConsumeLogs ¶ added in v0.7.0
func (*ExampleExporterConsumer) ConsumeMetrics ¶ added in v0.9.0
ConsumeMetricsData receives consumerdata.MetricsData for processing by the MetricsConsumer.
func (*ExampleExporterConsumer) ConsumeTraces ¶ added in v0.9.0
ConsumeTraceData receives consumerdata.TraceData for processing by the TracesConsumer.
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( _ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter, ) (component.MetricsExporter, error)
CreateMetricsExporter creates a metrics exporter based on this config.
func (*ExampleExporterFactory) CreateTracesExporter ¶ added in v0.14.0
func (f *ExampleExporterFactory) CreateTracesExporter( _ context.Context, _ component.ExporterCreateParams, _ configmodels.Exporter, ) (component.TracesExporter, error)
CreateTraceExporter creates a trace exporter based on this config.
func (*ExampleExporterFactory) CustomUnmarshaler ¶ added in v0.8.0
func (f *ExampleExporterFactory) CustomUnmarshaler() component.CustomUnmarshaler
CustomUnmarshaler implements the deprecated way to provide custom unmarshalers.
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) ConsumeMetrics ¶ added in v0.9.0
func (*ExampleProcessor) ConsumeTraces ¶ added in v0.9.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(ctx context.Context, params component.ProcessorCreateParams, cfg configmodels.Processor, nextConsumer consumer.MetricsConsumer) (component.MetricsProcessor, error)
CreateMetricsProcessor creates a metrics processor based on this config.
func (*ExampleProcessorFactory) CreateTracesProcessor ¶ added in v0.14.0
func (f *ExampleProcessorFactory) CreateTracesProcessor(ctx context.Context, params component.ProcessorCreateParams, cfg configmodels.Processor, nextConsumer consumer.TracesConsumer) (component.TracesProcessor, 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 CreateTracesReceiver to fail. Useful for testing. FailTraceCreation bool `mapstructure:"-"` // FailMetricsCreation causes CreateMetricsReceiver 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, _ component.ReceiverCreateParams, cfg configmodels.Receiver, nextConsumer consumer.MetricsConsumer, ) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*ExampleReceiverFactory) CreateTracesReceiver ¶ added in v0.14.0
func (f *ExampleReceiverFactory) CreateTracesReceiver( _ context.Context, _ component.ReceiverCreateParams, cfg configmodels.Receiver, nextConsumer consumer.TracesConsumer, ) (component.TracesReceiver, 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 implements the deprecated way to provide custom unmarshalers.
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.TracesConsumer MetricsConsumer consumer.MetricsConsumer LogConsumer consumer.LogsConsumer }
ExampleReceiverProducer allows producing traces and metrics for testing purposes.
type MultiProtoReceiver ¶ added in v0.7.0
type MultiProtoReceiver struct { configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct 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.
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) CreateLogsReceiver ¶ added in v0.9.0
func (f *MultiProtoReceiverFactory) CreateLogsReceiver( _ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, _ consumer.LogsConsumer, ) (component.LogsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*MultiProtoReceiverFactory) CreateMetricsReceiver ¶ added in v0.7.0
func (f *MultiProtoReceiverFactory) CreateMetricsReceiver( _ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, _ consumer.MetricsConsumer, ) (component.MetricsReceiver, error)
CreateMetricsReceiver creates a metrics receiver based on this config.
func (*MultiProtoReceiverFactory) CreateTracesReceiver ¶ added in v0.14.0
func (f *MultiProtoReceiverFactory) CreateTracesReceiver( _ context.Context, _ component.ReceiverCreateParams, _ configmodels.Receiver, _ consumer.TracesConsumer, ) (component.TracesReceiver, error)
CreateTraceReceiver creates a trace receiver based on this config.
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.