xmetricstest

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Counter

func Counter(t testingT, n string, m interface{}) bool

Counter is an expectation that a certain metric is a counter. It must implement the go-kit metrics.Counter interface.

func Gauge

func Gauge(t testingT, n string, m interface{}) bool

Gauge is an expectation that a certain metric is a gauge. It must implement the go-kit metrics.Gauge interface.

func Histogram

func Histogram(t testingT, n string, m interface{}) bool

Histogram is an expectation that a certain metric is a histogram. It must implement the go-kit metrics.Histogram interface.

func Minimum

func Minimum(expected float64) expectation

Minimum returns an expectation for a metric to be at least a certain value. The metric in question must implement xmetrics.Valuer, as with the Value expectation.

func NewCounter

func NewCounter(name string) metrics.Counter

func NewGauge

func NewGauge(name string) metrics.Gauge

func NewHistogram

func NewHistogram(name string, buckets int) metrics.Histogram

func NewMetric

func NewMetric(m xmetrics.Metric) (interface{}, error)

NewMetric creates the appropriate go-kit metrics/generic metric from the supplied descriptor. Both summaries and histograms result in *generic.Histogram instances. If the returned error is nil, the returned metric will always be one of the metrics/generic types.

Only the metric Name is used. Namespace and subsystem are not applied by this factory function.

func Value

func Value(expected float64) expectation

Value returns an expectation for a metric to be of a certain value. The metric in question must implement xmetrics.Valuer, which both counter and gauge do. This assertion does not constrain the type of metric beyond simply exposing a value. Use another expectation to assert that a metric is of a more specific type.

Types

type LVKey

type LVKey string

LVKey represents a canonicalized key for a set of label/value pairs.

func NewLVKey

func NewLVKey(labelsAndValues []string) (LVKey, error)

NewLVKey produces a consistent, unique key for a set of label/value pairs. For example, {"code", "200", "method", "POST"} will result in the same key as {"method", "POST", "code", "200"}.

func (LVKey) Root

func (lvk LVKey) Root() bool

type Labeled

type Labeled interface {
	// Get returns the nested metric associated with a set of label/value pairs, creating one if no such metric exists.
	// If the given key represents the root key, this same instance is returned.
	Get(LVKey) interface{}
}

Labeled provides access to a metric's labeled "children".

type Provider

type Provider interface {
	provider.Provider

	// Expect associates an expectation with a metric.  The optional list of labels and values will
	// examine any nested metric instead of the root metric.  This method uses a Fluent Builder style:
	//
	//    provider.Expect("counter")(xmetricstest.Counter, xmetricstest.Value(1.0)).
	//        Expect("not_found", "code", "404")(xmetricstest.Counter)
	//
	// The returned closure is used to attach expectations to the metric identified by the name and
	// optional label/value pairs.
	Expect(string, ...string) func(...expectation) Provider

	// Assert executes an assertion against this provider immediately, without adding it to the
	// set of expectations asserted via AssertExpectations.
	Assert(testingT, string, ...string) func(...expectation) bool

	// AssertExpectations verifies all expectations.  It returns true if and only if all
	// expectations pass or if there were no expectations set.
	AssertExpectations(testingT) bool
}

Provider is a testing implementation of go-kit's provider.Provider. Additionally, it provides assertion and expectation functionality.

func NewProvider

func NewProvider(o *xmetrics.Options, m ...xmetrics.Module) Provider

NewProvider returns a testing Provider instance, using a similar merging algorithm as used by xmetrics.NewRegistry. Namespace and subsystem are not used to determine metric uniqueness, which is normally fine since an application tends to use one pair of (namespace, subsystem) for all its metrics.

The returned object may be used as a go-kit provider.Provider for testing application code. Additionally, it may also be used to set expectations and do assertions on the recorded metrics. At this time, label values *are not supported*.

If this function is unable to merge configuration into a Provider, it panics. The Provider will be usable if no options or modules are passed. Passing configuration is only necessary if the actual production configuration is being tested.

Jump to

Keyboard shortcuts

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