basic

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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

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

ErrControllerStarted indicates that a controller was started more than once.

Functions

This section is empty.

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:

  • Push and Pull: Start() must be called to begin calling the exporter; Collect() is called periodically by a background thread after starting the controller.
  • Pull-Only: Start() is optional in this case, to call Collect periodically. If Start() is not called, Collect() can be called manually to initiate collection

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

func New

func New(checkpointerFactory export.CheckpointerFactory, opts ...Option) *Controller

New constructs a Controller using the provided checkpointer factory 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(readerFunc func(l instrumentation.Library, r export.Reader) error) error

ForEach implements export.InstrumentationLibraryReader.

func (*Controller) IsRunning

func (c *Controller) IsRunning() bool

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

func (*Controller) Meter added in v0.24.0

func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter

Meter returns a new Meter defined by instrumentationName and configured with opts.

func (*Controller) Resource added in v0.23.0

func (c *Controller) Resource() *resource.Resource

Resource returns the *resource.Resource associated with 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 added in v0.19.0

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.

Jump to

Keyboard shortcuts

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