Skip to content

Move server metrics to health port #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/server/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,17 @@ func (p *Proxy) runAgentServer(o *options.ProxyRunOptions, server *server.ProxyS

func (p *Proxy) runAdminServer(o *options.ProxyRunOptions, _ *server.ProxyServer) error {
muxHandler := http.NewServeMux()
muxHandler.Handle("/metrics", promhttp.Handler())
muxHandler.Handle("/metrics", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents: just leave the metrics handler in both places unconditionally, and add a comment that admin server is only for backward compatibility.

Otherwise, nice to add some unit test coverage of this redirect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aldudko , I think @jkh52 has a point. Can we just leave the metrics response in place on the admin server? If you can reach it, you don't need to redirect. If you can only reach the health port, then the redirect doesn't help.

host, _, err := net.SplitHostPort(r.Host)
// The port number may be omitted if the admin server is running on port
// 80, the default port for HTTP
if err != nil {
host = r.Host
}
dest := *r.URL
dest.Host = net.JoinHostPort(host, strconv.Itoa(o.HealthPort))
http.Redirect(w, r, dest.String(), http.StatusMovedPermanently)
}))
if o.EnableProfiling {
muxHandler.HandleFunc("/debug/pprof", util.RedirectTo("/debug/pprof/"))
muxHandler.HandleFunc("/debug/pprof/", netpprof.Index)
Expand Down Expand Up @@ -471,6 +481,7 @@ func (p *Proxy) runHealthServer(o *options.ProxyRunOptions, server *server.Proxy
})

muxHandler := http.NewServeMux()
muxHandler.Handle("/metrics", promhttp.Handler())
muxHandler.HandleFunc("/healthz", livenessHandler)
// "/ready" is deprecated but being maintained for backward compatibility
muxHandler.HandleFunc("/ready", readinessHandler)
Expand Down