Microservices for Java EE Architects: Addendum for The Java EE Architect's Handbook by Ashmore Derek C

Microservices for Java EE Architects: Addendum for The Java EE Architect's Handbook by Ashmore Derek C

Author:Ashmore, Derek C. [Ashmore, Derek C.]
Language: eng
Format: azw3
Publisher: DVT Press
Published: 2016-04-21T04:00:00+00:00


Health Checks

A health check is typically a URL that provides some type of indication that the service is responsive and able to fulfill its function. That URL is invoked by some type of monitoring tool (e.g., Nagios) that is capable of alerting an administrator if the health check fails. The simplest alert is that the microservice JVM is unresponsive. The question then becomes: what is your definition of ‘responsive’? Often just able to respond with an HTTP 200 isn’t sufficient.

In addition to verifying that the service itself is able to respond to a URL without error, I like to check access to external resources and dependencies. For example, I like to check database connection pool health. Yes, databases and other external resources should also be monitored with separate health checks, but checking the health of the connection pool used for database access also verifies that the pool is sized properly for the transaction volume that the service is currently handling. This kind of check can only be performed within the microservice process itself and cannot effectively be monitored from the outside. That kind of condition can also happen with traditional web applications and isn’t really new with microservices.

Health checks, regardless of the technical stack used for the microservices you are writing, should be part of the application architecture provided by the enterprise. There is no reason why each service producer should need to build their own. I usually utilize the Dropwizard metrics library to code health checks.

Those looking for a code-level example of such a health check can find one here. This example checks the connection pool to validate that the number of transactions waiting for a database connection is less than a configurable number (it defaults to three). That is, if too many transactions are waiting for database connections, then the service isn’t healthy because consumers are suffering performance issues. In this case, the connection pool might need to be resized for the load that the service is handling. In addition, I validate a connection from the pool to make sure not only that the database is available, but also that network connectivity between the service and database is available.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.