wire up feature-gate for component slis

Change-Id: Iba6ffbcac9dba4f4be3023ada6ac31691c1ae17b
This commit is contained in:
Han Kang 2022-10-05 15:56:06 -07:00
parent 44a0b4e145
commit 01bfbdff2d
3 changed files with 14 additions and 3 deletions

View File

@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
utilwaitgroup "k8s.io/apimachinery/pkg/util/waitgroup"
"k8s.io/apimachinery/pkg/version"
@ -67,6 +68,7 @@ import (
"k8s.io/client-go/informers"
restclient "k8s.io/client-go/rest"
"k8s.io/component-base/logs"
"k8s.io/component-base/metrics/features"
"k8s.io/component-base/metrics/prometheus/slis"
"k8s.io/klog/v2"
openapicommon "k8s.io/kube-openapi/pkg/common"
@ -318,6 +320,10 @@ type AuthorizationInfo struct {
Authorizer authorizer.Authorizer
}
func init() {
utilruntime.Must(features.AddFeatureGates(utilfeature.DefaultMutableFeatureGate))
}
// NewConfig returns a Config struct with the default values
func NewConfig(codecs serializer.CodecFactory) *Config {
defaultHealthChecks := []healthz.HealthChecker{healthz.PingHealthz, healthz.LogHealthz}
@ -882,13 +888,18 @@ func installAPI(s *GenericAPIServer, c *Config) {
// so far, only logging related endpoints are considered valid to add for these debug flags.
routes.DebugFlags{}.Install(s.Handler.NonGoRestfulMux, "v", routes.StringFlagPutHandler(logs.GlogSetter))
}
if c.EnableMetrics {
if c.EnableProfiling {
routes.MetricsWithReset{}.Install(s.Handler.NonGoRestfulMux)
slis.SLIMetricsWithReset{}.Install(s.Handler.NonGoRestfulMux)
if utilfeature.DefaultFeatureGate.Enabled(features.ComponentSLIs) {
slis.SLIMetricsWithReset{}.Install(s.Handler.NonGoRestfulMux)
}
} else {
routes.DefaultMetrics{}.Install(s.Handler.NonGoRestfulMux)
slis.SLIMetrics{}.Install(s.Handler.NonGoRestfulMux)
if utilfeature.DefaultFeatureGate.Enabled(features.ComponentSLIs) {
slis.SLIMetrics{}.Install(s.Handler.NonGoRestfulMux)
}
}
}

View File

@ -169,7 +169,6 @@ func TestNewWithDelegate(t *testing.T) {
"/livez/poststarthook/storage-object-count-tracker-hook",
"/livez/poststarthook/wrapping-post-start-hook",
"/metrics",
"/metrics/slis",
"/readyz",
"/readyz/delegate-health",
"/readyz/informer-sync",

1
vendor/modules.txt vendored
View File

@ -1973,6 +1973,7 @@ k8s.io/component-base/logs/klogflags
k8s.io/component-base/logs/logreduction
k8s.io/component-base/logs/testinit
k8s.io/component-base/metrics
k8s.io/component-base/metrics/features
k8s.io/component-base/metrics/legacyregistry
k8s.io/component-base/metrics/prometheus/clientgo
k8s.io/component-base/metrics/prometheus/clientgo/leaderelection