mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Clean up kube-proxy metrics startup
This commit is contained in:
parent
8747ba9370
commit
15632b10cb
@ -580,6 +580,7 @@ func serveHealthz(hz healthcheck.ProxierHealthUpdater) {
|
||||
if hz == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fn := func() {
|
||||
err := hz.Run()
|
||||
if err != nil {
|
||||
@ -593,6 +594,39 @@ func serveHealthz(hz healthcheck.ProxierHealthUpdater) {
|
||||
go wait.Until(fn, 5*time.Second, wait.NeverStop)
|
||||
}
|
||||
|
||||
func serveMetrics(bindAddress string, proxyMode string, enableProfiling bool) {
|
||||
if len(bindAddress) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
proxyMux := mux.NewPathRecorderMux("kube-proxy")
|
||||
healthz.InstallHandler(proxyMux)
|
||||
proxyMux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
fmt.Fprintf(w, "%s", proxyMode)
|
||||
})
|
||||
|
||||
//lint:ignore SA1019 See the Metrics Stability Migration KEP
|
||||
proxyMux.Handle("/metrics", legacyregistry.Handler())
|
||||
|
||||
if enableProfiling {
|
||||
routes.Profiling{}.Install(proxyMux)
|
||||
}
|
||||
|
||||
configz.InstallHandler(proxyMux)
|
||||
|
||||
fn := func() {
|
||||
err := http.ListenAndServe(bindAddress, proxyMux)
|
||||
if err != nil {
|
||||
// For historical reasons we do not abort on errors here. We may
|
||||
// change that in the future.
|
||||
utilruntime.HandleError(fmt.Errorf("starting metrics server failed: %v", err))
|
||||
}
|
||||
}
|
||||
go wait.Until(fn, 5*time.Second, wait.NeverStop)
|
||||
}
|
||||
|
||||
// Run runs the specified ProxyServer. This should never exit (unless CleanupAndExit is set).
|
||||
// TODO: At the moment, Run() cannot return a nil error, otherwise it's caller will never exit. Update callers of Run to handle nil errors.
|
||||
func (s *ProxyServer) Run() error {
|
||||
@ -618,27 +652,7 @@ func (s *ProxyServer) Run() error {
|
||||
serveHealthz(s.HealthzServer)
|
||||
|
||||
// Start up a metrics server if requested
|
||||
if len(s.MetricsBindAddress) > 0 {
|
||||
proxyMux := mux.NewPathRecorderMux("kube-proxy")
|
||||
healthz.InstallHandler(proxyMux)
|
||||
proxyMux.HandleFunc("/proxyMode", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
fmt.Fprintf(w, "%s", s.ProxyMode)
|
||||
})
|
||||
//lint:ignore SA1019 See the Metrics Stability Migration KEP
|
||||
proxyMux.Handle("/metrics", legacyregistry.Handler())
|
||||
if s.EnableProfiling {
|
||||
routes.Profiling{}.Install(proxyMux)
|
||||
}
|
||||
configz.InstallHandler(proxyMux)
|
||||
go wait.Until(func() {
|
||||
err := http.ListenAndServe(s.MetricsBindAddress, proxyMux)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("starting metrics server failed: %v", err))
|
||||
}
|
||||
}, 5*time.Second, wait.NeverStop)
|
||||
}
|
||||
serveMetrics(s.MetricsBindAddress, s.ProxyMode, s.EnableProfiling)
|
||||
|
||||
// Tune conntrack, if requested
|
||||
// Conntracker is always nil for windows
|
||||
|
@ -20,7 +20,6 @@ go_library(
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/clock:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
|
||||
"//vendor/github.com/lithammer/dedent:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
|
Loading…
Reference in New Issue
Block a user