-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix/prometheusexporter Shutdown HTTP server #35465
base: main
Are you sure you want to change the base?
Fix/prometheusexporter Shutdown HTTP server #35465
Conversation
00e689f
to
52eee00
Compare
mux := http.NewServeMux() | ||
mux.Handle("/metrics", pe.handler) | ||
srv, err := pe.config.ToServer(ctx, host, pe.settings, mux) | ||
pe.shutdownFunc = func(ctx context.Context) error { | ||
err := ln.Close() | ||
err2 := srv.Shutdown(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will srv be nil if ToServer returned an error above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll adjust it accordingly!
func (pe *prometheusExporter) Shutdown(context.Context) error { | ||
return pe.shutdownFunc() | ||
func (pe *prometheusExporter) Shutdown(ctx context.Context) error { | ||
return pe.shutdownFunc(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil check required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint. What would you prefer to happen when ctx is nil? Pass ctx.TODO on or return an error?
Description: Shutdown the http.Server instance on exporter shutdown
Link to tracking Issue: #35464
Testing: Manual testing. I included this version of the exporter in our internal distribution and deployed it to verify the metrics no longer go stale after receiving a
NOHUP
signal.Documentation: n/a