componenttest

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 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.

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

func (*ExampleExporterConsumer) ConsumeMetrics added in v0.9.0

func (exp *ExampleExporterConsumer) ConsumeMetrics(_ context.Context, md pdata.Metrics) error

ConsumeMetricsData receives consumerdata.MetricsData for processing by the MetricsConsumer.

func (*ExampleExporterConsumer) ConsumeTraces added in v0.9.0

func (exp *ExampleExporterConsumer) ConsumeTraces(_ context.Context, td pdata.Traces) error

ConsumeTraceData receives consumerdata.TraceData for processing by the TracesConsumer.

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) CreateTracesExporter added in v0.14.0

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

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 pdata.Logs) error

func (*ExampleProcessor) ConsumeMetrics added in v0.9.0

func (ep *ExampleProcessor) ConsumeMetrics(ctx context.Context, md pdata.Metrics) error

func (*ExampleProcessor) ConsumeTraces added in v0.9.0

func (ep *ExampleProcessor) ConsumeTraces(ctx context.Context, td pdata.Traces) 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) CreateTracesProcessor added in v0.14.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 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 (*ExampleReceiverFactory) CreateMetricsReceiver added in v0.7.0

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*ExampleReceiverFactory) CreateTracesReceiver added in v0.14.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 implements the deprecated way to provide custom unmarshalers.

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.TracesConsumer
	MetricsConsumer consumer.MetricsConsumer
	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 {
	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

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*MultiProtoReceiverFactory) CreateMetricsReceiver added in v0.7.0

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*MultiProtoReceiverFactory) CreateTracesReceiver added in v0.14.0

CreateTraceReceiver creates a trace receiver based on this config.

func (*MultiProtoReceiverFactory) Type added in v0.7.0

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

func (*MultiProtoReceiverFactory) Unmarshal added in v0.8.0

func (f *MultiProtoReceiverFactory) Unmarshal(componentViperSection *viper.Viper, intoCfg interface{}) error

Unmarshal implements the ConfigUnmarshaler interface.

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