hermes-rb 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7a8150916885c53a7ec982a4a8b4c52b3ae181c372a49d848af7e1938c4e57d
4
- data.tar.gz: 1df94ecfc4595c5c8e6c67d79750c4a2fbca4f1a7119a1f5c532b83890a9e1f8
3
+ metadata.gz: 7cc73b9dbd7c2d1569311975037c0d5f45aac33c3eca2ba581b095dc2670662f
4
+ data.tar.gz: dbb3cd464fd5ac24ba0e8f9c8dcbaf904a31d49ad43088f1e01c06323862ee36
5
5
  SHA512:
6
- metadata.gz: 57bd2ad4a3a48368360bc1d7fcd42817ef698f326c423068b237123142707d64ca025af62cc8fc0bc9540a0cfe338d701124d73a19b3fe6795c98a7a91ff3a50
7
- data.tar.gz: 89550087ed862bdeb2cb3472d766071f6504f8608ffad58c3fa164c756dee2775b91d7ee299a55949e8ba7d8a31750accaff0688269a13cf81185a924bf71cfc
6
+ metadata.gz: 04ebe50de83e5c3fbce03dc0c543563cdc7dd3e64f93cb65a7783c4437f56dadd31f5fcb60c8ec3332e480f8485224282728856ae9c0a1d732c7de9918b2a1b7
7
+ data.tar.gz: 2873fba2537bb1d8eb9b46e829fc1b312d079fd3eed7dc65bed09caa536349741c365ca2ee108617833b360e8e91d0c6814c01c23c13874b68ca725f84b11ae0
data/Changelog.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 0.6.0
6
+ - Add Health check
7
+
5
8
  ## 0.5.0
6
9
  - Add Datadog tracer
7
10
  - Allow to provide a custom tracer
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hermes-rb (0.5.0)
4
+ hermes-rb (0.6.0)
5
5
  activerecord (>= 5)
6
6
  activesupport (>= 5)
7
7
  dry-container (~> 0)
data/README.md CHANGED
@@ -459,6 +459,33 @@ end
459
459
 
460
460
  Hermes is just an extra layer on top of [hutch](https://github.com/gocardless/hutch), refer to Hutch's docs for more info about dealing with the workers and deployment.
461
461
 
462
+ ## Health Checks
463
+
464
+ If you want to perform a health check, use `Hermes::Checks::HealthCheck.check`, which checks if it's possible to connect RabbitMQ via Hutch.
465
+
466
+ The interface is compliant with `health_check`[https://github.com/ianheggie/health_check] gem. If you want to add the custom health check, just add this to the config:
467
+
468
+ ``` rb
469
+ config.add_custom_check("hermes") do
470
+ Hermes::Checks::HealthCheck.check
471
+ end
472
+ ```
473
+
474
+ You can also use `bin/health_check` file to perform healthcheck - on success, the script exits with `0` status and on failure, it logs the error and exits with `1` status.
475
+
476
+ To perform the actual check:
477
+
478
+ 1. Via `health_check` gem:
479
+ ```
480
+ curl -v localhost:3000/health_check/hermes.json
481
+ ```
482
+
483
+ 2. Via binary:
484
+
485
+ ```
486
+ bin/hermes_health_check
487
+ ```
488
+
462
489
  ## CircleCI config for installing RabbitMQ
463
490
 
464
491
  Use `- image: brandembassy/rabbitmq:latest`
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative "../lib/hermes-rb"
5
+
6
+ result = Hermes::Checks::HealthCheck.check
7
+ if result.empty?
8
+ exit 0
9
+ else
10
+ Hermes::DependenciesContainer["logger"].log_health_check_failure(result)
11
+ exit 1
12
+ end
data/hermes-rb.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
25
  end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.bindir = "bin"
27
+ spec.executables = ["hermes_health_check"]
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_dependency "dry-struct", "~> 1"
data/lib/hermes.rb CHANGED
@@ -25,6 +25,7 @@ require "hermes/producer_error_handler"
25
25
  require "hermes/producer_error_handler/null_handler"
26
26
  require "hermes/producer_error_handler/safe_handler"
27
27
  require "hermes/tracers"
28
+ require "hermes/checks"
28
29
  require "active_support"
29
30
  require "active_support/core_ext/string"
30
31
  require "active_record"
@@ -0,0 +1,5 @@
1
+ module Hermes
2
+ module Checks
3
+ autoload :HealthCheck, "hermes/checks/health_check"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module Hermes
2
+ module Checks
3
+ class HealthCheck
4
+ def self.check
5
+ broker = Hutch::Broker.new
6
+ broker.connect
7
+ broker.disconnect
8
+ ""
9
+ rescue StandardError => e
10
+ "[Hermes - #{e.message}] "
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/hermes/logger.rb CHANGED
@@ -17,6 +17,10 @@ module Hermes
17
17
  backend.info "[Hutch] published event to: #{routing_key}, properties: #{properties}, body: #{strip_sensitive_info(body)} at #{timestamp}"
18
18
  end
19
19
 
20
+ def log_health_check_failure(error)
21
+ backend.info "[Hermes] health check failed: #{error}"
22
+ end
23
+
20
24
  private
21
25
 
22
26
  def strip_sensitive_info(body)
@@ -1,5 +1,5 @@
1
1
  module Hermes
2
2
  module Rb
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Galanciak
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -210,7 +210,8 @@ description: A messenger of gods, delivering them via RabbitMQ with a little hel
210
210
  from Hutch
211
211
  email:
212
212
  - dev@bookingsync.com
213
- executables: []
213
+ executables:
214
+ - hermes_health_check
214
215
  extensions: []
215
216
  extra_rdoc_files: []
216
217
  files:
@@ -224,12 +225,15 @@ files:
224
225
  - README.md
225
226
  - Rakefile
226
227
  - bin/console
228
+ - bin/hermes_health_check
227
229
  - bin/setup
228
230
  - hermes-rb.gemspec
229
231
  - lib/hermes-rb.rb
230
232
  - lib/hermes.rb
231
233
  - lib/hermes/b_3_propagation_model_headers.rb
232
234
  - lib/hermes/base_event.rb
235
+ - lib/hermes/checks.rb
236
+ - lib/hermes/checks/health_check.rb
233
237
  - lib/hermes/configuration.rb
234
238
  - lib/hermes/consumer_builder.rb
235
239
  - lib/hermes/database_error_handler.rb