viewstate

package
v1.28.0 Latest Latest
Warning

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

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

Documentation

Overview

package viewstate implements a View compiler, which combines information about the instrument kind (especially synchronous vs. asynchronous), the configured view(s) and reader defaults, and conflicting instruments in the same namespace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accumulator

type Accumulator interface {
	// SnapshotAndProcess() takes a snapshot of data aggregated
	// through Update() and simultaneously resets the current
	// aggregator.  The attribute.Set is possibly filtered, after
	// which the snapshot is merged into the output.
	//
	// There is no return value from this method; the caller can
	// safely forget an Accumulator after this method is called,
	// provided Update is not used again.
	//
	// When `release` is true, this is the last time the Accumulator
	// will be snapshot/processed (according to the caller's
	// reference counting) and it can be forgotten.
	SnapshotAndProcess(release bool)
}

Accumulator is an intermediate interface used for short-term aggregation. Every Accumulator is also an Updater. The owner of an Accumulator is responsible for maintaining the current set of Accumulators, defined as those which have been Updated and not yet had SnapshotAndProcess() called.

type Compiler

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

Compiler implements Views for a single Meter. A single Compiler controls the namespace of metric instruments output and reports conflicting definitions for the same name.

Information flows through the Compiler as follows:

When new instruments are created:

  • The Compiler.Compile() method returns an Instrument value and possible duplicate or semantic conflict error.

When instruments are used: - The Instrument.NewAccumulator() method returns an Accumulator value for each attribute.Set used - The Accumulator.Update() aggregates one value for each measurement.

During collection:

  • The Accumulator.SnapshotAndProcess() method captures the current value and conveys it to the output storage
  • The Compiler.Collectors() interface returns one Collector per output Metric in the Meter (duplicate definitions included).
  • The Collector.Collect() method outputs one Point for each attribute.Set in the result.

func New

func New(library instrumentation.Library, views *view.Views) *Compiler

New returns a compiler for library given configured views.

func (*Compiler) Collectors

func (v *Compiler) Collectors() []data.Collector

func (*Compiler) Compile

Compile is called during NewInstrument by the Meter implementation, the result saved in the instrument and used to construct new Accumulators throughout its lifetime.

type Conflict

type Conflict struct {
	// Duplicates
	Duplicates []Duplicate
	// Semantic will be a SemanticError if there was an instrument
	// vs. aggregation conflict or nil otherwise.
	Semantic error
}

Conflict describes both the duplicates instruments found and semantic errors caused when registering a new instrument.

func (Conflict) Error

func (c Conflict) Error() string

Error shows the semantic error if non-nil and a summary of the duplicates if any were present.

type Duplicate

type Duplicate interface {
	// Aggregation is the requested aggregation kind.  (If the
	// original aggregation caused a semantic error, this will
	// have been corrected to the default aggregation.)
	Aggregation() aggregation.Kind
	// Descriptor describes the output of the View (Name,
	// Description, Unit, Number Kind, InstrumentKind).
	Descriptor() sdkinstrument.Descriptor
	// Keys is non-nil with the distinct set of keys.  This uses
	// an attribute.Set where the Key is significant and the Value
	// is a meaningless Int(0), for simplicity.
	Keys() *attribute.Set
	// Config is the aggregator configuration.
	Config() aggregator.Config
	// OriginalName is the original name of the Duplicate
	// instrument before renaming.
	OriginalName() string
}

Duplicate is one of the other matching instruments when duplicate instrument registration conflicts arise.

type Instrument

type Instrument interface {
	// NewAccumulator returns an Accumulator and an Updater[N]
	// matching the number type of the API-level instrument.
	//
	// Callers are expected to type-assert Updater[int64] or
	// Updater[float64] before calling Update().
	//
	// The caller's primary responsibility is to maintain
	// the collection of Accumulators that had Update()
	// called since the last collection and to ensure that each
	// of them has SnapshotAndProcess() called.
	NewAccumulator(kvs attribute.Set) Accumulator
}

Instrument is a compiled implementation of an instrument corresponding with one or more instrument-view behaviors.

func Combine

func Combine(desc sdkinstrument.Descriptor, insts ...Instrument) Instrument

Combine accepts a variable number of Instruments to combine. If 0 items, nil is returned. If 1 item, the item itself is return. otherwise, a multiInstrument of the appropriate number kind is returned.

type SemanticError

type SemanticError struct {
	Instrument  sdkinstrument.Kind
	Aggregation aggregation.Kind
}

SemanticError occurs when an instrument is paired with an incompatible aggregation.

func (SemanticError) Error

func (s SemanticError) Error() string

func (SemanticError) Is

func (SemanticError) Is(err error) bool

type Updater

type Updater[N number.Any] interface {
	// Update captures a single measurement.  For synchronous
	// instruments, this passes directly through to the
	// aggregator.  For asynchronous instruments, the last value
	// is captured by the accumulator snapshot.
	Update(value N)
}

Updater captures single measurements, for N an int64 or float64.

type ViewConflictsBuilder

type ViewConflictsBuilder map[string][]Conflict

ViewConflicts represents a per-reader summary of conflicts caused by creating an instrument after applying the view configuration. ViewConflicts may contain either or both of a list of duplicates and a semantic error. Typically these conflicts will be the same for all readers, however since readers influence the defaults for aggregation kind and aggregator configuration, it is possible for different conflicts to arise.

Full information about every conflict or error is always returned to the caller that registered the instrument along with a valid (potentially in-conflict) instrument.

func (*ViewConflictsBuilder) Add

func (vc *ViewConflictsBuilder) Add(name string, c Conflict)

func (*ViewConflictsBuilder) AsError

func (vc *ViewConflictsBuilder) AsError() error

func (*ViewConflictsBuilder) Combine

func (vc *ViewConflictsBuilder) Combine(other ViewConflictsBuilder)

type ViewConflictsError

type ViewConflictsError map[string][]Conflict

func (ViewConflictsError) Error

func (vc ViewConflictsError) Error() string

Error shows one example Conflict with a summary of how many conflicts and readers experienced conflicts, in case of multiple readers and/or conflicts.

func (ViewConflictsError) Is

func (ViewConflictsError) Is(err error) bool

Jump to

Keyboard shortcuts

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