From 15884a5fd07bb52976d00dd1f88ddcb9622bd893 Mon Sep 17 00:00:00 2001 From: yongruilin Date: Wed, 30 Oct 2024 09:28:24 -0700 Subject: [PATCH] feat: Add function to reset label allow list for apiserver endpoints metrics Kubernetes-commit: d3795eaf76e5ecc632325cfb598533c4e3c31704 --- pkg/endpoints/metrics/metrics.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/endpoints/metrics/metrics.go b/pkg/endpoints/metrics/metrics.go index 48fc951ad..0c7a3f6b9 100644 --- a/pkg/endpoints/metrics/metrics.go +++ b/pkg/endpoints/metrics/metrics.go @@ -416,6 +416,33 @@ func Reset() { } } +// ResetLabelAllowLists resets the label allow lists for all metrics. +// NOTE: This is only used for testing. +func ResetLabelAllowLists() { + for _, metric := range metrics { + if counterVec, ok := metric.(*compbasemetrics.CounterVec); ok { + counterVec.ResetLabelAllowLists() + continue + } + if gaugeVec, ok := metric.(*compbasemetrics.GaugeVec); ok { + gaugeVec.ResetLabelAllowLists() + continue + } + if histogramVec, ok := metric.(*compbasemetrics.HistogramVec); ok { + histogramVec.ResetLabelAllowLists() + continue + } + if summaryVec, ok := metric.(*compbasemetrics.SummaryVec); ok { + summaryVec.ResetLabelAllowLists() + continue + } + if timingHistogramVec, ok := metric.(*compbasemetrics.TimingHistogramVec); ok { + timingHistogramVec.ResetLabelAllowLists() + continue + } + } +} + // UpdateInflightRequestMetrics reports concurrency metrics classified by // mutating vs Readonly. func UpdateInflightRequestMetrics(phase string, nonmutating, mutating int) {