Skip to content

Commit 74d7aaa

Browse files
author
Alex Dudko
committed
Move server metrics to health port
1 parent e135055 commit 74d7aaa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/server/app/server.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,17 @@ func (p *Proxy) runAgentServer(o *options.ProxyRunOptions, server *server.ProxyS
422422

423423
func (p *Proxy) runAdminServer(o *options.ProxyRunOptions, _ *server.ProxyServer) error {
424424
muxHandler := http.NewServeMux()
425-
muxHandler.Handle("/metrics", promhttp.Handler())
425+
muxHandler.Handle("/metrics", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
426+
host, _, err := net.SplitHostPort(r.Host)
427+
// The port number may be omitted if the admin server is running on port
428+
// 80, the default port for HTTP
429+
if err != nil {
430+
host = r.Host
431+
}
432+
dest := *r.URL
433+
dest.Host = net.JoinHostPort(host, strconv.Itoa(o.HealthPort))
434+
http.Redirect(w, r, dest.String(), http.StatusMovedPermanently)
435+
}))
426436
if o.EnableProfiling {
427437
muxHandler.HandleFunc("/debug/pprof", util.RedirectTo("/debug/pprof/"))
428438
muxHandler.HandleFunc("/debug/pprof/", netpprof.Index)
@@ -471,6 +481,7 @@ func (p *Proxy) runHealthServer(o *options.ProxyRunOptions, server *server.Proxy
471481
})
472482

473483
muxHandler := http.NewServeMux()
484+
muxHandler.Handle("/metrics", promhttp.Handler())
474485
muxHandler.HandleFunc("/healthz", livenessHandler)
475486
// "/ready" is deprecated but being maintained for backward compatibility
476487
muxHandler.HandleFunc("/ready", readinessHandler)

0 commit comments

Comments
 (0)