Repository: kubernetes/kubernetes
File: staging/src/k8s.io/component-base/metrics/testutil/metrics.go (Go)

Code before:
	"reflect"
	"sort"
	"strings"

	dto "github.com/prometheus/client_model/go"
	"github.com/prometheus/common/expfmt"
	"github.com/prometheus/common/model"

	"k8s.io/component-base/metrics"
)

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
)

// 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 SampleTime = model.Time
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 {
	var leftKeySet []string
	var rightKeySet []string
	for k := range *m {
		leftKeySet = append(leftKeySet, k)
	}
	for k := range o {
		rightKeySet = append(rightKeySet, k)
	}
	if !reflect.DeepEqual(leftKeySet, rightKeySet) {
		return false
	}
	for _, k := range leftKeySet {
		if !(*m)[k].Equal(o[k]) {
			return false
		}

Review comment (suggestion):
To keep the same semantic, I think it would be better to just call it `Time`

Code after:
	"reflect"
	"sort"
	"strings"

	dto "github.com/prometheus/client_model/go"
	"github.com/prometheus/common/expfmt"
	"github.com/prometheus/common/model"

	"k8s.io/component-base/metrics"
)

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
)

// 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 Time = model.Time
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 {
	var leftKeySet []string
	var rightKeySet []string
	for k := range *m {
		leftKeySet = append(leftKeySet, k)
	}
	for k := range o {
		rightKeySet = append(rightKeySet, k)
	}
	if !reflect.DeepEqual(leftKeySet, rightKeySet) {
		return false
	}
	for _, k := range leftKeySet {
		if !(*m)[k].Equal(o[k]) {
			return false
		}