0.0
No commit activity in last 3 years
No release in over 3 years
Health reporter
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 10
~> 10.0
~> 2.13
~> 0.8.0
~> 2.1

Runtime

~> 0.12
 Project Readme

HealthReporter

The HealthReporter gem makes the caching of health check requests on services easy. Simiply register a lambda returning true/false that determines if the service is healthy or not. The HealthReporter caches the result for future requests using a TTL value. If the cache is still valid it will not use the lambda to determine service health.

Installation

Add this line to your application's Gemfile:

gem 'health_reporter'

And then execute:

bundle

Or install it yourself as:

gem install health_reporter

Configuration

Testing

Run the rspec test tests using docker compose:

docker-compose build
docker-compose run --rm health-reporter bundle exec rspec -cfd spec/*

Usage

Overview

Out of the box you can simply call it as follows with the preconfigured always true self-check lambda:

  require 'health_reporter'
  HealthReporter.healthy?
  => true

The default values can be overridden as follow:

  require 'health_reporter'
  HealthReporter.self_test = lambda{ false }
  HealthReporter.healthy_cache_ttl = 60
  HealthReporter.unhealthy_cache_ttl = 30
  HealthReporter.healthy?
  => false

Configuration on startup

First it is set up somewhere in your service startup (config.ru) where you configure how it determines health:

  require 'health_reporter'
  HealthReporter.self_test = lambda{ false }
  HealthReporter.healthy_cache_ttl = 60
  HealthReporter.unhealthy_cache_ttl = 30

Health checking via an endpoint

In the controller/model of the health check you simply call the following and based on the boolean return respond with 200 or 500 for other services to see this service health:

  require 'health_reporter'
  HealthReporter.healthy?
  => false

Add service dependencies to check

In a microservices environment the health of a service is also determined by the health of other services it is reaching out to during normal operation. This gem allows you to register those dependency services to also be checked. The dependencies are checked along with the service self-check. The combined health state will be cached. Therefore whilst the cache is still valid, the dependencies will also not be rechecked.

  HealthReporter.register_dependency(url: 'https://hardware-store/status')

Or with specific status code and timeout configuration:

  HealthReporter.register_dependency(url: 'https://hardware-store/status', code: 200, timeout: 3)

Contributing

Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)

License

The gem is available as open source under the terms of the MIT License.