mockitmetrics

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

mockitmetrics

A simple mock implementation for go-kit metrics allowing for easy validation of metrics generating code.

Build Status codecov.io Go Report Card Apache V2 License GitHub Release GoDoc

Summary

A simple library that makes testing if metrics are being recorded when they should easy.

In general it is wise to be cautious of over-validating metrics and logs, but it's also wise to make sure when things get a bit crazy you're covered.

Usage

Documentation

Index

Constants

View Source
const (
	DelimiterDefault = "."
	NoLabelDefault   = "none"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a mock counter.

func NewCounter

func NewCounter(opts ...Option) *Counter

NewCounter creates a new counter with the provided options.

func (*Counter) Add

func (c *Counter) Add(delta float64)

Add adds the provided delta to the counter.

func (*Counter) Value

func (c *Counter) Value() map[string]float64

Value returns the current value of the tree of counters.

func (*Counter) With

func (c *Counter) With(labelValues ...string) kit.Counter

With returns a new counter with the provided label values.

type Gauge

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

Gauge is a mock gauge.

func NewGauge

func NewGauge(opts ...Option) *Gauge

NewGauge creates a new gauge with the provided options.

func (*Gauge) Add

func (g *Gauge) Add(delta float64)

Add adds the provided delta to the gauge.

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set sets the gauge to the provided value.

func (*Gauge) Value

func (g *Gauge) Value() map[string]float64

Value returns the current value of the gauge.

func (*Gauge) With

func (g *Gauge) With(labelValues ...string) kit.Gauge

With returns a new gauge with the provided label values.

type Histogram

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

Histogram is a mock histogram.

func NewHistogram

func NewHistogram(opts ...Option) *Histogram

NewHistogram creates a new histogram with the provided options.

func (*Histogram) Observe

func (h *Histogram) Observe(value float64)

Observe adds the provided value to the histogram.

func (*Histogram) Value

func (h *Histogram) Value() map[string][]float64

Value returns the current value of the histogram.

func (*Histogram) With

func (h *Histogram) With(labelValues ...string) kit.Histogram

With returns a new histogram with the provided label values.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func Delimiter

func Delimiter(d string) Option

Delimiter sets the delimiter used to join labels.

func ExpectLabels

func ExpectLabels(labels ...string) Option

ExpectLabels sets the labels that are expected to be passed to the metric.

The labels aren't validated against, but provide the number of labels that are expected to be passed to the metric.

If the number of labels passed to the metric doesn't match the number of labels passed to ExpectLabels, the call to update the metric will panic.

func PanicFunc

func PanicFunc(f func(any)) Option

PanicFunc sets the function to call when panic() would be called.

Jump to

Keyboard shortcuts

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