Update dependency go modules for k8s v1.26.0-rc.0

This commit is contained in:
Sunny Song
2022-11-23 00:44:15 +00:00
parent 1097a9601b
commit f095f3155b
373 changed files with 45668 additions and 4985 deletions

43
vendor/k8s.io/component-base/metrics/buckets.go generated vendored Normal file
View File

@@ -0,0 +1,43 @@
/*
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 metrics
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)
}
// MergeBuckets merges buckets together
func MergeBuckets(buckets ...[]float64) []float64 {
result := make([]float64, 1)
for _, s := range buckets {
result = append(result, s...)
}
return result
}

View File

@@ -45,9 +45,9 @@ type StableCollector interface {
HiddenMetrics() []string
}
// BaseStableCollector which implements almost all of the methods defined by StableCollector
// BaseStableCollector which implements almost all methods defined by StableCollector
// is a convenient assistant for custom collectors.
// It is recommend that inherit BaseStableCollector when implementing custom collectors.
// It is recommended to inherit BaseStableCollector when implementing custom collectors.
type BaseStableCollector struct {
descriptors map[string]*Desc // stores all descriptors by pair<fqName, Desc>, these are collected from DescribeWithStability().
registerable map[string]*Desc // stores registerable descriptors by pair<fqName, Desc>, is a subset of descriptors.
@@ -62,7 +62,7 @@ func (bsc *BaseStableCollector) DescribeWithStability(ch chan<- *Desc) {
}
// Describe sends all descriptors to the provided channel.
// It intend to be called by prometheus registry.
// It intended to be called by prometheus registry.
func (bsc *BaseStableCollector) Describe(ch chan<- *prometheus.Desc) {
for _, d := range bsc.registerable {
ch <- d.toPrometheusDesc()

View File

@@ -44,7 +44,7 @@ func NewCounter(opts *CounterOpts) *Counter {
kc := &Counter{
CounterOpts: opts,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
kc.setPrometheusCounter(noop)
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
@@ -129,7 +129,7 @@ func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
CounterVec: noopCounterVec,
CounterOpts: opts,
originalLabels: labels,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
cv.lazyInit(cv, fqName)
return cv

View File

@@ -46,7 +46,7 @@ func NewGauge(opts *GaugeOpts) *Gauge {
kc := &Gauge{
GaugeOpts: opts,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
kc.setPrometheusGauge(noop)
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
@@ -115,7 +115,7 @@ func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
GaugeVec: noopGaugeVec,
GaugeOpts: opts,
originalLabels: labels,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
cv.lazyInit(cv, fqName)
return cv

View File

@@ -23,19 +23,6 @@ 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 {
@@ -52,7 +39,7 @@ func NewHistogram(opts *HistogramOpts) *Histogram {
h := &Histogram{
HistogramOpts: opts,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
h.setPrometheusHistogram(noopMetric{})
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
@@ -119,7 +106,7 @@ func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
HistogramVec: noopHistogramVec,
HistogramOpts: opts,
originalLabels: labels,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
v.lazyInit(v, fqName)
return v

View File

@@ -72,6 +72,7 @@ type lazyMetric struct {
markDeprecationOnce sync.Once
createOnce sync.Once
self kubeCollector
stabilityLevel StabilityLevel
}
func (r *lazyMetric) IsCreated() bool {
@@ -149,6 +150,7 @@ func (r *lazyMetric) Create(version *semver.Version) bool {
if r.IsHidden() {
return false
}
r.createOnce.Do(func() {
r.createLock.Lock()
defer r.createLock.Unlock()
@@ -159,6 +161,13 @@ func (r *lazyMetric) Create(version *semver.Version) bool {
r.self.initializeMetric()
}
})
sl := r.stabilityLevel
deprecatedV := r.self.DeprecatedVersion()
dv := ""
if deprecatedV != nil {
dv = deprecatedV.String()
}
registeredMetrics.WithLabelValues(string(sl), dv).Inc()
return r.IsCreated()
}

View File

@@ -66,9 +66,15 @@ func BuildFQName(namespace, subsystem, name string) string {
type StabilityLevel string
const (
// INTERNAL metrics have no stability guarantees, as such, labels may
// be arbitrarily added/removed and the metric may be deleted at any time.
INTERNAL StabilityLevel = "INTERNAL"
// ALPHA metrics have no stability guarantees, as such, labels may
// be arbitrarily added/removed and the metric may be deleted at any time.
ALPHA StabilityLevel = "ALPHA"
// BETA metrics are governed by the deprecation policy outlined in by
// the control plane metrics stability KEP.
BETA StabilityLevel = "BETA"
// STABLE metrics are guaranteed not be mutated and removal is governed by
// the deprecation policy outlined in by the control plane metrics stability KEP.
STABLE StabilityLevel = "STABLE"

View File

@@ -32,10 +32,35 @@ import (
var (
showHiddenOnce sync.Once
disabledMetricsLock sync.RWMutex
showHidden atomic.Value
showHidden atomic.Bool
registries []*kubeRegistry // stores all registries created by NewKubeRegistry()
registriesLock sync.RWMutex
disabledMetrics = map[string]struct{}{}
registeredMetrics = NewCounterVec(
&CounterOpts{
Name: "registered_metric_total",
Help: "The count of registered metrics broken by stability level and deprecation version.",
StabilityLevel: ALPHA,
},
[]string{"stability_level", "deprecated_version"},
)
disabledMetricsTotal = NewCounter(
&CounterOpts{
Name: "disabled_metric_total",
Help: "The count of disabled metrics.",
StabilityLevel: ALPHA,
},
)
hiddenMetricsTotal = NewCounter(
&CounterOpts{
Name: "hidden_metric_total",
Help: "The count of hidden metrics.",
StabilityLevel: ALPHA,
},
)
)
// shouldHide be used to check if a specific metric with deprecated version should be hidden
@@ -67,6 +92,7 @@ func SetDisabledMetric(name string) {
disabledMetricsLock.Lock()
defer disabledMetricsLock.Unlock()
disabledMetrics[name] = struct{}{}
disabledMetricsTotal.Inc()
}
// SetShowHidden will enable showing hidden metrics. This will no-opt
@@ -87,7 +113,7 @@ func SetShowHidden() {
// is enabled. While the primary usecase for this is internal (to determine
// registration behavior) this can also be used to introspect
func ShouldShowHidden() bool {
return showHidden.Load() != nil && showHidden.Load().(bool)
return showHidden.Load()
}
// Registerable is an interface for a collector metric which we
@@ -129,6 +155,8 @@ type KubeRegistry interface {
// Reset invokes the Reset() function on all items in the registry
// which are added as resettables.
Reset()
// RegisterMetaMetrics registers metrics about the number of registered metrics.
RegisterMetaMetrics()
}
// kubeRegistry is a wrapper around a prometheus registry-type object. Upon initialization
@@ -250,6 +278,7 @@ func (kr *kubeRegistry) trackHiddenCollector(c Registerable) {
defer kr.hiddenCollectorsLock.Unlock()
kr.hiddenCollectors[c.FQName()] = c
hiddenMetricsTotal.Inc()
}
// trackStableCollectors stores all custom collectors.
@@ -329,9 +358,14 @@ func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
return r
}
// NewKubeRegistry creates a new vanilla Registry without any Collectors
// pre-registered.
// NewKubeRegistry creates a new vanilla Registry
func NewKubeRegistry() KubeRegistry {
r := newKubeRegistry(BuildVersion())
return r
}
func (r *kubeRegistry) RegisterMetaMetrics() {
r.MustRegister(registeredMetrics)
r.MustRegister(disabledMetricsTotal)
r.MustRegister(hiddenMetricsTotal)
}

View File

@@ -49,7 +49,7 @@ func NewSummary(opts *SummaryOpts) *Summary {
s := &Summary{
SummaryOpts: opts,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
s.setPrometheusSummary(noopMetric{})
s.lazyInit(s, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
@@ -118,7 +118,7 @@ func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec {
v := &SummaryVec{
SummaryOpts: opts,
originalLabels: labels,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
v.lazyInit(v, fqName)
return v

View File

@@ -57,7 +57,7 @@ func NewTestableTimingHistogram(nowFunc func() time.Time, opts *TimingHistogramO
h := &TimingHistogram{
TimingHistogramOpts: opts,
nowFunc: nowFunc,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
h.setPrometheusHistogram(noopMetric{})
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
@@ -136,7 +136,7 @@ func NewTestableTimingHistogramVec(nowFunc func() time.Time, opts *TimingHistogr
TimingHistogramOpts: opts,
nowFunc: nowFunc,
originalLabels: labels,
lazyMetric: lazyMetric{},
lazyMetric: lazyMetric{stabilityLevel: opts.StabilityLevel},
}
v.lazyInit(v, fqName)
return v
@@ -177,6 +177,9 @@ func (v *TimingHistogramVec) WithLabelValuesChecked(lvs ...string) (GaugeMetric,
v.LabelValueAllowLists.ConstrainToAllowedList(v.originalLabels, lvs)
}
ops, err := v.TimingHistogramVec.GetMetricWithLabelValues(lvs...)
if err != nil {
return noop, err
}
return ops.(GaugeMetric), err
}

View File

@@ -47,6 +47,16 @@ func NewLazyConstMetric(desc *Desc, valueType ValueType, value float64, labelVal
return prometheus.MustNewConstMetric(desc.toPrometheusDesc(), valueType.toPromValueType(), value, labelValues...)
}
// NewConstMetric is a helper of NewConstMetric.
//
// Note: If the metrics described by the desc is hidden, the metrics will not be created.
func NewConstMetric(desc *Desc, valueType ValueType, value float64, labelValues ...string) (Metric, error) {
if desc.IsHidden() {
return nil, nil
}
return prometheus.NewConstMetric(desc.toPrometheusDesc(), valueType.toPromValueType(), value, labelValues...)
}
// NewLazyMetricWithTimestamp is a helper of NewMetricWithTimestamp.
//
// Warning: the Metric 'm' must be the one created by NewLazyConstMetric(),

View File

@@ -145,6 +145,12 @@ type Gatherer interface {
prometheus.Gatherer
}
// Registerer is the interface for the part of a registry in charge of registering
// the collected metrics.
type Registerer interface {
prometheus.Registerer
}
// GaugeFunc is a Gauge whose value is determined at collect time by calling a
// provided function.
//