Merge pull request #128321 from yongruilin/reset-label-allow-list

feat(metrics): Add method to reset label allow lists
This commit is contained in:
Kubernetes Prow Robot 2024-10-28 23:56:59 +00:00 committed by GitHub
commit 36081ff24f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package metrics
import (
"context"
"sync"
"github.com/blang/semver/v4"
"github.com/prometheus/client_golang/prometheus"
@ -273,6 +274,13 @@ func (v *CounterVec) Reset() {
v.CounterVec.Reset()
}
// ResetLabelAllowLists resets the label allow list for the CounterVec.
// NOTE: This should only be used in test.
func (v *CounterVec) ResetLabelAllowLists() {
v.initializeLabelAllowListsOnce = sync.Once{}
v.LabelValueAllowLists = nil
}
// WithContext returns wrapped CounterVec with context
func (v *CounterVec) WithContext(ctx context.Context) *CounterVecWithContext {
return &CounterVecWithContext{

View File

@ -18,6 +18,7 @@ package metrics
import (
"context"
"sync"
"github.com/blang/semver/v4"
"github.com/prometheus/client_golang/prometheus"
@ -239,6 +240,13 @@ func (v *GaugeVec) Reset() {
v.GaugeVec.Reset()
}
// ResetLabelAllowLists resets the label allow list for the GaugeVec.
// NOTE: This should only be used in test.
func (v *GaugeVec) ResetLabelAllowLists() {
v.initializeLabelAllowListsOnce = sync.Once{}
v.LabelValueAllowLists = nil
}
func newGaugeFunc(opts *GaugeOpts, function func() float64, v semver.Version) GaugeFunc {
g := NewGauge(opts)

View File

@ -18,6 +18,7 @@ package metrics
import (
"context"
"sync"
"github.com/blang/semver/v4"
"github.com/prometheus/client_golang/prometheus"
@ -241,6 +242,13 @@ func (v *HistogramVec) Reset() {
v.HistogramVec.Reset()
}
// ResetLabelAllowLists resets the label allow list for the HistogramVec.
// NOTE: This should only be used in test.
func (v *HistogramVec) ResetLabelAllowLists() {
v.initializeLabelAllowListsOnce = sync.Once{}
v.LabelValueAllowLists = nil
}
// WithContext returns wrapped HistogramVec with context
func (v *HistogramVec) WithContext(ctx context.Context) *HistogramVecWithContext {
return &HistogramVecWithContext{

View File

@ -18,6 +18,7 @@ package metrics
import (
"context"
"sync"
"github.com/blang/semver/v4"
"github.com/prometheus/client_golang/prometheus"
@ -214,6 +215,13 @@ func (v *SummaryVec) Reset() {
v.SummaryVec.Reset()
}
// ResetLabelAllowLists resets the label allow list for the SummaryVec.
// NOTE: This should only be used in test.
func (v *SummaryVec) ResetLabelAllowLists() {
v.initializeLabelAllowListsOnce = sync.Once{}
v.LabelValueAllowLists = nil
}
// WithContext returns wrapped SummaryVec with context
func (v *SummaryVec) WithContext(ctx context.Context) *SummaryVecWithContext {
return &SummaryVecWithContext{

View File

@ -18,6 +18,7 @@ package metrics
import (
"context"
"sync"
"time"
"github.com/blang/semver/v4"
@ -267,6 +268,13 @@ func (v *TimingHistogramVec) Reset() {
v.TimingHistogramVec.Reset()
}
// ResetLabelAllowLists resets the label allow list for the TimingHistogramVec.
// NOTE: This should only be used in test.
func (v *TimingHistogramVec) ResetLabelAllowLists() {
v.initializeLabelAllowListsOnce = sync.Once{}
v.LabelValueAllowLists = nil
}
// WithContext returns wrapped TimingHistogramVec with context
func (v *TimingHistogramVec) InterfaceWithContext(ctx context.Context) GaugeVecMetric {
return &TimingHistogramVecWithContext{