otelcol

package module
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 35 Imported by: 66

Documentation

Overview

Package service handles the command-line, configuration, and runs the OpenTelemetry Collector.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCommand

func NewCommand(set CollectorSettings) *cobra.Command

NewCommand constructs a new cobra.Command using the given CollectorSettings. Any URIs specified in CollectorSettings.ConfigProviderSettings.ResolverSettings.URIs are considered defaults and will be overwritten by config flags passed as command-line arguments to the executable.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector represents a server providing the OpenTelemetry Collector service.

func NewCollector

func NewCollector(set CollectorSettings) (*Collector, error)

NewCollector creates and returns a new instance of Collector.

func (*Collector) DryRun

func (col *Collector) DryRun(ctx context.Context) error

func (*Collector) GetState

func (col *Collector) GetState() State

GetState returns current state of the collector server.

func (*Collector) Run

func (col *Collector) Run(ctx context.Context) error

Run starts the collector according to the given configuration, and waits for it to complete. Consecutive calls to Run are not allowed, Run shouldn't be called once a collector is shut down.

func (*Collector) Shutdown

func (col *Collector) Shutdown()

Shutdown shuts down the collector server.

type CollectorSettings

type CollectorSettings struct {
	// Factories service factories.
	Factories func() (Factories, error)

	// BuildInfo provides collector start information.
	BuildInfo component.BuildInfo

	// DisableGracefulShutdown disables the automatic graceful shutdown
	// of the collector on SIGINT or SIGTERM.
	// Users who want to handle signals themselves can disable this behavior
	// and manually handle the signals to shutdown the collector.
	DisableGracefulShutdown bool

	// Deprecated: [v0.95.0] Use ConfigProviderSettings instead.
	// ConfigProvider provides the service configuration.
	// If the provider watches for configuration change, collector may reload the new configuration upon changes.
	ConfigProvider ConfigProvider

	// ConfigProviderSettings allows configuring the way the Collector retrieves its configuration
	// The Collector will reload based on configuration changes from the ConfigProvider if any
	// confmap.Providers watch for configuration changes.
	ConfigProviderSettings ConfigProviderSettings

	// LoggingOptions provides a way to change behavior of zap logging.
	LoggingOptions []zap.Option

	// SkipSettingGRPCLogger avoids setting the grpc logger
	SkipSettingGRPCLogger bool
}

CollectorSettings holds configuration for creating a new Collector.

type Config

type Config struct {
	// Receivers is a map of ComponentID to Receivers.
	Receivers map[component.ID]component.Config

	// Exporters is a map of ComponentID to Exporters.
	Exporters map[component.ID]component.Config

	// Processors is a map of ComponentID to Processors.
	Processors map[component.ID]component.Config

	// Connectors is a map of ComponentID to connectors.
	Connectors map[component.ID]component.Config

	// Extensions is a map of ComponentID to extensions.
	Extensions map[component.ID]component.Config

	Service service.Config
}

Config defines the configuration for the various elements of collector or agent.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate returns an error if the config is invalid.

This function performs basic validation of configuration. There may be more subtle invalid cases that we currently don't check for but which we may want to add in the future (e.g. disallowing receiving and exporting on the same endpoint).

type ConfigProvider

type ConfigProvider interface {
	// Get returns the service configuration, or error otherwise.
	//
	// Should never be called concurrently with itself, Watch or Shutdown.
	Get(ctx context.Context, factories Factories) (*Config, error)

	// Watch blocks until any configuration change was detected or an unrecoverable error
	// happened during monitoring the configuration changes.
	//
	// Error is nil if the configuration is changed and needs to be re-fetched. Any non-nil
	// error indicates that there was a problem with watching the config changes.
	//
	// Should never be called concurrently with itself or Get.
	Watch() <-chan error

	// Shutdown signals that the provider is no longer in use and the that should close
	// and release any resources that it may have created.
	//
	// This function must terminate the Watch channel.
	//
	// Should never be called concurrently with itself or Get.
	Shutdown(ctx context.Context) error
}

ConfigProvider provides the service configuration.

The typical usage is the following:

cfgProvider.Get(...)
cfgProvider.Watch() // wait for an event.
cfgProvider.Get(...)
cfgProvider.Watch() // wait for an event.
// repeat Get/Watch cycle until it is time to shut down the Collector process.
cfgProvider.Shutdown()

func NewConfigProvider

func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error)

NewConfigProvider returns a new ConfigProvider that provides the service configuration: * Initially it resolves the "configuration map":

  • Retrieve the confmap.Conf by merging all retrieved maps from the given `locations` in order.
  • Then applies all the confmap.Converter in the given order.

* Then unmarshalls the confmap.Conf into the service Config.

type ConfigProviderSettings

type ConfigProviderSettings struct {
	// ResolverSettings are the settings to configure the behavior of the confmap.Resolver.
	ResolverSettings confmap.ResolverSettings
}

ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider.

type ConfmapProvider

type ConfmapProvider interface {
	// GetConfmap resolves the Collector's configuration and provides it as a confmap.Conf object.
	//
	// Should never be called concurrently with itself or any ConfigProvider method.
	GetConfmap(ctx context.Context) (*confmap.Conf, error)
}

ConfmapProvider is an optional interface to be implemented by ConfigProviders to provide confmap.Conf objects representing a marshaled version of the Collector's configuration.

The purpose of this interface is that otelcol.ConfigProvider structs do not necessarily need to use confmap.Conf as their underlying config structure.

type Factories

type Factories struct {
	// Receivers maps receiver type names in the config to the respective factory.
	Receivers map[component.Type]receiver.Factory

	// Processors maps processor type names in the config to the respective factory.
	Processors map[component.Type]processor.Factory

	// Exporters maps exporter type names in the config to the respective factory.
	Exporters map[component.Type]exporter.Factory

	// Extensions maps extension type names in the config to the respective factory.
	Extensions map[component.Type]extension.Factory

	// Connectors maps connector type names in the config to the respective factory.
	Connectors map[component.Type]connector.Factory
}

Factories struct holds in a single type all component factories that can be handled by the Config.

type State

type State int

State defines Collector's state.

const (
	StateStarting State = iota
	StateRunning
	StateClosing
	StateClosed
)

func (State) String

func (s State) String() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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