rails-healthcheck 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22fb393936d02fef7c715773678079e8bd55dda200a2691b09c6ef1e5bd8d16e
4
- data.tar.gz: 4922a32a61ab5099aeedd14087a5b76567a34b41acec65a79b7dd7cde093ecb9
3
+ metadata.gz: eb62ca798614c3adf6326d3b15cac4dd404f177d1dc5ad5f491938f2e3534530
4
+ data.tar.gz: 531f13e1c8cf658a26e85569e3d72b47b38498a17843cc0c28722c757369d929
5
5
  SHA512:
6
- metadata.gz: 3f0967885d9c1f473ba3c0aedc951430f766f76da7e74da2cdb5301801f62fd52c631a1bb2d4cac6d009a41d2c1fe15a5cc22c582b1edeb5c4543b9c83d7c445
7
- data.tar.gz: 513bb01b1d0c3dc472fd96d935eeb70bd26ffec2295a001ed2737228a04d0c0b9c7753eb3737d9eba18b5352cee737dee273dc7b0e7bf309abd0244538d4190f
6
+ metadata.gz: 0c347e99945ed94ce23ee3c4e4c9250b12da9381aa371392ff08e8bd5d247e72179f38f1c57edb1a51008cb113e22e6029795b8c5e22d31a620f30c133085837
7
+ data.tar.gz: a40b7c53c042fa550507fd3d9102eaf4ffb0ec84503f538976a7463c435832d18a0be1816683b9a2157c657c100a09847572ec9864762d454074e987599bc9d4
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version][gem_version_image]][gem_version_page]
4
4
  [![Build Status][travis_status_image]][travis_page]
5
5
  [![Maintainability][code_climate_maintainability_image]][code_climate_maintainability_page]
6
- [![Test Coverage][code_climate_test_coverage_image]][code_climate_test_coverage_page]
7
6
 
8
7
  A simple way to configure a healthcheck route in Rails applications
9
8
 
