promtest

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package promtest provides helpers for parsing and extracting prometheus metrics. These functions are only intended to be called from test files, as there is a dependency on the standard library testing package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMetric

func FindMetric(mfs []*dto.MetricFamily, name string, labels map[string]string) *dto.Metric

FindMetric iterates through mfs to find the first metric family matching name. If a metric family matches, then the metrics inside the family are searched, and the first metric whose labels match the given labels are returned. If no matches are found, FindMetric returns nil.

FindMetric assumes that the labels on the metric family are well formed, i.e. there are no duplicate label names, and the label values are not empty strings.

func FromHTTPResponse

func FromHTTPResponse(r *http.Response) ([]*dto.MetricFamily, error)

FromHTTPResponse parses the prometheus metrics from the given *http.Response. It relies on properly set response headers to correctly parse. It will unconditionally close the response body.

This is particularly helpful when testing the output of the /metrics endpoint of a service. However, for comprehensive testing of metrics, it usually makes more sense to add collectors to a registry and call Registry.Gather to get the metrics without involving HTTP.

func MustFindMetric

func MustFindMetric(tb testing.TB, mfs []*dto.MetricFamily, name string, labels map[string]string) *dto.Metric

MustFindMetric returns the matching metric, or if no matching metric could be found, it calls tb.Log with helpful output of what was actually available, before calling tb.FailNow.

func MustGather

func MustGather(tb testing.TB, g prometheus.Gatherer) []*dto.MetricFamily

MustGather calls g.Gather and calls tb.Fatal if there was an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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