-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Override healthcheck HTTP status #1821
Conversation
Some monitoring tools only parse responses with status 200. With this change status 500 can be disabled.
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.
@maffe Thanks for your contribution! 🙂
I've added a few remarks about your PR.
@@ -124,7 +124,8 @@ protected void doGet(HttpServletRequest req, | |||
if (results.isEmpty()) { | |||
resp.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); | |||
} else { | |||
if (isAllHealthy(results)) { | |||
final boolean alwaysOk = Boolean.parseBoolean(req.getParameter("alwaysOk")); |
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.
Could we rename the parameter to overrideStatusCode
?
The name alwaysOk
implies that the health check result would be always healthy. 😉
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.
Initially I planned to name it similar to your proposal, but then I thought this would suggest the parameter value should be the desired status code (overrideStatusCode=200
) instead of a boolean. I included OK
because this is the official name for HTTP status 200. Also, I think OK
differs from healthy
enough to not suggest it would affect those entries.
Maybe httpStatusOk=true
?
metrics-servlets/src/main/java/com/codahale/metrics/servlets/HealthCheckServlet.java
Show resolved
Hide resolved
This approach is a bit different than what I'd expect. It seems a little strange to have the client be able to dynamically influence the response status code of the If the behavior was to be configurable, I would expect it to be configured through the @maffe Can you elaborate a bit on your use case and which monitoring tools you are having trouble with? Alternatively, a workaround could be to use a servlet filter to swallow the 500 status code from the |
Currently a PRTG HTTP Sensor is used to retrieve the overall status. The goal is to monitor each healthcheck individually, but the REST Custom Sensor just shows gaps for everything when the status is 500. Disabling the status 500 via query parameter would make it possible to use both types of sensors with minimal code change in Dropwizard. Using static configuration would also work when the basic HTTP Sensor is not needed. |
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821
Resolved in #1871. |
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `com.codahale.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821 Refs #1871
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821 Refs #1871
- Allow overriding the `ObjectMapper` instance used in `HealthCheckServlet` with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.mapper` - Allow setting the HTTP status code used to indicate health to 200 (OK) with the servlet attribute `io.dropwizard.metrics.servlets.HealthCheckServlet.httpStatusIndicator`, or with the HTTP query parameter `httpStatusIndicator` per request Refs #1821 Refs #1871 Fixes #3918
Some monitoring tools only parse responses with status 200. With this change status 500 can be disabled.