component-base metrics: allow usage of Prometheus types in tests

Test code using the testutil.Metrics type already depended on the Prometheus
types, but couldn't reference them by name. This is necessary for example when
using Gomega (to cast from `any` in a matcher) or when defining a `var
sample *Sample` which gets set later.
This commit is contained in:
Patrick Ohly
2025-05-19 08:30:08 +02:00
parent dcefe0ef41
commit 75432a1410

View File

@@ -38,8 +38,20 @@ var (
QuantileLabel model.LabelName = model.QuantileLabel
)
// Metrics is generic metrics for other specific metrics
type Metrics map[string]model.Samples
// Metrics is generic metrics for other specific metrics.
// This directly exposes Prometheus types. Test code may
// use those via type aliases provided by this package
// instead of imorting the Prometheus packages (https://github.com/kubernetes/kubernetes/issues/89267).
type Metrics map[string]Samples
type Samples = model.Samples
type Sample = model.Sample
type Metric = model.Metric
type LabelValue = model.LabelValue
type LabelName = model.LabelName
type SampleHistogram = model.SampleHistogram
type FloatString = model.FloatString
type HistogramBuckets = model.HistogramBuckets
type HistogramBucket = model.HistogramBucket
// Equal returns true if all metrics are the same as the arguments.
func (m *Metrics) Equal(o Metrics) bool {