-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 promhttp error handling #726
Conversation
Essentially, just don't try to set a status code and send any error message in the body once metrics gathering has succeeded. At that point, the most likely reason for errors is anyway that the client has disconnected, in which sending an error is moot. The other possible reason for an error is a problem during metrics encoding. This is unlikely to happen (it's a coding error here in client_golang in any case), and if it is happening, the odds are we have already sent something to the ResponseWriter, which means we cannot set a status code anymore. The doc comment for HTTPErrorOnError now describes these circumstances explicitly and recommends to set a logger to report that kind of error. This should fix the reason for the infamous `superfluous response.WriteHeader call` message. Signed-off-by: beorn7 <beorn@grafana.com>
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.
It makes sense to me 👍
Thanks!
// WriteHeader is called more than once, but we want to protect | ||
// against it here. Note that we still delegate the WriteHeader | ||
// to the original ResponseWriter to not mask the bug from it. | ||
r.observeWriteHeader(code) |
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.
👍
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 @bwplotka 🐟 (o: I'll merge and cut a bug fix release. |
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.
LGTM!
// WriteHeader is called more than once, but we want to protect | ||
// against it here. Note that we still delegate the WriteHeader | ||
// to the original ResponseWriter to not mask the bug from it. | ||
r.observeWriteHeader(code) |
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.
👍
Essentially, just don't try to set a status code and send any error
message in the body once metrics gathering has succeeded. At that
point, the most likely reason for errors is anyway that the client has
disconnected, in which sending an error is moot. The other possible
reason for an error is a problem during metrics encoding. This is
unlikely to happen (it's a coding error here in client_golang in any
case), and if it is happening, the odds are we have already sent
something to the ResponseWriter, which means we cannot set a status
code anymore. The doc comment for HTTPErrorOnError now describes these
circumstances explicitly and recommends to set a logger to report that
kind of error.
This should fix the reason for the infamous
superfluous response.WriteHeader call
message.@lidel @woodsaj