49
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
49
vendor/k8s.io/component-base/metrics/gauge.go
generated
vendored
@@ -19,6 +19,8 @@ package metrics
|
||||
import (
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
// Gauge is our internal representation for our wrapping struct around prometheus
|
||||
@@ -34,10 +36,8 @@ type Gauge struct {
|
||||
// However, the object returned will not measure anything unless the collector is first
|
||||
// registered, since the metric is lazily instantiated.
|
||||
func NewGauge(opts *GaugeOpts) *Gauge {
|
||||
// todo: handle defaulting better
|
||||
if opts.StabilityLevel == "" {
|
||||
opts.StabilityLevel = ALPHA
|
||||
}
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
kc := &Gauge{
|
||||
GaugeOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
@@ -86,10 +86,8 @@ type GaugeVec struct {
|
||||
// However, the object returned will not measure anything unless the collector is first
|
||||
// registered, since the metric is lazily instantiated.
|
||||
func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
|
||||
// todo: handle defaulting better
|
||||
if opts.StabilityLevel == "" {
|
||||
opts.StabilityLevel = ALPHA
|
||||
}
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
cv := &GaugeVec{
|
||||
GaugeVec: noopGaugeVec,
|
||||
GaugeOpts: opts,
|
||||
@@ -142,7 +140,7 @@ func (v *GaugeVec) WithLabelValues(lvs ...string) GaugeMetric {
|
||||
// must match those of the VariableLabels in Desc). If that label map is
|
||||
// accessed for the first time, a new GaugeMetric is created IFF the gaugeVec has
|
||||
// been registered to a metrics registry.
|
||||
func (v *GaugeVec) With(labels prometheus.Labels) GaugeMetric {
|
||||
func (v *GaugeVec) With(labels map[string]string) GaugeMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop // return no-op gauge
|
||||
}
|
||||
@@ -156,9 +154,40 @@ func (v *GaugeVec) With(labels prometheus.Labels) GaugeMetric {
|
||||
// with those of the VariableLabels in Desc. However, such inconsistent Labels
|
||||
// can never match an actual metric, so the method will always return false in
|
||||
// that case.
|
||||
func (v *GaugeVec) Delete(labels prometheus.Labels) bool {
|
||||
func (v *GaugeVec) Delete(labels map[string]string) bool {
|
||||
if !v.IsCreated() {
|
||||
return false // since we haven't created the metric, we haven't deleted a metric with the passed in values
|
||||
}
|
||||
return v.GaugeVec.Delete(labels)
|
||||
}
|
||||
|
||||
// Reset deletes all metrics in this vector.
|
||||
func (v *GaugeVec) Reset() {
|
||||
if !v.IsCreated() {
|
||||
return
|
||||
}
|
||||
|
||||
v.GaugeVec.Reset()
|
||||
}
|
||||
|
||||
func newGaugeFunc(opts GaugeOpts, function func() float64, v semver.Version) GaugeFunc {
|
||||
g := NewGauge(&opts)
|
||||
|
||||
if !g.Create(&v) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return prometheus.NewGaugeFunc(g.GaugeOpts.toPromGaugeOpts(), function)
|
||||
}
|
||||
|
||||
// NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The
|
||||
// value reported is determined by calling the given function from within the
|
||||
// Write method. Take into account that metric collection may happen
|
||||
// concurrently. If that results in concurrent calls to Write, like in the case
|
||||
// where a GaugeFunc is directly registered with Prometheus, the provided
|
||||
// function must be concurrency-safe.
|
||||
func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc {
|
||||
v := parseVersion(version.Get())
|
||||
|
||||
return newGaugeFunc(opts, function, v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user