kubernetes: k8s.io/kubernetes/staging/src/k8s.io/component-base/metrics/testutil Index | Files

package testutil

import "k8s.io/kubernetes/staging/src/k8s.io/component-base/metrics/testutil"


Package Files

metrics.go promlint.go testutil.go


var (
    // MetricNameLabel is label under which model.Sample stores metric name
    MetricNameLabel model.LabelName = model.MetricNameLabel
    // QuantileLabel is label under which model.Sample stores latency quantile value
    QuantileLabel model.LabelName = model.QuantileLabel

func CollectAndCompare Uses

func CollectAndCompare(c metrics.Collector, expected io.Reader, metricNames ...string) error

CollectAndCompare registers the provided Collector with a newly created pedantic Registry. It then does the same as GatherAndCompare, gathering the metrics from the pedantic Registry.

func ComputeHistogramDelta Uses

func ComputeHistogramDelta(before, after model.Samples, label model.LabelName)

ComputeHistogramDelta computes the change in histogram metric for a selected label. Results are stored in after samples

func CustomCollectAndCompare Uses

func CustomCollectAndCompare(c metrics.StableCollector, expected io.Reader, metricNames ...string) error

CustomCollectAndCompare registers the provided StableCollector with a newly created registry. It then does the same as GatherAndCompare, gathering the metrics from the pedantic Registry.

func GatherAndCompare Uses

func GatherAndCompare(g metrics.Gatherer, expected io.Reader, metricNames ...string) error

GatherAndCompare gathers all metrics from the provided Gatherer and compares it to an expected output read from the provided Reader in the Prometheus text exposition format. If any metricNames are provided, only metrics with those names are compared.

func GetCounterMetricValue Uses

func GetCounterMetricValue(m metrics.CounterMetric) (float64, error)

GetCounterMetricValue extract metric value from CounterMetric

func GetGaugeMetricValue Uses

func GetGaugeMetricValue(m metrics.GaugeMetric) (float64, error)

GetGaugeMetricValue extract metric value from GaugeMetric

func GetHistogramMetricValue Uses

func GetHistogramMetricValue(m metrics.ObserverMetric) (float64, error)

GetHistogramMetricValue extract sum of all samples from ObserverMetric

func GetMetricValuesForLabel Uses

func GetMetricValuesForLabel(ms Metrics, metricName, label string) map[string]int64

GetMetricValuesForLabel returns value of metric for a given dimension

func LabelsMatch Uses

func LabelsMatch(metric *dto.Metric, labelFilter map[string]string) bool

LabelsMatch returns true if metric has all expected labels otherwise false

func NewFakeKubeRegistry Uses

func NewFakeKubeRegistry(ver string) metrics.KubeRegistry

NewFakeKubeRegistry creates a fake `KubeRegistry` that takes the input version as `build in version`. It should only be used in testing scenario especially for the deprecated metrics. The input version format should be `major.minor.patch`, e.g. '1.18.0'.

func ParseMetrics Uses

func ParseMetrics(data string, output *Metrics) error

ParseMetrics parses Metrics from data returned from prometheus endpoint

func PrintSample Uses

func PrintSample(sample *model.Sample) string

PrintSample returns formatted representation of metric Sample

func TextToMetricFamilies Uses

func TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricFamily, error)

TextToMetricFamilies reads 'in' as the simple and flat text-based exchange format and creates MetricFamily proto messages. It returns the MetricFamily proto messages in a map where the metric names are the keys, along with any error encountered.

func ValidateMetrics Uses

func ValidateMetrics(metrics Metrics, metricName string, expectedLabels ...string) error

ValidateMetrics verifies if every sample of metric has all expected labels

type Histogram Uses

type Histogram struct {

Histogram wraps prometheus histogram DTO (data transfer object)

func GetHistogramFromGatherer Uses

func GetHistogramFromGatherer(gatherer metrics.Gatherer, metricName string) (Histogram, error)

GetHistogramFromGatherer collects a metric from a gatherer implementing k8s.io/component-base/metrics.Gatherer interface. Used only for testing purposes where we need to gather metrics directly from a running binary (without metrics endpoint).

func (*Histogram) Average Uses

func (hist *Histogram) Average() float64

Average computes histogram's average value

func (*Histogram) Clear Uses

func (hist *Histogram) Clear()

Clear clears all fields of the wrapped histogram

func (*Histogram) Quantile Uses

func (hist *Histogram) Quantile(q float64) float64

Quantile computes q-th quantile of a cumulative histogram. It's expected the histogram is valid (by calling Validate)

func (*Histogram) Validate Uses

func (hist *Histogram) Validate() error

Validate makes sure the wrapped histogram has all necessary fields set and with valid values.

type Linter Uses

type Linter struct {
    // contains filtered or unexported fields

A Linter is a Prometheus metrics linter. It identifies issues with metric names, types, and metadata, and reports them to the caller.

func NewPromLinter Uses

func NewPromLinter(r io.Reader) *Linter

NewPromLinter creates a new Linter that reads an input stream of Prometheus metrics. Only the text exposition format is supported.

func (*Linter) Lint Uses

func (l *Linter) Lint() ([]Problem, error)

Lint performs a linting pass, returning a slice of Problems indicating any issues found in the metrics stream. The slice is sorted by metric name and issue description.

type Metrics Uses

type Metrics map[string]model.Samples

Metrics is generic metrics for other specific metrics

func NewMetrics Uses

func NewMetrics() Metrics

NewMetrics returns new metrics which are initialized.

func (*Metrics) Equal Uses

func (m *Metrics) Equal(o Metrics) bool

Equal returns true if all metrics are the same as the arguments.

type Problem Uses

type Problem promlint.Problem

A Problem is an issue detected by a Linter.

func (*Problem) String Uses

func (p *Problem) String() string

Package testutil imports 13 packages (graph). Updated 2020-12-10. Refresh now. Tools for package owners.