rebase: update kubernetes to 1.28.0 in main

updating kubernetes to 1.28.0
in the main repo.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2023-08-17 07:15:28 +02:00
committed by mergify[bot]
parent b2fdc269c3
commit ff3e84ad67
706 changed files with 45252 additions and 16346 deletions

View File

@ -19,19 +19,28 @@ package metrics
import (
"io"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
processStartedAt time.Time
)
func init() {
processStartedAt = time.Now()
}
// These constants cause handlers serving metrics to behave as described if
// errors are encountered.
const (
// Serve an HTTP status code 500 upon the first error
// HTTPErrorOnError serve an HTTP status code 500 upon the first error
// encountered. Report the error message in the body.
HTTPErrorOnError promhttp.HandlerErrorHandling = iota
// Ignore errors and try to serve as many metrics as possible. However,
// if no metrics can be served, serve an HTTP status code 500 and the
// ContinueOnError ignore errors and try to serve as many metrics as possible.
// However, if no metrics can be served, serve an HTTP status code 500 and the
// last error message in the body. Only use this in deliberate "best
// effort" metrics collection scenarios. In this case, it is highly
// recommended to provide other means of detecting errors: By setting an
@ -41,7 +50,7 @@ const (
// alerts.
ContinueOnError
// Panic upon the first error encountered (useful for "crash only" apps).
// PanicOnError panics upon the first error encountered (useful for "crash only" apps).
PanicOnError
)
@ -50,6 +59,7 @@ const (
type HandlerOpts promhttp.HandlerOpts
func (ho *HandlerOpts) toPromhttpHandlerOpts() promhttp.HandlerOpts {
ho.ProcessStartTime = processStartedAt
return promhttp.HandlerOpts(*ho)
}

View File

@ -18,6 +18,7 @@ package legacyregistry
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
@ -45,19 +46,22 @@ var (
// Registerer exposes the global registerer
Registerer = defaultRegistry.Registerer
processStart time.Time
)
func init() {
RawMustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
RawMustRegister(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll)))
defaultRegistry.RegisterMetaMetrics()
processStart = time.Now()
}
// Handler returns an HTTP handler for the DefaultGatherer. It is
// already instrumented with InstrumentHandler (using "prometheus" as handler
// name).
func Handler() http.Handler {
return promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, promhttp.HandlerFor(defaultRegistry, promhttp.HandlerOpts{}))
return promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, promhttp.HandlerFor(defaultRegistry, promhttp.HandlerOpts{ProcessStartTime: processStart}))
}
// HandlerWithReset returns an HTTP handler for the DefaultGatherer but invokes
@ -65,7 +69,7 @@ func Handler() http.Handler {
func HandlerWithReset() http.Handler {
return promhttp.InstrumentMetricHandler(
prometheus.DefaultRegisterer,
metrics.HandlerWithReset(defaultRegistry, metrics.HandlerOpts{}))
metrics.HandlerWithReset(defaultRegistry, metrics.HandlerOpts{ProcessStartTime: processStart}))
}
// CustomRegister registers a custom collector but uses the global registry.

View File

@ -30,7 +30,7 @@ var (
Namespace: "kubernetes",
Name: "feature_enabled",
Help: "This metric records the data about the stage and enablement of a k8s feature.",
StabilityLevel: k8smetrics.ALPHA,
StabilityLevel: k8smetrics.BETA,
},
[]string{"name", "stage"},
)

View File

@ -37,7 +37,7 @@ var (
Namespace: "kubernetes",
Name: "healthcheck",
Help: "This metric records the result of a single healthcheck.",
StabilityLevel: k8smetrics.ALPHA,
StabilityLevel: k8smetrics.BETA,
},
[]string{"name", "type"},
)
@ -48,7 +48,7 @@ var (
Namespace: "kubernetes",
Name: "healthchecks_total",
Help: "This metric records the results of all healthcheck.",
StabilityLevel: k8smetrics.ALPHA,
StabilityLevel: k8smetrics.BETA,
},
[]string{"name", "type", "status"},
)

View File

@ -39,26 +39,26 @@ var (
registeredMetrics = NewCounterVec(
&CounterOpts{
Name: "registered_metric_total",
Name: "registered_metrics_total",
Help: "The count of registered metrics broken by stability level and deprecation version.",
StabilityLevel: ALPHA,
StabilityLevel: BETA,
},
[]string{"stability_level", "deprecated_version"},
)
disabledMetricsTotal = NewCounter(
&CounterOpts{
Name: "disabled_metric_total",
Name: "disabled_metrics_total",
Help: "The count of disabled metrics.",
StabilityLevel: ALPHA,
StabilityLevel: BETA,
},
)
hiddenMetricsTotal = NewCounter(
&CounterOpts{
Name: "hidden_metric_total",
Name: "hidden_metrics_total",
Help: "The count of hidden metrics.",
StabilityLevel: ALPHA,
StabilityLevel: BETA,
},
)
)

View File

@ -19,11 +19,13 @@ package testutil
import (
"fmt"
"io"
"testing"
"github.com/prometheus/client_golang/prometheus/testutil"
apimachineryversion "k8s.io/apimachinery/pkg/version"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
)
// CollectAndCompare registers the provided Collector with a newly created
@ -91,3 +93,62 @@ func NewFakeKubeRegistry(ver string) metrics.KubeRegistry {
return metrics.NewKubeRegistry()
}
func AssertVectorCount(t *testing.T, name string, labelFilter map[string]string, wantCount int) {
metrics, err := legacyregistry.DefaultGatherer.Gather()
if err != nil {
t.Fatalf("Failed to gather metrics: %s", err)
}
counterSum := 0
for _, mf := range metrics {
if mf.GetName() != name {
continue // Ignore other metrics.
}
for _, metric := range mf.GetMetric() {
if !LabelsMatch(metric, labelFilter) {
continue
}
counterSum += int(metric.GetCounter().GetValue())
}
}
if wantCount != counterSum {
t.Errorf("Wanted count %d, got %d for metric %s with labels %#+v", wantCount, counterSum, name, labelFilter)
for _, mf := range metrics {
if mf.GetName() == name {
for _, metric := range mf.GetMetric() {
t.Logf("\tnear match: %s", metric.String())
}
}
}
}
}
func AssertHistogramTotalCount(t *testing.T, name string, labelFilter map[string]string, wantCount int) {
metrics, err := legacyregistry.DefaultGatherer.Gather()
if err != nil {
t.Fatalf("Failed to gather metrics: %s", err)
}
counterSum := 0
for _, mf := range metrics {
if mf.GetName() != name {
continue // Ignore other metrics.
}
for _, metric := range mf.GetMetric() {
if !LabelsMatch(metric, labelFilter) {
continue
}
counterSum += int(metric.GetHistogram().GetSampleCount())
}
}
if wantCount != counterSum {
t.Errorf("Wanted count %d, got %d for metric %s with labels %#+v", wantCount, counterSum, name, labelFilter)
for _, mf := range metrics {
if mf.GetName() == name {
for _, metric := range mf.GetMetric() {
t.Logf("\tnear match: %s\n", metric.String())
}
}
}
}
}