Use custom mux instead of DefaultServeMux
Signed-off-by: Poor12 <shentiecheng@huawei.com>
This commit is contained in:
parent
18e3fba143
commit
1613839201
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue