Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Argannor
Copy link

@Argannor Argannor commented Sep 27, 2024

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

@Argannor Argannor requested review from dashpole and a team as code owners September 27, 2024 14:57
Copy link

linux-foundation-easycla bot commented Sep 27, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@Argannor Argannor force-pushed the fix/prometheusexporter-shutdown-server branch from 00e689f to 52eee00 Compare September 27, 2024 15:03
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)
Copy link
Contributor

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?

Copy link
Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nil check required

Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants