metrictest

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LabelsToMap

func LabelsToMap(kvs ...attribute.KeyValue) map[attribute.Key]attribute.Value

LabelsToMap converts label set to keyValue map, to be easily used in tests

func NewDescriptor added in v0.24.0

func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, opts ...metric.InstrumentOption) sdkapi.Descriptor

NewDescriptor is a test helper for constructing test metric descriptors using standard options.

func ResolveNumberByKind

func ResolveNumberByKind(t *testing.T, kind number.Kind, value float64) number.Number

ResolveNumberByKind takes defined metric descriptor creates a concrete typed metric number

Types

type Async

type Async struct {
	Instrument
	// contains filtered or unexported fields
}

func (*Async) Implementation

func (a *Async) Implementation() interface{}

type Batch

type Batch struct {
	// Measurement needs to be aligned for 64-bit atomic operations.
	Measurements []Measurement
	Ctx          context.Context
	Labels       []attribute.KeyValue
	Library      Library
}

type Handle

type Handle struct {
	Instrument *Sync
	Labels     []attribute.KeyValue
}

func (*Handle) RecordOne

func (h *Handle) RecordOne(ctx context.Context, number number.Number)

func (*Handle) Unbind

func (h *Handle) Unbind()

type Instrument

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

func (Instrument) Descriptor

func (i Instrument) Descriptor() sdkapi.Descriptor

type Library added in v0.24.0

type Library struct {
	InstrumentationName    string
	InstrumentationVersion string
	SchemaURL              string
}

Library is the same as "sdk/instrumentation".Library but there is a package cycle to use it.

type Measured

type Measured struct {
	Name    string
	Labels  map[attribute.Key]attribute.Value
	Number  number.Number
	Library Library
}

Measured is the helper struct which provides flat representation of recorded measurements to simplify testing

func AsStructs

func AsStructs(batches []Batch) []Measured

AsStructs converts recorded batches to array of flat, readable Measured helper structures

type Measurement

type Measurement struct {
	// Number needs to be aligned for 64-bit atomic operations.
	Number     number.Number
	Instrument sdkapi.InstrumentImpl
}

type MeterImpl

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

MeterImpl is an OpenTelemetry Meter implementation used for testing.

func (*MeterImpl) CollectAsync

func (m *MeterImpl) CollectAsync(labels []attribute.KeyValue, obs ...sdkapi.Observation)

CollectAsync is called from asyncInstruments.Run() with the lock held.

func (*MeterImpl) NewAsyncInstrument

func (m *MeterImpl) NewAsyncInstrument(descriptor sdkapi.Descriptor, runner sdkapi.AsyncRunner) (sdkapi.AsyncImpl, error)

NewAsyncInstrument implements sdkapi.MeterImpl.

func (*MeterImpl) NewSyncInstrument

func (m *MeterImpl) NewSyncInstrument(descriptor sdkapi.Descriptor) (sdkapi.SyncImpl, error)

NewSyncInstrument implements sdkapi.MeterImpl.

func (*MeterImpl) RecordBatch

func (m *MeterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurements ...sdkapi.Measurement)

RecordBatch implements sdkapi.MeterImpl.

type MeterProvider added in v0.24.0

type MeterProvider struct {
	MeasurementBatches []Batch
	// contains filtered or unexported fields
}

MeterProvider is a collection of named MeterImpls used for testing.

func NewMeterProvider

func NewMeterProvider() *MeterProvider

NewMeterProvider returns a MeterProvider suitable for testing. When the test is complete, consult MeterProvider.MeasurementBatches.

func (*MeterProvider) Meter added in v0.24.0

func (p *MeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter

Meter implements metric.MeterProvider.

func (*MeterProvider) RunAsyncInstruments added in v0.24.0

func (p *MeterProvider) RunAsyncInstruments()

RunAsyncInstruments is used in tests to trigger collection from asynchronous instruments.

type Sync

type Sync struct {
	Instrument
}

func (*Sync) Implementation

func (s *Sync) Implementation() interface{}

func (*Sync) RecordOne

func (s *Sync) RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue)

Jump to

Keyboard shortcuts

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