package basic

import "go.opentelemetry.io/otel/sdk/metric/controller/basic"

Index

Constants

const DefaultPeriod = 10 * time.Second

DefaultPeriod is used for:

- the minimum time between calls to Collect() - the timeout for Export() - the timeout for Collect().

Variables

var ErrControllerStarted = fmt.Errorf("controller already started")

ErrControllerStarted indicates that a controller was started more than once.

Types

type Controller

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

Controller organizes and synchronizes collection of metric data in both "pull" and "push" configurations. This supports two distinct modes:

The controller supports mixing push and pull access to metric data using the export.CheckpointSet RWLock interface. Collection will be blocked by a pull request in the basic controller.

func New

func New(checkpointer export.Checkpointer, opts ...Option) *Controller

New constructs a Controller using the provided checkpointer and options (including optional exporter) to configure a metric export pipeline.

func (*Controller) Collect

func (c *Controller) Collect(ctx context.Context) error

Collect requests a collection. The collection will be skipped if the last collection is aged less than the configured collection period.

func (*Controller) ForEach

func (c *Controller) ForEach(ks export.ExportKindSelector, f func(export.Record) error) error

ForEach gives the caller read-locked access to the current export.CheckpointSet.

func (*Controller) IsRunning

func (c *Controller) IsRunning() bool

IsRunning returns true if the controller was started via Start(), indicating that the current export.CheckpointSet is being kept up-to-date.

func (*Controller) MeterProvider

func (c *Controller) MeterProvider() metric.MeterProvider

MeterProvider returns a MeterProvider instance for this controller.

func (*Controller) SetClock

func (c *Controller) SetClock(clock controllerTime.Clock)

SetClock supports setting a mock clock for testing. This must be called before Start().

func (*Controller) Start

func (c *Controller) Start(ctx context.Context) error

Start begins a ticker that periodically collects and exports metrics with the configured interval. This is required for calling a configured Exporter (see WithExporter) and is otherwise optional when only pulling metric data.

The passed context is passed to Collect() and subsequently to asynchronous instrument callbacks. Returns an error when the controller was already started.

Note that it is not necessary to Start a controller when only pulling data; use the Collect() and ForEach() methods directly in this case.

func (*Controller) Stop

func (c *Controller) Stop(ctx context.Context) error

Stop waits for the background goroutine to return and then collects and exports metrics one last time before returning. The passed context is passed to the final Collect() and subsequently to the final asynchronous instruments.

Note that Stop() will not cancel an ongoing collection or export.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the interface that applies the value to a configuration option.

func WithCollectPeriod

func WithCollectPeriod(period time.Duration) Option

WithCollectPeriod sets the CollectPeriod configuration option of a Config.

func WithCollectTimeout

func WithCollectTimeout(timeout time.Duration) Option

WithCollectTimeout sets the CollectTimeout configuration option of a Config.

func WithExporter

func WithExporter(exporter export.Exporter) Option

WithExporter sets the exporter configuration option of a Config.

func WithPushTimeout

func WithPushTimeout(timeout time.Duration) Option

WithPushTimeout sets the PushTimeout configuration option of a Config.

func WithResource

func WithResource(r *resource.Resource) Option

WithResource sets the Resource configuration option of a Config by merging it with the Resource configuration in the environment.

Source Files

config.go controller.go

Version
v0.21.0
Published
Jun 18, 2021
Platform
linux/amd64
Imports
11 packages
Last checked
1 hour ago

Tools for package owners.