-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Log an error if health indicator throws an exception #9110
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
Conversation
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.
I'm not sure a health indicator should ever throw an exception. Wouldn't it be better to simply return "DOWN"?
| connection.getMetaData().getJMSProviderName()); | ||
| } | ||
| catch (Exception ex) { | ||
| logger.warn(String.format( |
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.
I don't like that this is JMS-specific. Why not log something in AbstractHealthIndicator?
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.
Ditto. My initial reaction was "why do we need to log something here specifically?". We could add the exception to the detail as well.
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.
Makes sense, I'll add the information to the AbstractHealthIndicator.
@dsyer |
|
Updated commit to write warning message in AbstractHealthIndicator |
| logger.warn(String.format( | ||
| "%s failed: %s", | ||
| this.getClass().getSimpleName(), | ||
| ex.getMessage())); |
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.
I think it'd be better to include the whole exception by using warn(String, Throwable) rather than just the message, particularly as the message is already part of the health's detail
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.
Updated
| catch (Exception ex) { | ||
| logger.warn(String.format( | ||
| "%s failed: %s", | ||
| this.getClass().getSimpleName(), |
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.
To avoid ambiguity, I think it'd be better to use getName()
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.
Wouldn't it be better to have a non static logger and use getClass() as the source? That way the classname of the health indicator would show up in the log entry by default.
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 probably would, however I don't think we'd done that anywhere else in the codebase. If the logger's non-static we probably need to think about exposing it to subclasses.
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.
Any suggestion which option should I add? I see both static and non-static examples in the code base.
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.
Let's go for private final Log please. We can think about exposing it to subclasses separately if/when the need arises.
|
@wilkinsona I've changed logger to non-static and added getClass() as log name to make message cleaner. |
* gh-9110: Log a warning if a health indicator throws an exception
|
Thanks for the PR. It's now been merged into 1.5.x and master. |
When running an application on Kubernetes its probes use /health endpoint to check if application is ready and alive. In case if JMS connection is not available, probes fail and pod is killed and restarted. However, the error message is simply that 'readiness/liveliness probe has failed'. Because JMS health indicator doesn't print any logging about failure, it's hard to figure out why did the probe fail.