Merge pull request #2120 from Poor12/master

Use custom mux instead of DefaultServeMux
This commit is contained in:
karmada-bot 2022-07-05 10:14:31 +08:00 committed by GitHub
commit fbe7d49917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -142,12 +142,13 @@ func run(opts *options.Options, stopChan <-chan struct{}) error {
}
func serveHealthzAndMetrics(address string) {
http.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
http.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics", promhttp.Handler())
klog.Fatal(http.ListenAndServe(address, nil))
klog.Fatal(http.ListenAndServe(address, mux))
}

View File

@ -87,12 +87,13 @@ func run(ctx context.Context, opts *options.Options) error {
}
func serveHealthzAndMetrics(address string) {
http.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
http.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics", promhttp.Handler())
klog.Fatal(http.ListenAndServe(address, nil))
klog.Fatal(http.ListenAndServe(address, mux))
}

View File

@ -169,12 +169,13 @@ func run(opts *options.Options, stopChan <-chan struct{}, registryOptions ...Opt
}
func serveHealthzAndMetrics(address string) {
http.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
http.Handle("/metrics", promhttp.Handler())
mux.Handle("/metrics", promhttp.Handler())
klog.Fatal(http.ListenAndServe(address, nil))
klog.Fatal(http.ListenAndServe(address, mux))
}