{"id":20515774,"url":"https://github.com/kuper-tech/http_health_check","last_synced_at":"2025-04-14T00:33:24.432Z","repository":{"id":46584660,"uuid":"515250229","full_name":"Kuper-Tech/http_health_check","owner":"Kuper-Tech","description":"Simple and extensible HTTP health checks server","archived":false,"fork":false,"pushed_at":"2023-08-16T09:37:48.000Z","size":52,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-10-30T02:32:59.226Z","etag":null,"topics":["delayed-job","ruby","sidekiq"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kuper-Tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-18T15:57:15.000Z","updated_at":"2024-09-23T09:31:49.000Z","dependencies_parsed_at":"2024-07-09T16:45:44.721Z","dependency_job_id":null,"html_url":"https://github.com/Kuper-Tech/http_health_check","commit_stats":null,"previous_names":["kuper-tech/http_health_check","sbermarket-tech/http_health_check"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuper-Tech%2Fhttp_health_check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuper-Tech%2Fhttp_health_check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuper-Tech%2Fhttp_health_check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kuper-Tech%2Fhttp_health_check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kuper-Tech","download_url":"https://codeload.github.com/Kuper-Tech/http_health_check/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224846738,"owners_count":17379598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delayed-job","ruby","sidekiq"],"created_at":"2024-11-15T21:24:37.766Z","updated_at":"2024-11-15T21:24:38.505Z","avatar_url":"https://github.com/Kuper-Tech.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HttpHealthCheck\n\n[![Gem Version](https://badge.fury.io/rb/http_health_check.svg)](https://badge.fury.io/rb/http_health_check)\n\nHttpHealthCheck is a tiny framework for building health check for your application components. It provides a set of built-in checkers (a.k.a. probes) and utilities for building your own.\n\nHttpHealthCheck is built with kubernetes health probes in mind, but it can be used with http health checker.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'http_health_check', '~\u003e 0.4.1'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install http_health_check\n\n## Usage\n\n### Sidekiq\n\nSidekiq health check is available at `/readiness/sidekiq`.\n\n```ruby\n# ./config/initializers/sidekiq.rb\nSidekiq.configure_server do |config|\n  HttpHealthCheck.run_server_async(port: 5555)\nend\n```\n\n### Delayed Job\n\nDelayedJob health check is available at `/readiness/delayed_job`.\n\n```ruby\n# ./script/delayed_job\nmodule Delayed::AfterFork\n  def after_fork\n    HttpHealthCheck.run_server_async(port: 5555)\n    super\n  end\nend\n```\n\n### Karafka ~\u003e 1.4\n\nRuby-kafka probe is disabled by default as it requires app-specific configuration to work properly. Example usage with karafka framework:\n\n```ruby\n# ./karafka.rb\n\nclass KarafkaApp \u003c Karafka::App\n  # ...\n  # karafka app configuration\n  # ...\nend\n\nKarafkaApp.boot!\n\nHttpHealthCheck.run_server_async(\n  port: 5555,\n  rack_app: HttpHealthCheck::RackApp.configure do |c|\n    c.probe '/readiness/karafka', HttpHealthCheck::Probes::RubyKafka.new(\n      consumer_groups: HttpHealthCheck::Utils::Karafka.consumer_groups(KarafkaApp),\n      # default heartbeat interval is 3 seconds, but we want to give it\n      # an ability to skip a few before failing the probe\n      heartbeat_interval_sec: 10,\n      # includes a list of topics and partitions into response for every consumer thread. false by default\n      verbose: false\n    )\n  end\n)\n```\n\nRuby kafka probe supports multi-threaded setups, i.e. if you are using karafka and you define multiple blocks with the same consumer group like\n\n```ruby\nclass KarafkaApp \u003c Karafka::App\n  consumer_groups.draw do\n    consumer_group 'foo' do\n      # ...\n    end\n  end\n\n  consumer_groups.draw do\n    consumer_group 'foo' do\n      # ...\n    end\n  end\nend\n\nHttpHealthCheck::Utils::Karafka.consumer_groups(KarafkaApp)\n# =\u003e ['foo', 'foo']\n```\n\nruby-kafka probe will count heartbeats from multiple threads.\n\n### Kubernetes deployment example\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: sidekiq\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: sidekiq\n  template:\n    metadata:\n      labels:\n        app: sidekiq\n    spec:\n      containers:\n        - name: sidekiq\n          image: my-app:latest\n          livenessProbe:\n            httpGet:\n              path: /liveness\n              port: 5555\n              scheme: HTTP\n          readinessProbe:\n            httpGet:\n              path: /readiness/sidekiq\n              port: 5555\n              scheme: HTTP\n```\n\n### Changing global configuration\n\n```ruby\nHttpHealthCheck.configure do |c|\n  # add probe with any callable class\n  c.probe '/health/my_service', MyProbe.new\n\n  # or with block\n  c.probe '/health/fake' do |_env|\n    [200, {}, ['OK']]\n  end\n\n  # optionally add built-in probes\n  HttpHealthCheck.add_builtin_probes(c)\n\n  # optionally override fallback (route not found) handler\n  c.fallback_handler do |env|\n    [404, {}, ['not found :(']]\n  end\n\n  # configure requests logger. Disabled by default\n  c.logger Rails.logger\nend\n```\n\n### Running server with custom rack app\n\n```ruby\nrack_app = HttpHealthCheck::RackApp.configure do |c|\n  c.probe '/health/my_service', MyProbe.new\nend\nHttpHealthCheck.run_server_async(port: 5555, rack_app: rack_app)\n```\n\n### Writing your own probes\n\nProbes are built around [HttpHealthCheck::Probe](./lib/http_health_check/probe.rb) mixin. Every probe defines **probe** method which receives [rack env](https://www.rubydoc.info/gems/rack/Rack/Request/Env)\nand should return [HttpHealthCheck::Probe::Result](./lib/http_health_check/probe/result.rb) or rack-compatible response (status-headers-body tuple).\nProbe-mixin provides convenience methods `probe_ok` and `probe_error` for creating [HttpHealthCheck::Probe::Result](./lib/http_health_check/probe/result.rb) instance. Both of them accept optional metadata hash that will be added to the response body.\nAny exception (StandardError) will be captured and converted into error-result.\n\n```ruby\nclass MyProbe\n  include HttpHealthCheck::Probe\n\n  def probe(_env)\n    status = MyService.status\n    return probe_ok if status == :ok\n\n    probe_error status: status\n  end\nend\n```\n\n```ruby\nHttpHealthCheck.configure do |config|\n  config.probe '/readiness/my_service', MyProbe.new\nend\n```\n\n### Built-in probes\n\n#### [Sidekiq](./lib/http_health_check/probes/sidekiq.rb)\n\nSidekiq probe ensures that sidekiq is ready by checking redis is available and writable. It uses sidekiq's redis connection pool to avoid spinning up extra connections.\nBe aware that this approach does not cover issues with sidekiq being stuck processing slow/endless jobs. Such cases are nearly impossible to cover without false-positive alerts.\n\n```ruby\nHttpHealthCheck.configure do |config|\n  config.probe '/readiness/sidekiq', HttpHealthCheck::Probes::Sidekiq.new\nend\n```\n\n#### [DelayedJob](./lib/http_health_check/probes/delayed_job.rb) (active record)\n\nDelayed Job probe is intended to work with [active record backend](https://github.com/collectiveidea/delayed_job_active_record).\nIt checks DelayedJob is healthy by enqueuing an empty job which will be deleted right after insertion. This allows us to be sure that the underlying database is connectable and writable.\nBe aware that by enqueuing a new job with every health check, we are incrementing the primary key sequence.\n\n```ruby\nHttpHealthCheck.configure do |config|\n  config.probe '/readiness/delayed_job', HttpHealthCheck::Probes::DelayedJob.new\nend\n```\n\n#### [ruby-kafka](./lib/http_health_check/probes/ruby_kafka.rb)\n\nruby-kafka probe is expected to be configured with consumer groups list. It subscribes to ruby-kafka's `heartbeat.consumer.kafka` ActiveSupport notification and tracks heartbeats for every given consumer group.\nIt expects a heartbeat every `:heartbeat_interval_sec` (10 seconds by default).\n\n```ruby\nheartbeat_app = HttpHealthCheck::RackApp.configure do |c|\n  c.probe '/readiness/kafka', HttpHealthCheck::Probes::Karafka.new(\n    consumer_groups: ['consumer-one', 'consumer-two'],\n    heartbeat_interval_sec: 42\n  )\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\nSome specs require redis to be run. You can use your own installation or start one via docker-compose.\n\n```shell\ndocker-compose up redis\n```\n\n## Deployment\n\n1. Update changelog and git add it\n2.\n\n```sh\nbump2version patch --allow-dirty\n```\n\n3. git push \u0026\u0026 git push --tags\n4. gem build\n5. gem push http_health_check-x.x.x.gem\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuper-tech%2Fhttp_health_check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuper-tech%2Fhttp_health_check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuper-tech%2Fhttp_health_check/lists"}