...

Package prommatch

import "github.com/linkerd/linkerd2/testutil/prommatch"
Overview
Index

Overview ▾

Package prommatch provides means of checking whether a prometheus metrics contain a specific series.

It tries to give a similar look and feel as time series in PromQL. So where in PromQL one would write this:

request_total{direction="outbound", target_port=~"8\d\d\d"} 30

In prommatch, one can write this:

portRE := regex.MustCompile(`^8\d\d\d$`)
prommatch.NewMatcher("request_total", prommatch.Labels{
	"direction": prommatch.Equals("outbound"),
	"target_port": prommatch.Like(portRE),
})

type Expression

Expression can match or reject one time series.

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

func HasPositiveValue

func HasPositiveValue() Expression

HasPositiveValue is used to select time series with a positive value.

func HasValueLike

func HasValueLike(f func(float64) bool) Expression

HasValueLike is used for selecting time series based on value.

func HasValueOf

func HasValueOf(f float64) Expression

HasValueOf is used for selecting time series based on a specific value.

type LabelMatcher

LabelMatcher can match or reject a label's value.

type LabelMatcher func(string) bool

func Absent

func Absent() LabelMatcher

Absent is when you want to match series MISSING a specific label.

func Any

func Any() LabelMatcher

Any is when you want to select a series which has a certain label, but don't care about the value.

func Equals

func Equals(expected string) LabelMatcher

Equals is when you want label value to have an exact value.

func IsAddr

func IsAddr() LabelMatcher

IsAddr is used to check if the value is an IP:port combo, where IP can be an IPv4 or an IPv6

func IsIP

func IsIP() LabelMatcher

IsIP use used to check if the value is an IPv4 or IPv6

func Like

func Like(re *regexp.Regexp) LabelMatcher

Like is when you want label value to match a regular expression.

type Labels

Labels is used for selecting series with matching labels.

type Labels map[string]LabelMatcher

func TargetAddrLabels

func TargetAddrLabels() Labels

TargetAddrLabels match series with proper target_addr, target_port, and target_ip.

type Matcher

Matcher contains a list of expressions, which will be checked against each series.

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

func NewMatcher

func NewMatcher(name string, ms ...Expression) *Matcher

NewMatcher will match series name (exactly) and all the additional matchers.

func (*Matcher) HasMatchInString

func (e *Matcher) HasMatchInString(s string) (bool, error)

HasMatchInString will return: - true, if the provided metrics have a series which matches all expressions, - false, if none of the series matches, - error, if the provided string is not valid Prometheus metrics,

type Suite

Suite is a list of matchers and messages to check against a string of metrics.

type Suite []matcherAndMessage

func (Suite) CheckString

func (ms Suite) CheckString(metrics string) error

CheckString will run each assertion in the suite against the provided metrics.

func (Suite) MustContain

func (ms Suite) MustContain(message string, m *Matcher) Suite

MustContain a series which will match the provided matcher.

func (Suite) MustNotContain

func (ms Suite) MustNotContain(message string, m *Matcher) Suite

MustNotContain a series which will match the provided matcher.