componenttest

package
Version: v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

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

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

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

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

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           []pdata.Traces
	Metrics          []pdata.Metrics
	Logs             []pdata.Logs
	ExporterStarted  bool
	ExporterShutdown bool
}

ExampleExporterConsumer stores consumed traces and metrics for testing purposes.

func (*ExampleExporterConsumer) ConsumeLogs

func (exp *ExampleExporterConsumer) ConsumeLogs(_ context.Context, ld pdata.Logs) error

func (*ExampleExporterConsumer) ConsumeMetrics

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

ConsumeMetricsData receives consumerdata.MetricsData for processing by the MetricsConsumer.

func (*ExampleExporterConsumer) ConsumeTraces

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

ConsumeTraceData receives consumerdata.TraceData for processing by the TracesConsumer.

func (*ExampleExporterConsumer) Shutdown

Shutdown is invoked during shutdown.

func (*ExampleExporterConsumer) Start

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

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) CreateLogsExporter

func (*ExampleExporterFactory) CreateMetricsExporter

CreateMetricsExporter creates a metrics exporter based on this config.

func (*ExampleExporterFactory) CreateTracesExporter

CreateTraceExporter creates a trace exporter based on this config.

func (*ExampleExporterFactory) CustomUnmarshaler

func (f *ExampleExporterFactory) CustomUnmarshaler() component.CustomUnmarshaler

CustomUnmarshaler implements the deprecated way to provide custom unmarshalers.

func (*ExampleExporterFactory) Type

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

type ExampleExtension

type ExampleExtension struct {
}

func (*ExampleExtension) Shutdown

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

func (*ExampleExtension) Start

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

CreateExtension creates an Extension based on this config.

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

func (*ExampleProcessor) ConsumeMetrics

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

func (*ExampleProcessor) ConsumeTraces

func (ep *ExampleProcessor) ConsumeTraces(ctx context.Context, td pdata.Traces) error

func (*ExampleProcessor) GetCapabilities

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

func (*ExampleProcessor) Shutdown

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

func (*ExampleProcessor) Start

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) CreateLogsProcessor

func (*ExampleProcessorFactory) CreateMetricsProcessor

CreateMetricsProcessor creates a metrics processor based on this config.

func (*ExampleProcessorFactory) CreateTracesProcessor

CreateTraceProcessor creates a trace processor based on this config.

func (*ExampleProcessorFactory) 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.
	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

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) CreateLogsReceiver

func (*ExampleReceiverFactory) CreateMetricsReceiver

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*ExampleReceiverFactory) CreateTracesReceiver

CreateTraceReceiver creates a trace receiver based on this config.

func (*ExampleReceiverFactory) CustomUnmarshaler

func (f *ExampleReceiverFactory) CustomUnmarshaler() component.CustomUnmarshaler

CustomUnmarshaler implements the deprecated way to provide custom unmarshalers.

func (*ExampleReceiverFactory) Type

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

type ExampleReceiverProducer

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

Shutdown tells the receiver that should stop reception,

func (*ExampleReceiverProducer) Start

Start tells the receiver to start its processing.

type MultiProtoReceiver

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

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) CreateLogsReceiver

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*MultiProtoReceiverFactory) CreateMetricsReceiver

CreateMetricsReceiver creates a metrics receiver based on this config.

func (*MultiProtoReceiverFactory) CreateTracesReceiver

CreateTraceReceiver creates a trace receiver based on this config.

func (*MultiProtoReceiverFactory) Type

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

func (*MultiProtoReceiverFactory) Unmarshal

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

Unmarshal implements the ConfigUnmarshaler interface.

type MultiProtoReceiverOneCfg

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