Documentation
¶
Overview ¶
Package metrictest is a small metric testing library for the Prometheus Go client https://github.com/prometheus/client_golang. See documentation for each Assert function for usage details.
Index ¶
- func AssertCounter(t TestingT, expected float64, counter prometheus.Counter)
- func AssertCounterVec(t TestingT, expected float64, counterVec *prometheus.CounterVec, ...)
- func AssertGauge(t TestingT, expected float64, gauge prometheus.Gauge)
- func AssertGaugeVec(t TestingT, expected float64, gaugeVec *prometheus.GaugeVec, labels ...string)
- func AssertHistogramSamples(t TestingT, count int, sum float64, histogram prometheus.Histogram)
- func AssertHistogramVecSamples(t TestingT, count int, sum float64, histogramVec *prometheus.HistogramVec, ...)
- func AssertSummarySamples(t TestingT, count int, sum float64, summary prometheus.Histogram)
- func AssertSummaryVecSamples(t TestingT, count int, sum float64, summaryVec *prometheus.SummaryVec, ...)
- func ToExpVar(c prometheus.Collector) (string, error)
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCounter ¶
func AssertCounter(t TestingT, expected float64, counter prometheus.Counter)
AssertCounter asserts the value of a prometheus.Counter
counter.Add(10) metrictest.AssertCounter(t, 10, counter)
func AssertCounterVec ¶
func AssertCounterVec(t TestingT, expected float64, counterVec *prometheus.CounterVec, labels ...string)
AssertCounterVec asserts the value of a single counter in a prometheus.CounterVec
counterVec.WithLabelValues("a-label", "another-label").Inc(10)
metrictest.AssertCounterVec(t, 10, counterVec, "a-label", "another-label")
Asserting that the value of a counter is 0 is equivalent to asserting that the counter does not exist.
func AssertGauge ¶
func AssertGauge(t TestingT, expected float64, gauge prometheus.Gauge)
AssertGauge asserts the value of a prometheus.Gauge
gauge.Set(10) metrictest.AssertGauge(t, 10, gauge)
func AssertGaugeVec ¶
func AssertGaugeVec(t TestingT, expected float64, gaugeVec *prometheus.GaugeVec, labels ...string)
AssertGaugeVec asserts the value of a single gauge in a prometheus.GaugeVec
gaugeVec.WithLabelValues("a-label", "another-label").Set(10)
metrictest.AssertGaugeVec(t, 10, gaugeVec, "a-label", "another-label")
Asserting that the value of a gauge is 0 is equivalent to asserting that the gauge does not exist.
func AssertHistogramSamples ¶
func AssertHistogramSamples(t TestingT, count int, sum float64, histogram prometheus.Histogram)
AssertHistogramSamples asserts the count and sum of all samples captured by the prometheus.Histogram
histogram.Observe(10) histogram.Observe(20) metrictest.AssertHistogramSamples(t, 2, 30, histogram)
func AssertHistogramVecSamples ¶
func AssertHistogramVecSamples(t TestingT, count int, sum float64, histogramVec *prometheus.HistogramVec, labels ...string)
AssertHistogramVecSamples asserts the count and sum of all samples captured by a single histogram contained by the prometheus.HistogramVec
histogramVec.WithLabelValues("a-label", "another-label").Observe(10)
histogramVec.WithLabelValues("a-label", "another-label").Observe(20)
metrictest.AssertHistogramSamples(t, 2, 30, histogram, "a-label", "another-label")
func AssertSummarySamples ¶
func AssertSummarySamples(t TestingT, count int, sum float64, summary prometheus.Histogram)
AssertSummarySamples asserts the count and sum of all samples captured by the prometheus.Summary
summary.Observe(10) summary.Observe(20) metrictest.AssertSummarySamples(t, 2, 30, summary)
func AssertSummaryVecSamples ¶
func AssertSummaryVecSamples(t TestingT, count int, sum float64, summaryVec *prometheus.SummaryVec, labels ...string)
AssertSummaryVecSamples asserts the count and sum of all samples captured by a single summary contained by the prometheus.SummaryVec
summaryVec.WithLabelValues("a-label", "another-label").Observe(10)
summaryVec.WithLabelValues("a-label", "another-label").Observe(20)
metrictest.AssertSummarySamples(t, 2, 30, summary, "a-label", "another-label")