componenttest

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 16 Imported by: 37

Documentation

Overview

Package componenttest define types and functions used to help test packages implementing the component package interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDocs added in v0.5.0

func CheckDocs(projectPath string, relativeComponentsPath string, projectGoModule string) error

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

func ExampleComponents() (
	factories component.Factories,
	err error,
)

ExampleComponents registers example factories. This is only used by tests.

func NewNopHost

func NewNopHost() component.Host

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 (*ErrorWaitingHost) GetExtensions

func (*ErrorWaitingHost) GetFactory

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 (exp *ExampleExporterConsumer) ConsumeLogs(_ context.Context, ld data.Logs) error

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

Shutdown is invoked during shutdown.

func (*ExampleExporterConsumer) Start added in v0.7.0

Start tells the exporter to start. The exporter may prepare for exporting by connecting to the endpoint. Host parameter can be used for communicating with the host after Start() has already returned.

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 (*ExampleExporterFactory) CreateMetricsExporter added in v0.7.0

CreateMetricsExporter creates a metrics exporter based on this config.

func (*ExampleExporterFactory) CreateTraceExporter added in v0.7.0

CreateTraceExporter creates a trace exporter based on this config.

func (*ExampleExporterFactory) Type added in v0.7.0

Type gets the type of the Exporter config created by this factory.

type ExampleExtension added in v0.7.0

type ExampleExtension struct {
}

func (*ExampleExtension) Shutdown added in v0.7.0

func (e *ExampleExtension) Shutdown(_ context.Context) error

func (*ExampleExtension) Start added in v0.7.0

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

CreateExtension creates an Extension based on this config.

func (*ExampleExtensionFactory) Type added in v0.7.0

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 (ep *ExampleProcessor) ConsumeLogs(ctx context.Context, ld data.Logs) error

func (*ExampleProcessor) GetCapabilities added in v0.7.0

func (ep *ExampleProcessor) GetCapabilities() component.ProcessorCapabilities

func (*ExampleProcessor) Shutdown added in v0.7.0

func (ep *ExampleProcessor) Shutdown(_ context.Context) error

func (*ExampleProcessor) Start added in v0.7.0

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 (*ExampleProcessorFactory) CreateMetricsProcessor added in v0.7.0

CreateMetricsProcessor creates a metrics processor based on this config.

func (*ExampleProcessorFactory) CreateTraceProcessor added in v0.7.0

CreateTraceProcessor creates a trace processor based on this config.

func (*ExampleProcessorFactory) Type added in v0.7.0

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 (*ExampleReceiverFactory) CreateMetricsReceiver added in v0.7.0

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*ExampleReceiverFactory) CreateTraceReceiver added in v0.7.0

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

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.

func (*ExampleReceiverProducer) Shutdown added in v0.7.0

Shutdown tells the receiver that should stop reception,

func (*ExampleReceiverProducer) Start added in v0.7.0

Start tells the receiver to start its processing.

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

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

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*MultiProtoReceiverFactory) CreateTraceReceiver added in v0.7.0

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

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 (*NopHost) GetExtensions

func (nh *NopHost) GetExtensions() map[configmodels.Extension]component.ServiceExtension

func (*NopHost) GetFactory

func (nh *NopHost) GetFactory(_ component.Kind, _ configmodels.Type) component.Factory

GetFactory of the specified kind. Returns the factory for a component type.

func (*NopHost) ReportFatalError

func (nh *NopHost) ReportFatalError(_ error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL