rails-healthcheck 1.3.0 → 1.4.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: 2d25b4cf169226744a322cf74972627d1091753e66ba5fe6eec51f3bba7af225
4
- data.tar.gz: 60fe9a9689b2c21e4cac94f5cc8baf6586720fe70bda3e2ea6cd1da2086983d4
3
+ metadata.gz: 5a5cf78b04593281cfd2e3018a79703e07aadc3d2a4ace5cc2d972f7ad083705
4
+ data.tar.gz: d0559dc632284d6f0a7f853632998973e6f2937974b1e20606a55851e1cd7c46
5
5
  SHA512:
6
- metadata.gz: a73b3ae6bfe2395d17ef0867db9811e4db58cfa539c4cb9f8d97849b2555206c6b879e1cf82038175760a7a3378436c6daed1bf033df94f975548dd0da3f1fd6
7
- data.tar.gz: a36bfef4ea3fca59937a309646f7bd4fc278b9571df00fa98929dd0048e63de6631afcf0264b255c3df8c8bbb1a22eade6bc8b107f1cd889c458812de91f98b4
6
+ metadata.gz: c9e1c73e1314bd9731e0f81f4aa45364490e64b9fbdb3339b93506337c9778a76172347af086fe7cb834f5e5740cb63df9203968554685febaaf0e65e21c1e5b
7
+ data.tar.gz: 453b5a2ce77392ad5b1763d3e56b386d2a078c2fc3d9f950e30b673b331f1400a4f966228141de6cb2ee7a31eef09d022d68901abe2ff1e31c024867a6a13321
data/README.md CHANGED
@@ -1,20 +1,19 @@
1
1
  # [Rails::Healthcheck][gem_page]
2
2
 
3
3
  [![Gem Version][gem_version_image]][gem_version_page]
4
- [![Build Status][travis_status_image]][travis_page]
5
- [![Maintainability][code_climate_maintainability_image]][code_climate_maintainability_page]
6
4
 
7
5
  A simple way to configure a healthcheck route in Rails applications
8
6
 
9
7
  ## Table of Contents
8
+
10
9
  - [Getting started](#getting-started)
11
10
  - [Installation](#installation)
12
11
  - [Settings](#settings)
13
12
  - [Custom Response](#custom-response)
14
- - [Verbose Errors](#verbose-errors)
13
+ - [Verbose](#verbose)
15
14
  - [Ignoring logs](#ignoring-logs)
16
15
  - [Lograge](#lograge)
17
- - [Datadog](#lograge)
16
+ - [Datadog](#datadog)
18
17
  - [Requests Examples](#requests-examples)
19
18
  - [Contributing](#contributing)
20
19
  - [License](#license)
@@ -51,8 +50,8 @@ Healthcheck.configure do |config|
51
50
 
52
51
  # -- Custom Response --
53
52
  # config.custom = lambda { |controller, checker|
54
- # controller.render json: my_custom_response unless checker.errored?
55
- # ...
53
+ # return controller.render(plain: 'Everything is awesome!') unless checker.errored?
54
+ # controller.verbose? ? controller.verbose_error(checker) : controller.head_error
56
55
  # }
57
56
 
58
57
  # -- Checks --
@@ -83,25 +82,39 @@ end
83
82
 
84
83
  Pass a `lambda` or `proc` receiving the params `controller` and `checker` to use it correctly. To use checker, you can see the avialable methods [here][checker_url] and [how][healthcheck_controller_url] it is implemented on HealthcheckController.
85
84
 
86
- ### Verbose Errors
85
+ ### Verbose
86
+
87
+ You can enable verbose responses setting `config.verbose = true`.
87
88
 
88
- When happen an error and verbose is enabled (`config.verbose = true`), the response will be like this:
89
+ - On success
89
90
 
90
91
  ```json
91
92
  {
92
- "code": 503,
93
- "errors": [
94
- {
95
- "name": "migrations",
96
- "exception": "ActiveRecord::PendingMigrationError",
97
- "message": "Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=production"
98
- },
99
- {
100
- "name": "environments",
101
- "exception": "Dotenv::MissingKeys",
102
- "message": "Missing required configuration key: [\"RAILS_ENV\"]"
103
- }
104
- ]
93
+ "code": 200,
94
+ "status": {
95
+ "migrations": "OK",
96
+ "environments": "OK"
97
+ }
98
+ }
99
+ ```
100
+
101
+ - On error
102
+
103
+ ```json
104
+ {
105
+ "code": 503,
106
+ "errors": [
107
+ {
108
+ "name": "migrations",
109
+ "exception": "ActiveRecord::PendingMigrationError",
110
+ "message": "Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=production"
111
+ },
112
+ {
113
+ "name": "environments",
114
+ "exception": "Dotenv::MissingKeys",
115
+ "message": "Missing required configuration key: [\"RAILS_ENV\"]"
116
+ }
117
+ ]
105
118
  }
106
119
  ```
107
120
 
@@ -143,6 +156,7 @@ HTTP/1.1 200 OK
143
156
  ```
144
157
 
145
158
  - Error
159
+
146
160
  ```shell
147
161
  curl -i localhost:3000/healthcheck
148
162
 
@@ -150,6 +164,7 @@ HTTP/1.1 503 Service Unavailable
150
164
  ```
151
165
 
152
166
  - Error (Verbose)
167
+
153
168
  ```shell
154
169
  curl -i localhost:3000/healthcheck
155
170
 
@@ -177,10 +192,6 @@ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trac
177
192
  [code_of_conduct_page]: https://github.com/linqueta/rails-healthcheck/blob/master/CODE_OF_CONDUCT.md
178
193
  [mit_license_page]: https://opensource.org/licenses/MIT
179
194
  [contributor_convenant_page]: http://contributor-covenant.org
180
- [travis_status_image]: https://travis-ci.org/linqueta/rails-healthcheck.svg?branch=master
181
- [travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
182
- [code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
183
- [code_climate_maintainability_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/maintainability
184
195
  [gem_version_image]: https://badge.fury.io/rb/rails-healthcheck.svg
185
196
  [gem_version_page]: https://badge.fury.io/rb/rails-healthcheck
186
197
  [checker_url]: https://github.com/linqueta/rails-healthcheck/blob/master/lib/healthcheck/checker.rb
@@ -1,32 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'action_controller/railtie'
4
+
4
5
  module Healthcheck
5
6
  class HealthchecksController < ActionController::Base
6
7
  def check
7
- checker = Healthcheck.check
8
- return Healthcheck.configuration.custom.call(self, checker) if Healthcheck.configuration.custom
9
- return head Healthcheck.configuration.success unless checker.errored?
10
-
11
- verbose? ? verbose_error(checker) : head_error
12
- end
13
-
14
- private
8
+ return Healthcheck.custom!(self) if Healthcheck.custom?
15
9
 
16
- def head_error
17
- head Healthcheck.configuration.error
18
- end
19
-
20
- def verbose_error(checker)
21
- render status: Healthcheck.configuration.error,
22
- json: {
23
- code: Healthcheck.configuration.error,
24
- errors: checker.errors.as_json
25
- }
26
- end
27
-
28
- def verbose?
29
- Healthcheck.configuration.verbose
10
+ checker = Healthcheck.check
11
+ response = if checker.errored?
12
+ Healthcheck::Response::Error.new(self, checker)
13
+ else
14
+ Healthcheck::Response::Success.new(self, checker)
15
+ end
16
+ response.execute!
30
17
  end
31
18
  end
32
19
  end
@@ -20,8 +20,8 @@ module Healthcheck
20
20
 
21
21
  # -- Custom Response --
22
22
  # config.custom = lambda { |controller, checker|
23
- # controller.render json: my_custom_response unless checker.errored?
24
- # ...
23
+ # return controller.render(plain: 'Everything is awesome!') unless checker.errored?
24
+ # controller.verbose? ? controller.verbose_error(checker) : controller.head_error
25
25
  # }
26
26
 
27
27
  # -- Checks --
data/lib/healthcheck.rb CHANGED
@@ -8,6 +8,10 @@ require 'healthcheck/error'
8
8
  require 'healthcheck/router'
9
9
  require 'healthcheck/engine'
10
10
 
11
+ require 'healthcheck/response/base'
12
+ require 'healthcheck/response/success'
13
+ require 'healthcheck/response/error'
14
+
11
15
  module Healthcheck
12
16
  CONTROLLER_ACTION = 'Healthcheck::HealthchecksController#check'
13
17
 
@@ -22,10 +26,18 @@ module Healthcheck
22
26
  end
23
27
 
24
28
  def routes(router)
25
- Healthcheck::Router.mount(router)
29
+ Router.mount(router)
26
30
  end
27
31
 
28
32
  def check
29
- Healthcheck::Checker.new.tap(&:check)
33
+ Checker.new.tap(&:check)
34
+ end
35
+
36
+ def custom!(controller)
37
+ configuration.custom.call(controller, check)
38
+ end
39
+
40
+ def custom?
41
+ configuration.custom
30
42
  end
31
43
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthcheck
4
+ module Response
5
+ class Base
6
+ def initialize(controller, checker)
7
+ @controller = controller
8
+ @checker = checker
9
+ @configuration = Healthcheck.configuration
10
+ end
11
+
12
+ def execute!
13
+ verbose? ? @controller.render(verbose) : @controller.head(status)
14
+ end
15
+
16
+ private
17
+
18
+ def verbose?
19
+ @configuration.verbose
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthcheck
4
+ module Response
5
+ class Error < Base
6
+ def verbose
7
+ {
8
+ status: Healthcheck.configuration.error,
9
+ json: {
10
+ code: Healthcheck.configuration.error,
11
+ errors: @checker.errors.as_json
12
+ }
13
+ }
14
+ end
15
+
16
+ def status
17
+ @configuration.error
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Healthcheck
4
+ module Response
5
+ class Success < Base
6
+ def verbose
7
+ {
8
+ status: @configuration.success,
9
+ json: {
10
+ code: @configuration.success,
11
+ status: @configuration.checks.each_with_object({}) { |check, obj| obj[check.name] = 'OK' }
12
+ }
13
+ }
14
+ end
15
+
16
+ def status
17
+ @configuration.success
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Healthcheck
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-healthcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linqueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -166,6 +166,9 @@ files:
166
166
  - lib/healthcheck/configuration.rb
167
167
  - lib/healthcheck/engine.rb
168
168
  - lib/healthcheck/error.rb
169
+ - lib/healthcheck/response/base.rb
170
+ - lib/healthcheck/response/error.rb
171
+ - lib/healthcheck/response/success.rb
169
172
  - lib/healthcheck/router.rb
170
173
  - lib/healthcheck/version.rb
171
174
  - lib/rails-healthcheck.rb