From 75432a14108455f87c65aaac63509d354c25655e Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 19 May 2025 08:30:08 +0200 Subject: [PATCH] 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. --- .../component-base/metrics/testutil/metrics.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go index 05d15b08d75..e1ed9243809 100644 --- a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go +++ b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go @@ -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 {