Documentation ¶
Overview ¶
Package tools provides utilities for writing tests for code that produces Prometheus metrics.
MetricName, MetricLabel and MetricValue provide an easy way to validate metrics during unit testing:
func TestMetrics(t *testing.T) { ... ch := make(chan prometheus.Metric) go yourMetric.Collect(ch) m := <-ch assert.Equal(t, "foo_bar_gauge", metrics.MetricName(m)) assert.Equal(t, 1.0, metrics.MetricValue(m).GetGauge().GetValue()) assert.Equal(t, "valueA", metrics.MetricLabel(m, "labelA")) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MetricLabel ¶
func MetricLabel(metric prometheus.Metric, labelName string) (value string)
MetricLabel returns the value of a metric's label. Panics if metric is not a valid Prometheus metric.
func MetricName ¶
func MetricName(metric prometheus.Metric) (name string)
MetricName returns the name of the provided Prometheus metric.
func MetricValue ¶
func MetricValue(metric prometheus.Metric) *pcg.Metric
MetricValue converts a Prometheus metric to a prometheus/client_model/go metric, so the caller can read its value:
ch := make(chan prometheus.Metric) go c.Collect(ch) m := <-ch metric := metrics.MetricValue(m) assert.Equal(t, 1.0, metric.GetGauge().GetValue())
Panics if metric is not a valid Prometheus metric.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.