otel: go.opentelemetry.io/otel/sdk/metric/processor/processortest Index | Files

package processortest

import "go.opentelemetry.io/otel/sdk/metric/processor/processortest"

Index

Package Files

test.go

func AggregatorSelector Uses

func AggregatorSelector() export.AggregatorSelector

AggregatorSelector returns a policy that is consistent with the test descriptors above. I.e., it returns sum.New() for counter instruments and lastvalue.New() for lastValue instruments.

func Checkpointer Uses

func Checkpointer(p *Processor) export.Checkpointer

Checkpointer returns a checkpointer that computes a single interval.

type Exporter Uses

type Exporter struct {
    export.ExportKindSelector

    // InjectErr supports returning conditional errors from
    // the Export() routine.  This must be set before the
    // Exporter is first used.
    InjectErr func(export.Record) error
    // contains filtered or unexported fields
}

Exporter is a testing implementation of export.Exporter that assembles its results as a map[string]float64.

func NewExporter Uses

func NewExporter(selector export.ExportKindSelector, encoder label.Encoder) *Exporter

NewExporter returns a new testing Exporter implementation. Verify exporter outputs using Values(), e.g.,:

require.EqualValues(t, map[string]float64{
    "counter.sum/A=1,B=2/R=V": 100,
}, exporter.Values())

Where in the example A=1,B=2 is the encoded labels and R=V is the encoded resource value.

func (*Exporter) Export Uses

func (e *Exporter) Export(_ context.Context, ckpt export.CheckpointSet) error

func (*Exporter) ExportCount Uses

func (e *Exporter) ExportCount() int

ExportCount returns the number of times Export() has been called since the last Reset().

func (*Exporter) Reset Uses

func (e *Exporter) Reset()

Reset sets the exporter's output to the initial, empty state and resets the export count to zero.

func (*Exporter) Values Uses

func (e *Exporter) Values() map[string]float64

Values returns the mapping from label set to point values for the accumulations that were processed. Point values are chosen as either the Sum or the LastValue, whichever is implemented. (All the built-in Aggregators implement one of these interfaces.)

type Output Uses

type Output struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

Output implements export.CheckpointSet.

func NewOutput Uses

func NewOutput(labelEncoder label.Encoder) *Output

NewOutput is a helper for testing an expected set of Accumulations (from an Accumulator) or an expected set of Records (from a Processor). If testing with an Accumulator, it may be simpler to use the test Processor in this package.

func (*Output) AddAccumulation Uses

func (o *Output) AddAccumulation(acc export.Accumulation) error

AddAccumulation adds a string representation of the exported metric data to a map for use in testing. The value taken from the accumulation is either the Sum() or the LastValue() of its Aggregator().Aggregation(), whichever is defined.

func (*Output) AddRecord Uses

func (o *Output) AddRecord(rec export.Record) error

AddRecord adds a string representation of the exported metric data to a map for use in testing. The value taken from the record is either the Sum() or the LastValue() of its Aggregation(), whichever is defined. Record timestamps are ignored.

func (*Output) ForEach Uses

func (o *Output) ForEach(_ export.ExportKindSelector, ff func(export.Record) error) error

ForEach implements export.CheckpointSet.

func (*Output) Map Uses

func (o *Output) Map() map[string]float64

Map returns the calculated values for test validation from a set of Accumulations or a set of Records. When mapping records or accumulations into floating point values, the Sum() or LastValue() is chosen, whichever is implemented by the underlying Aggregator.

func (*Output) Reset Uses

func (o *Output) Reset()

Reset restores the Output to its initial state, with no accumulated metric data.

type Processor Uses

type Processor struct {
    export.AggregatorSelector
    // contains filtered or unexported fields
}

Processor is a testing implementation of export.Processor that assembles its results as a map[string]float64.

func NewProcessor Uses

func NewProcessor(selector export.AggregatorSelector, encoder label.Encoder) *Processor

NewProcessor returns a new testing Processor implementation. Verify expected outputs using Values(), e.g.:

require.EqualValues(t, map[string]float64{
    "counter.sum/A=1,B=2/R=V": 100,
}, processor.Values())

Where in the example A=1,B=2 is the encoded labels and R=V is the encoded resource value.

func (*Processor) Process Uses

func (p *Processor) Process(accum export.Accumulation) error

Process implements export.Processor.

func (*Processor) Values Uses

func (p *Processor) Values() map[string]float64

Values returns the mapping from label set to point values for the accumulations that were processed. Point values are chosen as either the Sum or the LastValue, whichever is implemented. (All the built-in Aggregators implement one of these interfaces.)

Package processortest imports 16 packages (graph). Updated 2020-10-20. Refresh now. Tools for package owners.