mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rebase: update K8s packages to v0.32.1
Update K8s packages in go.mod to v0.32.1 Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
76
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
76
vendor/k8s.io/component-base/metrics/counter.go
generated
vendored
@ -18,15 +18,19 @@ package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
// Counter is our internal representation for our wrapping struct around prometheus
|
||||
// counters. Counter implements both kubeCollector and CounterMetric.
|
||||
type Counter struct {
|
||||
ctx context.Context
|
||||
CounterMetric
|
||||
*CounterOpts
|
||||
lazyMetric
|
||||
@ -36,6 +40,14 @@ type Counter struct {
|
||||
// The implementation of the Metric interface is expected by testutil.GetCounterMetricValue.
|
||||
var _ Metric = &Counter{}
|
||||
|
||||
// All supported exemplar metric types implement the metricWithExemplar interface.
|
||||
var _ metricWithExemplar = &Counter{}
|
||||
|
||||
// exemplarCounterMetric holds a context to extract exemplar labels from, and a counter metric to attach them to. It implements the metricWithExemplar interface.
|
||||
type exemplarCounterMetric struct {
|
||||
*Counter
|
||||
}
|
||||
|
||||
// NewCounter returns an object which satisfies the kubeCollector and CounterMetric interfaces.
|
||||
// However, the object returned will not measure anything unless the collector is first
|
||||
// registered, since the metric is lazily instantiated.
|
||||
@ -93,11 +105,42 @@ func (c *Counter) initializeDeprecatedMetric() {
|
||||
c.initializeMetric()
|
||||
}
|
||||
|
||||
// WithContext allows the normal Counter metric to pass in context. The context is no-op now.
|
||||
// WithContext allows the normal Counter metric to pass in context.
|
||||
func (c *Counter) WithContext(ctx context.Context) CounterMetric {
|
||||
c.ctx = ctx
|
||||
return c.CounterMetric
|
||||
}
|
||||
|
||||
// withExemplar initializes the exemplarMetric object and sets the exemplar value.
|
||||
func (c *Counter) withExemplar(v float64) {
|
||||
(&exemplarCounterMetric{c}).withExemplar(v)
|
||||
}
|
||||
|
||||
func (c *Counter) Add(v float64) {
|
||||
c.withExemplar(v)
|
||||
}
|
||||
|
||||
func (c *Counter) Inc() {
|
||||
c.withExemplar(1)
|
||||
}
|
||||
|
||||
// withExemplar attaches an exemplar to the metric.
|
||||
func (e *exemplarCounterMetric) withExemplar(v float64) {
|
||||
if m, ok := e.CounterMetric.(prometheus.ExemplarAdder); ok {
|
||||
maybeSpanCtx := trace.SpanContextFromContext(e.ctx)
|
||||
if maybeSpanCtx.IsValid() && maybeSpanCtx.IsSampled() {
|
||||
exemplarLabels := prometheus.Labels{
|
||||
"trace_id": maybeSpanCtx.TraceID().String(),
|
||||
"span_id": maybeSpanCtx.SpanID().String(),
|
||||
}
|
||||
m.AddWithExemplar(v, exemplarLabels)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
e.CounterMetric.Add(v)
|
||||
}
|
||||
|
||||
// CounterVec is the internal representation of our wrapping struct around prometheus
|
||||
// counterVecs. CounterVec implements both kubeCollector and CounterVecMetric.
|
||||
type CounterVec struct {
|
||||
@ -119,11 +162,6 @@ func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
fqName := BuildFQName(opts.Namespace, opts.Subsystem, opts.Name)
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[fqName]; ok {
|
||||
opts.LabelValueAllowLists = allowList
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
|
||||
cv := &CounterVec{
|
||||
CounterVec: noopCounterVec,
|
||||
@ -176,7 +214,17 @@ func (v *CounterVec) WithLabelValues(lvs ...string) CounterMetric {
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
} else {
|
||||
v.initializeLabelAllowListsOnce.Do(func() {
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[v.FQName()]; ok {
|
||||
v.LabelValueAllowLists = allowList
|
||||
allowList.ConstrainToAllowedList(v.originalLabels, lvs)
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
})
|
||||
}
|
||||
|
||||
return v.CounterVec.WithLabelValues(lvs...)
|
||||
}
|
||||
|
||||
@ -190,6 +238,15 @@ func (v *CounterVec) With(labels map[string]string) CounterMetric {
|
||||
}
|
||||
if v.LabelValueAllowLists != nil {
|
||||
v.LabelValueAllowLists.ConstrainLabelMap(labels)
|
||||
} else {
|
||||
v.initializeLabelAllowListsOnce.Do(func() {
|
||||
allowListLock.RLock()
|
||||
if allowList, ok := labelValueAllowLists[v.FQName()]; ok {
|
||||
v.LabelValueAllowLists = allowList
|
||||
allowList.ConstrainLabelMap(labels)
|
||||
}
|
||||
allowListLock.RUnlock()
|
||||
})
|
||||
}
|
||||
return v.CounterVec.With(labels)
|
||||
}
|
||||
@ -217,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{
|
||||
|
Reference in New Issue
Block a user