@@ -11,6 +10,7 @@ A simple way to configure a healthcheck route in Rails applications
11
10
  - [Getting started](#getting-started)
12
11
  - [Installation](#installation)
13
12
  - [Settings](#settings)
13
+ - [Custom Response](#custom-response)
14
14
  - [Verbose Errors](#verbose-errors)
15
15
  - [Ignoring logs](#ignoring-logs)
16
16
  - [Lograge](#lograge)
@@ -35,7 +35,7 @@ and run the command bellow to create the initializer:
35
35
  rails generate healthcheck:install
36
36
  ```
37
37
 
38
- ## Settings
38
+ ### Settings
39
39
 
40
40
  You can set the settings in the initializer file (_config/initializers/healthcheck.rb_):
41
41
 
@@ -49,6 +49,12 @@ Healthcheck.configure do |config|
49
49
  config.route = '/healthcheck'
50
50
  config.method = :get
51
51
 
52
+ # -- Custom Response --
53
+ # config.custom = lambda { |controller, checker|
54
+ # controller.render json: my_custom_response unless checker.errored?
55
+ # ...
56
+ # }
57
+
52
58
  # -- Checks --
53
59
  # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
54
60
  # config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
@@ -57,6 +63,26 @@ Healthcheck.configure do |config|
57
63
  end
58
64
  ```
59
65
 
66
+ ### Custom Response
67
+
68
+ You can override the configs `success`, `error` and `verbose` and write your custom behaviour for the healthcheck api using the field `custom` in the initializer:
69
+
70
+ ```ruby
71
+ Healthcheck.configure do |config|
72
+ # ...
73
+
74
+ # -- Custom Response --
75
+ config.custom = lambda { |controller, checker|
76
+ controller.render json: { field_name: 'my custom field value' } unless checker.errored?
77
+ ...
78
+ }
79
+
80
+ # ...
81
+ end
82
+ ```
83
+
84
+ 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
+
60
86
  ### Verbose Errors
61
87
 
62
88
  When happen an error and verbose is enabled (`config.verbose = true`), the response will be like this:
@@ -114,17 +140,6 @@ Datadog::Pipeline.before_flush(filter)
114
140
  curl -i localhost:3000/healthcheck
115
141
 
116
142
  HTTP/1.1 200 OK
117
- X-Frame-Options: SAMEORIGIN
118
- X-XSS-Protection: 1; mode=block
119
- X-Content-Type-Options: nosniff
120
- X-Download-Options: noopen
121
- X-Permitted-Cross-Domain-Policies: none
122
- Referrer-Policy: strict-origin-when-cross-origin
123
- Content-Type: text/html
124
- Cache-Control: no-cache
125
- X-Request-Id: cbc9fdd0-8090-4927-b061-1e82bcf2e039
126
- X-Runtime: 0.003599
127
- Transfer-Encoding: chunked
128
143
  ```
129
144
 
130
145
  - Error
@@ -132,17 +147,6 @@ Transfer-Encoding: chunked
132
147
  curl -i localhost:3000/healthcheck
133
148
 
134
149
  HTTP/1.1 503 Service Unavailable
135
- X-Frame-Options: SAMEORIGIN
136
- X-XSS-Protection: 1; mode=block
137
- X-Content-Type-Options: nosniff
138
- X-Download-Options: noopen
139
- X-Permitted-Cross-Domain-Policies: none
140
- Referrer-Policy: strict-origin-when-cross-origin
141
- Content-Type: text/html
142
- Cache-Control: no-cache
143
- X-Request-Id: e07eb20f-7d32-4f1a-86ad-32403de2b19a
144
- X-Runtime: 0.033772
145
- Transfer-Encoding: chunked
146
150
  ```
147
151
 
148
152
  - Error (Verbose)
@@ -150,18 +154,6 @@ Transfer-Encoding: chunked
150
154
  curl -i localhost:3000/healthcheck
151
155
 
152
156
  HTTP/1.1 503 Service Unavailable
153
- X-Frame-Options: SAMEORIGIN
154
- X-XSS-Protection: 1; mode=block
155
- X-Content-Type-Options: nosniff
156
- X-Download-Options: noopen
157
- X-Permitted-Cross-Domain-Policies: none
158
- Referrer-Policy: strict-origin-when-cross-origin
159
- Content-Type: application/json; charset=utf-8
160
- Cache-Control: no-cache
161
- X-Request-Id: 8fa5e69a-bfe3-4bbc-875b-ce86f4269467
162
- X-Runtime: 0.019992
163
- Transfer-Encoding: chunked
164
-
165
157
  {"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
166
158
  ```
167
159
 
@@ -189,7 +181,7 @@ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trac
189
181
  [travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
190
182
  [code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
191
183
  [code_climate_maintainability_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/maintainability
192
- [code_climate_test_coverage_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/test_coverage
193
- [code_climate_test_coverage_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/test_coverage
194
184
  [gem_version_image]: https://badge.fury.io/rb/rails-healthcheck.svg
195
185
  [gem_version_page]: https://rubygems.org/gems/rails-healthcheck
186
+ [checker_url]: https://github.com/linqueta/rails-healthcheck/blob/master/lib/healthcheck/checker.rb
187
+ [healthcheck_controller_url]: https://github.com/linqueta/rails-healthcheck/blob/master/app/controllers/healthcheck/healthchecks_controller.rb
@@ -5,6 +5,7 @@ module Healthcheck
5
5
  class HealthchecksController < ActionController::Base
6
6
  def check
7
7
  checker = Healthcheck.check
8
+ return Healthcheck.configuration.custom.call(self, checker) if Healthcheck.configuration.custom
8
9
  return head Healthcheck.configuration.success unless checker.errored?
9
10
 
10
11
  verbose? ? verbose_error(checker) : head_error
@@ -13,7 +14,7 @@ module Healthcheck
13
14
  private
14
15
 
15
16
  def head_error
16
- head(Healthcheck.configuration.error)
17
+ head Healthcheck.configuration.error
17
18
  end
18
19
 
19
20
  def verbose_error(checker)
@@ -18,6 +18,12 @@ module Healthcheck
18
18
  config.route = '/healthcheck'
19
19
  config.method = :get
20
20
 
21
+ # -- Custom Response --
22
+ # config.custom = lambda { |controller, checker|
23
+ # controller.render json: my_custom_response unless checker.errored?
24
+ # ...
25
+ # }
26
+
21
27
  # -- Checks --
22
28
  # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
23
29
  # config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Healthcheck
4
4
  class Configuration
5
- SETTINGS = %i[success error verbose route method checks].freeze
5
+ SETTINGS = %i[success error verbose route method checks custom].freeze
6
6
 
7
7
  attr_accessor(*SETTINGS)
8
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Healthcheck
4
- VERSION = '1.1.5'
4
+ VERSION = '1.2.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.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linqueta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-27 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.17.0
103
+ version: 0.17.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.17.0
110
+ version: 0.17.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov-console
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,7 @@ homepage: https://github.com/linqueta/rails-healthcheck
159
159
  licenses:
160
160
  - MIT
161
161
  metadata: {}
162
- post_install_message:
162
+ post_install_message:
163
163
  rdoc_options: []
164
164
  require_paths:
165
165
  - lib
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubygems_version: 3.1.2
178
- signing_key:
178
+ signing_key:
179
179
  specification_version: 4
180
180
  summary: Healthcheck route for a Rails application
181
181
  test_files: []