mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update kubernetes to v1.25.0
update kubernetes to latest v1.25.0 release. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
f47839d73d
commit
e3bf375035
189
vendor/k8s.io/component-base/metrics/prometheusextension/timing_histogram.go
generated
vendored
Normal file
189
vendor/k8s.io/component-base/metrics/prometheusextension/timing_histogram.go
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package prometheusextension
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
// GaugeOps is the part of `prometheus.Gauge` that is relevant to
|
||||
// instrumented code.
|
||||
// This factoring should be in prometheus, analogous to the way
|
||||
// it already factors out the Observer interface for histograms and summaries.
|
||||
type GaugeOps interface {
|
||||
// Set is the same as Gauge.Set
|
||||
Set(float64)
|
||||
// Inc is the same as Gauge.inc
|
||||
Inc()
|
||||
// Dec is the same as Gauge.Dec
|
||||
Dec()
|
||||
// Add is the same as Gauge.Add
|
||||
Add(float64)
|
||||
// Sub is the same as Gauge.Sub
|
||||
Sub(float64)
|
||||
|
||||
// SetToCurrentTime the same as Gauge.SetToCurrentTime
|
||||
SetToCurrentTime()
|
||||
}
|
||||
|
||||
// A TimingHistogram tracks how long a `float64` variable spends in
|
||||
// ranges defined by buckets. Time is counted in nanoseconds. The
|
||||
// histogram's sum is the integral over time (in nanoseconds, from
|
||||
// creation of the histogram) of the variable's value.
|
||||
type TimingHistogram interface {
|
||||
prometheus.Metric
|
||||
prometheus.Collector
|
||||
GaugeOps
|
||||
}
|
||||
|
||||
// TimingHistogramOpts is the parameters of the TimingHistogram constructor
|
||||
type TimingHistogramOpts struct {
|
||||
Namespace string
|
||||
Subsystem string
|
||||
Name string
|
||||
Help string
|
||||
ConstLabels prometheus.Labels
|
||||
|
||||
// Buckets defines the buckets into which observations are
|
||||
// accumulated. Each element in the slice is the upper
|
||||
// inclusive bound of a bucket. The values must be sorted in
|
||||
// strictly increasing order. There is no need to add a
|
||||
// highest bucket with +Inf bound. The default value is
|
||||
// prometheus.DefBuckets.
|
||||
Buckets []float64
|
||||
|
||||
// The initial value of the variable.
|
||||
InitialValue float64
|
||||
}
|
||||
|
||||
// NewTimingHistogram creates a new TimingHistogram
|
||||
func NewTimingHistogram(opts TimingHistogramOpts) (TimingHistogram, error) {
|
||||
return NewTestableTimingHistogram(time.Now, opts)
|
||||
}
|
||||
|
||||
// NewTestableTimingHistogram creates a TimingHistogram that uses a mockable clock
|
||||
func NewTestableTimingHistogram(nowFunc func() time.Time, opts TimingHistogramOpts) (TimingHistogram, error) {
|
||||
desc := prometheus.NewDesc(
|
||||
prometheus.BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
||||
wrapTimingHelp(opts.Help),
|
||||
nil,
|
||||
opts.ConstLabels,
|
||||
)
|
||||
return newTimingHistogram(nowFunc, desc, opts)
|
||||
}
|
||||
|
||||
func wrapTimingHelp(given string) string {
|
||||
return "EXPERIMENTAL: " + given
|
||||
}
|
||||
|
||||
func newTimingHistogram(nowFunc func() time.Time, desc *prometheus.Desc, opts TimingHistogramOpts, variableLabelValues ...string) (TimingHistogram, error) {
|
||||
allLabelsM := prometheus.Labels{}
|
||||
allLabelsS := prometheus.MakeLabelPairs(desc, variableLabelValues)
|
||||
for _, pair := range allLabelsS {
|
||||
if pair == nil || pair.Name == nil || pair.Value == nil {
|
||||
return nil, errors.New("prometheus.MakeLabelPairs returned a nil")
|
||||
}
|
||||
allLabelsM[*pair.Name] = *pair.Value
|
||||
}
|
||||
weighted, err := newWeightedHistogram(desc, WeightedHistogramOpts{
|
||||
Namespace: opts.Namespace,
|
||||
Subsystem: opts.Subsystem,
|
||||
Name: opts.Name,
|
||||
Help: opts.Help,
|
||||
ConstLabels: allLabelsM,
|
||||
Buckets: opts.Buckets,
|
||||
}, variableLabelValues...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &timingHistogram{
|
||||
nowFunc: nowFunc,
|
||||
weighted: weighted,
|
||||
lastSetTime: nowFunc(),
|
||||
value: opts.InitialValue,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type timingHistogram struct {
|
||||
nowFunc func() time.Time
|
||||
weighted *weightedHistogram
|
||||
|
||||
// The following fields must only be accessed with weighted's lock held
|
||||
|
||||
lastSetTime time.Time // identifies when value was last set
|
||||
value float64
|
||||
}
|
||||
|
||||
var _ TimingHistogram = &timingHistogram{}
|
||||
|
||||
func (th *timingHistogram) Set(newValue float64) {
|
||||
th.update(func(float64) float64 { return newValue })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Inc() {
|
||||
th.update(func(oldValue float64) float64 { return oldValue + 1 })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Dec() {
|
||||
th.update(func(oldValue float64) float64 { return oldValue - 1 })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Add(delta float64) {
|
||||
th.update(func(oldValue float64) float64 { return oldValue + delta })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Sub(delta float64) {
|
||||
th.update(func(oldValue float64) float64 { return oldValue - delta })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) SetToCurrentTime() {
|
||||
th.update(func(oldValue float64) float64 { return th.nowFunc().Sub(time.Unix(0, 0)).Seconds() })
|
||||
}
|
||||
|
||||
func (th *timingHistogram) update(updateFn func(float64) float64) {
|
||||
th.weighted.lock.Lock()
|
||||
defer th.weighted.lock.Unlock()
|
||||
now := th.nowFunc()
|
||||
delta := now.Sub(th.lastSetTime)
|
||||
value := th.value
|
||||
if delta > 0 {
|
||||
th.weighted.observeWithWeightLocked(value, uint64(delta))
|
||||
th.lastSetTime = now
|
||||
}
|
||||
th.value = updateFn(value)
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Desc() *prometheus.Desc {
|
||||
return th.weighted.Desc()
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Write(dest *dto.Metric) error {
|
||||
th.Add(0) // account for time since last update
|
||||
return th.weighted.Write(dest)
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- th.weighted.Desc()
|
||||
}
|
||||
|
||||
func (th *timingHistogram) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- th
|
||||
}
|
111
vendor/k8s.io/component-base/metrics/prometheusextension/timing_histogram_vec.go
generated
vendored
Normal file
111
vendor/k8s.io/component-base/metrics/prometheusextension/timing_histogram_vec.go
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package prometheusextension
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// GaugeVecOps is a bunch of Gauge that have the same
|
||||
// Desc and are distinguished by the values for their variable labels.
|
||||
type GaugeVecOps interface {
|
||||
GetMetricWith(prometheus.Labels) (GaugeOps, error)
|
||||
GetMetricWithLabelValues(lvs ...string) (GaugeOps, error)
|
||||
With(prometheus.Labels) GaugeOps
|
||||
WithLabelValues(...string) GaugeOps
|
||||
CurryWith(prometheus.Labels) (GaugeVecOps, error)
|
||||
MustCurryWith(prometheus.Labels) GaugeVecOps
|
||||
}
|
||||
|
||||
type TimingHistogramVec struct {
|
||||
*prometheus.MetricVec
|
||||
}
|
||||
|
||||
var _ GaugeVecOps = &TimingHistogramVec{}
|
||||
var _ prometheus.Collector = &TimingHistogramVec{}
|
||||
|
||||
func NewTimingHistogramVec(opts TimingHistogramOpts, labelNames ...string) *TimingHistogramVec {
|
||||
return NewTestableTimingHistogramVec(time.Now, opts, labelNames...)
|
||||
}
|
||||
|
||||
func NewTestableTimingHistogramVec(nowFunc func() time.Time, opts TimingHistogramOpts, labelNames ...string) *TimingHistogramVec {
|
||||
desc := prometheus.NewDesc(
|
||||
prometheus.BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
||||
wrapTimingHelp(opts.Help),
|
||||
labelNames,
|
||||
opts.ConstLabels,
|
||||
)
|
||||
return &TimingHistogramVec{
|
||||
MetricVec: prometheus.NewMetricVec(desc, func(lvs ...string) prometheus.Metric {
|
||||
metric, err := newTimingHistogram(nowFunc, desc, opts, lvs...)
|
||||
if err != nil {
|
||||
panic(err) // like in prometheus.newHistogram
|
||||
}
|
||||
return metric
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) GetMetricWith(labels prometheus.Labels) (GaugeOps, error) {
|
||||
metric, err := hv.MetricVec.GetMetricWith(labels)
|
||||
if metric != nil {
|
||||
return metric.(GaugeOps), err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) GetMetricWithLabelValues(lvs ...string) (GaugeOps, error) {
|
||||
metric, err := hv.MetricVec.GetMetricWithLabelValues(lvs...)
|
||||
if metric != nil {
|
||||
return metric.(GaugeOps), err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) With(labels prometheus.Labels) GaugeOps {
|
||||
h, err := hv.GetMetricWith(labels)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) WithLabelValues(lvs ...string) GaugeOps {
|
||||
h, err := hv.GetMetricWithLabelValues(lvs...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) CurryWith(labels prometheus.Labels) (GaugeVecOps, error) {
|
||||
vec, err := hv.MetricVec.CurryWith(labels)
|
||||
if vec != nil {
|
||||
return &TimingHistogramVec{MetricVec: vec}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *TimingHistogramVec) MustCurryWith(labels prometheus.Labels) GaugeVecOps {
|
||||
vec, err := hv.CurryWith(labels)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return vec
|
||||
}
|
203
vendor/k8s.io/component-base/metrics/prometheusextension/weighted_histogram.go
generated
vendored
Normal file
203
vendor/k8s.io/component-base/metrics/prometheusextension/weighted_histogram.go
generated
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package prometheusextension
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
// WeightedHistogram generalizes Histogram: each observation has
|
||||
// an associated _weight_. For a given `x` and `N`,
|
||||
// `1` call on `ObserveWithWeight(x, N)` has the same meaning as
|
||||
// `N` calls on `ObserveWithWeight(x, 1)`.
|
||||
// The weighted sum might differ slightly due to the use of
|
||||
// floating point, although the implementation takes some steps
|
||||
// to mitigate that.
|
||||
// If every weight were 1,
|
||||
// this would be the same as the existing Histogram abstraction.
|
||||
type WeightedHistogram interface {
|
||||
prometheus.Metric
|
||||
prometheus.Collector
|
||||
WeightedObserver
|
||||
}
|
||||
|
||||
// WeightedObserver generalizes the Observer interface.
|
||||
type WeightedObserver interface {
|
||||
// Set the variable to the given value with the given weight.
|
||||
ObserveWithWeight(value float64, weight uint64)
|
||||
}
|
||||
|
||||
// WeightedHistogramOpts is the same as for an ordinary Histogram
|
||||
type WeightedHistogramOpts = prometheus.HistogramOpts
|
||||
|
||||
// NewWeightedHistogram creates a new WeightedHistogram
|
||||
func NewWeightedHistogram(opts WeightedHistogramOpts) (WeightedHistogram, error) {
|
||||
desc := prometheus.NewDesc(
|
||||
prometheus.BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
||||
wrapWeightedHelp(opts.Help),
|
||||
nil,
|
||||
opts.ConstLabels,
|
||||
)
|
||||
return newWeightedHistogram(desc, opts)
|
||||
}
|
||||
|
||||
func wrapWeightedHelp(given string) string {
|
||||
return "EXPERIMENTAL: " + given
|
||||
}
|
||||
|
||||
func newWeightedHistogram(desc *prometheus.Desc, opts WeightedHistogramOpts, variableLabelValues ...string) (*weightedHistogram, error) {
|
||||
if len(opts.Buckets) == 0 {
|
||||
opts.Buckets = prometheus.DefBuckets
|
||||
}
|
||||
|
||||
for i, upperBound := range opts.Buckets {
|
||||
if i < len(opts.Buckets)-1 {
|
||||
if upperBound >= opts.Buckets[i+1] {
|
||||
return nil, fmt.Errorf(
|
||||
"histogram buckets must be in increasing order: %f >= %f",
|
||||
upperBound, opts.Buckets[i+1],
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if math.IsInf(upperBound, +1) {
|
||||
// The +Inf bucket is implicit. Remove it here.
|
||||
opts.Buckets = opts.Buckets[:i]
|
||||
}
|
||||
}
|
||||
}
|
||||
upperBounds := make([]float64, len(opts.Buckets))
|
||||
copy(upperBounds, opts.Buckets)
|
||||
|
||||
return &weightedHistogram{
|
||||
desc: desc,
|
||||
variableLabelValues: variableLabelValues,
|
||||
upperBounds: upperBounds,
|
||||
buckets: make([]uint64, len(upperBounds)+1),
|
||||
hotCount: initialHotCount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type weightedHistogram struct {
|
||||
desc *prometheus.Desc
|
||||
variableLabelValues []string
|
||||
upperBounds []float64 // exclusive of +Inf
|
||||
|
||||
lock sync.Mutex // applies to all the following
|
||||
|
||||
// buckets is longer by one than upperBounds.
|
||||
// For 0 <= idx < len(upperBounds), buckets[idx] holds the
|
||||
// accumulated time.Duration that value has been <=
|
||||
// upperBounds[idx] but not <= upperBounds[idx-1].
|
||||
// buckets[len(upperBounds)] holds the accumulated
|
||||
// time.Duration when value fit in no other bucket.
|
||||
buckets []uint64
|
||||
|
||||
// sumHot + sumCold is the weighted sum of value.
|
||||
// Rather than risk loss of precision in one
|
||||
// float64, we do this sum hierarchically. Many successive
|
||||
// increments are added into sumHot; once in a while
|
||||
// the magnitude of sumHot is compared to the magnitude
|
||||
// of sumCold and, if the ratio is high enough,
|
||||
// sumHot is transferred into sumCold.
|
||||
sumHot float64
|
||||
sumCold float64
|
||||
|
||||
transferThreshold float64 // = math.Abs(sumCold) / 2^26 (that's about half of the bits of precision in a float64)
|
||||
|
||||
// hotCount is used to decide when to consider dumping sumHot into sumCold.
|
||||
// hotCount counts upward from initialHotCount to zero.
|
||||
hotCount int
|
||||
}
|
||||
|
||||
// initialHotCount is the negative of the number of terms
|
||||
// that are summed into sumHot before considering whether
|
||||
// to transfer to sumCold. This only has to be big enough
|
||||
// to make the extra floating point operations occur in a
|
||||
// distinct minority of cases.
|
||||
const initialHotCount = -15
|
||||
|
||||
var _ WeightedHistogram = &weightedHistogram{}
|
||||
var _ prometheus.Metric = &weightedHistogram{}
|
||||
var _ prometheus.Collector = &weightedHistogram{}
|
||||
|
||||
func (sh *weightedHistogram) ObserveWithWeight(value float64, weight uint64) {
|
||||
idx := sort.SearchFloat64s(sh.upperBounds, value)
|
||||
sh.lock.Lock()
|
||||
defer sh.lock.Unlock()
|
||||
sh.updateLocked(idx, value, weight)
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) observeWithWeightLocked(value float64, weight uint64) {
|
||||
idx := sort.SearchFloat64s(sh.upperBounds, value)
|
||||
sh.updateLocked(idx, value, weight)
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) updateLocked(idx int, value float64, weight uint64) {
|
||||
sh.buckets[idx] += weight
|
||||
newSumHot := sh.sumHot + float64(weight)*value
|
||||
sh.hotCount++
|
||||
if sh.hotCount >= 0 {
|
||||
sh.hotCount = initialHotCount
|
||||
if math.Abs(newSumHot) > sh.transferThreshold {
|
||||
newSumCold := sh.sumCold + newSumHot
|
||||
sh.sumCold = newSumCold
|
||||
sh.transferThreshold = math.Abs(newSumCold / 67108864)
|
||||
sh.sumHot = 0
|
||||
return
|
||||
}
|
||||
}
|
||||
sh.sumHot = newSumHot
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) Desc() *prometheus.Desc {
|
||||
return sh.desc
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) Write(dest *dto.Metric) error {
|
||||
count, sum, buckets := func() (uint64, float64, map[float64]uint64) {
|
||||
sh.lock.Lock()
|
||||
defer sh.lock.Unlock()
|
||||
nBounds := len(sh.upperBounds)
|
||||
buckets := make(map[float64]uint64, nBounds)
|
||||
var count uint64
|
||||
for idx, upperBound := range sh.upperBounds {
|
||||
count += sh.buckets[idx]
|
||||
buckets[upperBound] = count
|
||||
}
|
||||
count += sh.buckets[nBounds]
|
||||
return count, sh.sumHot + sh.sumCold, buckets
|
||||
}()
|
||||
metric, err := prometheus.NewConstHistogram(sh.desc, count, sum, buckets, sh.variableLabelValues...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return metric.Write(dest)
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- sh.desc
|
||||
}
|
||||
|
||||
func (sh *weightedHistogram) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- sh
|
||||
}
|
106
vendor/k8s.io/component-base/metrics/prometheusextension/weighted_histogram_vec.go
generated
vendored
Normal file
106
vendor/k8s.io/component-base/metrics/prometheusextension/weighted_histogram_vec.go
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package prometheusextension
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// WeightedObserverVec is a bunch of WeightedObservers that have the same
|
||||
// Desc and are distinguished by the values for their variable labels.
|
||||
type WeightedObserverVec interface {
|
||||
GetMetricWith(prometheus.Labels) (WeightedObserver, error)
|
||||
GetMetricWithLabelValues(lvs ...string) (WeightedObserver, error)
|
||||
With(prometheus.Labels) WeightedObserver
|
||||
WithLabelValues(...string) WeightedObserver
|
||||
CurryWith(prometheus.Labels) (WeightedObserverVec, error)
|
||||
MustCurryWith(prometheus.Labels) WeightedObserverVec
|
||||
}
|
||||
|
||||
// WeightedHistogramVec implements WeightedObserverVec
|
||||
type WeightedHistogramVec struct {
|
||||
*prometheus.MetricVec
|
||||
}
|
||||
|
||||
var _ WeightedObserverVec = &WeightedHistogramVec{}
|
||||
var _ prometheus.Collector = &WeightedHistogramVec{}
|
||||
|
||||
func NewWeightedHistogramVec(opts WeightedHistogramOpts, labelNames ...string) *WeightedHistogramVec {
|
||||
desc := prometheus.NewDesc(
|
||||
prometheus.BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
|
||||
wrapWeightedHelp(opts.Help),
|
||||
labelNames,
|
||||
opts.ConstLabels,
|
||||
)
|
||||
return &WeightedHistogramVec{
|
||||
MetricVec: prometheus.NewMetricVec(desc, func(lvs ...string) prometheus.Metric {
|
||||
metric, err := newWeightedHistogram(desc, opts, lvs...)
|
||||
if err != nil {
|
||||
panic(err) // like in prometheus.newHistogram
|
||||
}
|
||||
return metric
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) GetMetricWith(labels prometheus.Labels) (WeightedObserver, error) {
|
||||
metric, err := hv.MetricVec.GetMetricWith(labels)
|
||||
if metric != nil {
|
||||
return metric.(WeightedObserver), err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) GetMetricWithLabelValues(lvs ...string) (WeightedObserver, error) {
|
||||
metric, err := hv.MetricVec.GetMetricWithLabelValues(lvs...)
|
||||
if metric != nil {
|
||||
return metric.(WeightedObserver), err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) With(labels prometheus.Labels) WeightedObserver {
|
||||
h, err := hv.GetMetricWith(labels)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) WithLabelValues(lvs ...string) WeightedObserver {
|
||||
h, err := hv.GetMetricWithLabelValues(lvs...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) CurryWith(labels prometheus.Labels) (WeightedObserverVec, error) {
|
||||
vec, err := hv.MetricVec.CurryWith(labels)
|
||||
if vec != nil {
|
||||
return &WeightedHistogramVec{MetricVec: vec}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (hv *WeightedHistogramVec) MustCurryWith(labels prometheus.Labels) WeightedObserverVec {
|
||||
vec, err := hv.CurryWith(labels)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return vec
|
||||
}
|
Reference in New Issue
Block a user