38
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
38
vendor/k8s.io/component-base/metrics/histogram.go
generated
vendored
@@ -21,6 +21,19 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// DefBuckets is a wrapper for prometheus.DefBuckets
|
||||
var DefBuckets = prometheus.DefBuckets
|
||||
|
||||
// LinearBuckets is a wrapper for prometheus.LinearBuckets.
|
||||
func LinearBuckets(start, width float64, count int) []float64 {
|
||||
return prometheus.LinearBuckets(start, width, count)
|
||||
}
|
||||
|
||||
// ExponentialBuckets is a wrapper for prometheus.ExponentialBuckets.
|
||||
func ExponentialBuckets(start, factor float64, count int) []float64 {
|
||||
return prometheus.ExponentialBuckets(start, factor, count)
|
||||
}
|
||||
|
||||
// Histogram is our internal representation for our wrapping struct around prometheus
|
||||
// histograms. Summary implements both kubeCollector and ObserverMetric
|
||||
type Histogram struct {
|
||||
@@ -33,10 +46,8 @@ type Histogram struct {
|
||||
// NewHistogram returns an object which is Histogram-like. However, nothing
|
||||
// will be measured until the histogram is registered somewhere.
|
||||
func NewHistogram(opts *HistogramOpts) *Histogram {
|
||||
// todo: handle defaulting better
|
||||
if opts.StabilityLevel == "" {
|
||||
opts.StabilityLevel = ALPHA
|
||||
}
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
h := &Histogram{
|
||||
HistogramOpts: opts,
|
||||
lazyMetric: lazyMetric{},
|
||||
@@ -85,10 +96,8 @@ type HistogramVec struct {
|
||||
// prometheus.HistogramVec object. However, the object returned will not measure
|
||||
// anything unless the collector is first registered, since the metric is lazily instantiated.
|
||||
func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
|
||||
// todo: handle defaulting better
|
||||
if opts.StabilityLevel == "" {
|
||||
opts.StabilityLevel = ALPHA
|
||||
}
|
||||
opts.StabilityLevel.setDefaults()
|
||||
|
||||
v := &HistogramVec{
|
||||
HistogramVec: noopHistogramVec,
|
||||
HistogramOpts: opts,
|
||||
@@ -137,7 +146,7 @@ func (v *HistogramVec) WithLabelValues(lvs ...string) ObserverMetric {
|
||||
// must match those of the VariableLabels in Desc). If that label map is
|
||||
// accessed for the first time, a new ObserverMetric is created IFF the HistogramVec has
|
||||
// been registered to a metrics registry.
|
||||
func (v *HistogramVec) With(labels prometheus.Labels) ObserverMetric {
|
||||
func (v *HistogramVec) With(labels map[string]string) ObserverMetric {
|
||||
if !v.IsCreated() {
|
||||
return noop
|
||||
}
|
||||
@@ -151,9 +160,18 @@ func (v *HistogramVec) With(labels prometheus.Labels) ObserverMetric {
|
||||
// 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 *HistogramVec) Delete(labels prometheus.Labels) bool {
|
||||
func (v *HistogramVec) 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.HistogramVec.Delete(labels)
|
||||
}
|
||||
|
||||
// Reset deletes all metrics in this vector.
|
||||
func (v *HistogramVec) Reset() {
|
||||
if !v.IsCreated() {
|
||||
return
|
||||
}
|
||||
|
||||
v.HistogramVec.Reset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user