Skip to content

Conversation

@gytis
Copy link

@gytis gytis commented May 5, 2017

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 5, 2017
Copy link
Member

@dsyer dsyer left a 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(
Copy link
Member

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?

Copy link
Member

@snicoll snicoll May 10, 2017

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.

Copy link
Author

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.

@wilkinsona
Copy link
Member

I'm not sure a health indicator should ever throw an exception. Wouldn't it be better to simply return "DOWN"?

@dsyer AbstractHealthIndicator already does that for any subclass that throws an exception while performing the check

@gytis gytis changed the title Log an error if JMS health indicator fails Log an error if health indicator throws an exception May 10, 2017
@gytis
Copy link
Author

gytis commented May 10, 2017

Updated commit to write warning message in AbstractHealthIndicator

logger.warn(String.format(
"%s failed: %s",
this.getClass().getSimpleName(),
ex.getMessage()));
Copy link
Member

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

Copy link
Author

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(),
Copy link
Member

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()

Copy link
Member

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.

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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 wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 13, 2017
@gytis
Copy link
Author

gytis commented May 15, 2017

@wilkinsona I've changed logger to non-static and added getClass() as log name to make message cleaner.

@wilkinsona wilkinsona added this to the 1.5.4 milestone May 15, 2017
@wilkinsona wilkinsona added priority: normal type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 15, 2017
wilkinsona added a commit that referenced this pull request May 15, 2017
* gh-9110:
  Log a warning if a health indicator throws an exception
@wilkinsona
Copy link
Member

Thanks for the PR. It's now been merged into 1.5.x and master.

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

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants