rails-healthcheck 1.1.2 → 1.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d25b4cf169226744a322cf74972627d1091753e66ba5fe6eec51f3bba7af225
|
4
|
+
data.tar.gz: 60fe9a9689b2c21e4cac94f5cc8baf6586720fe70bda3e2ea6cd1da2086983d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a73b3ae6bfe2395d17ef0867db9811e4db58cfa539c4cb9f8d97849b2555206c6b879e1cf82038175760a7a3378436c6daed1bf033df94f975548dd0da3f1fd6
|
7
|
+
data.tar.gz: a36bfef4ea3fca59937a309646f7bd4fc278b9571df00fa98929dd0048e63de6631afcf0264b255c3df8c8bbb1a22eade6bc8b107f1cd889c458812de91f98b4
|
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,9 +10,11 @@ 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)
|
17
|
+
- [Datadog](#lograge)
|
17
18
|
- [Requests Examples](#requests-examples)
|
18
19
|
- [Contributing](#contributing)
|
19
20
|
- [License](#license)
|
@@ -34,7 +35,7 @@ and run the command bellow to create the initializer:
|
|
34
35
|
rails generate healthcheck:install
|
35
36
|
```
|
36
37
|
|
37
|
-
|
38
|
+
### Settings
|
38
39
|
|
39
40
|
You can set the settings in the initializer file (_config/initializers/healthcheck.rb_):
|
40
41
|
|
@@ -48,14 +49,40 @@ Healthcheck.configure do |config|
|
|
48
49
|
config.route = '/healthcheck'
|
49
50
|
config.method = :get
|
50
51
|
|
52
|
+
# -- Custom Response --
|
53
|
+
# config.custom = lambda { |controller, checker|
|
54
|
+
# controller.render json: my_custom_response unless checker.errored?
|
55
|
+
# ...
|
56
|
+
# }
|
57
|
+
|
51
58
|
# -- Checks --
|
52
|
-
# config.add_check :database,
|
53
|
-
# config.add_check :migrations
|
54
|
-
# config.add_check :cache,
|
59
|
+
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
|
60
|
+
# config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
|
61
|
+
# config.add_check :cache, -> { Rails.cache.read('some_key') }
|
55
62
|
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
|
56
63
|
end
|
57
64
|
```
|
58
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
|
+
|
59
86
|
### Verbose Errors
|
60
87
|
|
61
88
|
When happen an error and verbose is enabled (`config.verbose = true`), the response will be like this:
|
@@ -80,9 +107,9 @@ When happen an error and verbose is enabled (`config.verbose = true`), the respo
|
|
80
107
|
|
81
108
|
## Ignoring logs
|
82
109
|
|
83
|
-
|
110
|
+
If you want to ignore Healthcheck request logs, you can use these options:
|
84
111
|
|
85
|
-
|
112
|
+
### [Lograge](https://github.com/roidrage/lograge)
|
86
113
|
|
87
114
|
```ruby
|
88
115
|
# config/environments/production.rb
|
@@ -93,6 +120,18 @@ Rails.application.configure do
|
|
93
120
|
end
|
94
121
|
```
|
95
122
|
|
123
|
+
### [Datadog](https://github.com/roidrage/lograge)
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
# config/environments/production.rb
|
127
|
+
|
128
|
+
filter = Datadog::Pipeline::SpanFilter.new do |span|
|
129
|
+
span.name == 'rack.request' && span.get_tag('http.url') == Healthcheck.configuration.route
|
130
|
+
end
|
131
|
+
|
132
|
+
Datadog::Pipeline.before_flush(filter)
|
133
|
+
```
|
134
|
+
|
96
135
|
### Requests Examples
|
97
136
|
|
98
137
|
- Success
|
@@ -101,17 +140,6 @@ end
|
|
101
140
|
curl -i localhost:3000/healthcheck
|
102
141
|
|
103
142
|
HTTP/1.1 200 OK
|
104
|
-
X-Frame-Options: SAMEORIGIN
|
105
|
-
X-XSS-Protection: 1; mode=block
|
106
|
-
X-Content-Type-Options: nosniff
|
107
|
-
X-Download-Options: noopen
|
108
|
-
X-Permitted-Cross-Domain-Policies: none
|
109
|
-
Referrer-Policy: strict-origin-when-cross-origin
|
110
|
-
Content-Type: text/html
|
111
|
-
Cache-Control: no-cache
|
112
|
-
X-Request-Id: cbc9fdd0-8090-4927-b061-1e82bcf2e039
|
113
|
-
X-Runtime: 0.003599
|
114
|
-
Transfer-Encoding: chunked
|
115
143
|
```
|
116
144
|
|
117
145
|
- Error
|
@@ -119,17 +147,6 @@ Transfer-Encoding: chunked
|
|
119
147
|
curl -i localhost:3000/healthcheck
|
120
148
|
|
121
149
|
HTTP/1.1 503 Service Unavailable
|
122
|
-
X-Frame-Options: SAMEORIGIN
|
123
|
-
X-XSS-Protection: 1; mode=block
|
124
|
-
X-Content-Type-Options: nosniff
|
125
|
-
X-Download-Options: noopen
|
126
|
-
X-Permitted-Cross-Domain-Policies: none
|
127
|
-
Referrer-Policy: strict-origin-when-cross-origin
|
128
|
-
Content-Type: text/html
|
129
|
-
Cache-Control: no-cache
|
130
|
-
X-Request-Id: e07eb20f-7d32-4f1a-86ad-32403de2b19a
|
131
|
-
X-Runtime: 0.033772
|
132
|
-
Transfer-Encoding: chunked
|
133
150
|
```
|
134
151
|
|
135
152
|
- Error (Verbose)
|
@@ -137,18 +154,6 @@ Transfer-Encoding: chunked
|
|
137
154
|
curl -i localhost:3000/healthcheck
|
138
155
|
|
139
156
|
HTTP/1.1 503 Service Unavailable
|
140
|
-
X-Frame-Options: SAMEORIGIN
|
141
|
-
X-XSS-Protection: 1; mode=block
|
142
|
-
X-Content-Type-Options: nosniff
|
143
|
-
X-Download-Options: noopen
|
144
|
-
X-Permitted-Cross-Domain-Policies: none
|
145
|
-
Referrer-Policy: strict-origin-when-cross-origin
|
146
|
-
Content-Type: application/json; charset=utf-8
|
147
|
-
Cache-Control: no-cache
|
148
|
-
X-Request-Id: 8fa5e69a-bfe3-4bbc-875b-ce86f4269467
|
149
|
-
X-Runtime: 0.019992
|
150
|
-
Transfer-Encoding: chunked
|
151
|
-
|
152
157
|
{"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
|
153
158
|
```
|
154
159
|
|
@@ -176,7 +181,7 @@ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trac
|
|
176
181
|
[travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
|
177
182
|
[code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
|
178
183
|
[code_climate_maintainability_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/maintainability
|
179
|
-
[code_climate_test_coverage_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/test_coverage
|
180
|
-
[code_climate_test_coverage_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/test_coverage
|
181
184
|
[gem_version_image]: https://badge.fury.io/rb/rails-healthcheck.svg
|
182
|
-
[gem_version_page]: https://
|
185
|
+
[gem_version_page]: https://badge.fury.io/rb/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
|
17
|
+
head Healthcheck.configuration.error
|
17
18
|
end
|
18
19
|
|
19
20
|
def verbose_error(checker)
|
@@ -4,8 +4,8 @@ require 'rails/generators/base'
|
|
4
4
|
|
5
5
|
module Healthcheck
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
|
+
desc 'It creates an initializer to set the healthcheck settings'
|
7
8
|
def create_initializer_file
|
8
|
-
desc 'It creates an initialize to set the healthcheck settings'
|
9
9
|
create_file(
|
10
10
|
'config/initializers/healthcheck.rb',
|
11
11
|
<<~HEALTHCHECK_INITIALIZER_TEXT
|
@@ -18,10 +18,16 @@ 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
|
-
# config.add_check :database,
|
23
|
-
# config.add_check :migrations
|
24
|
-
# config.add_check :cache,
|
28
|
+
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
|
29
|
+
# config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
|
30
|
+
# config.add_check :cache, -> { Rails.cache.read('some_key') }
|
25
31
|
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
|
26
32
|
end
|
27
33
|
HEALTHCHECK_INITIALIZER_TEXT
|
data/lib/healthcheck/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-healthcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -44,28 +58,28 @@ dependencies:
|
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '13.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '13.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
70
|
+
name: rspec-rails
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +112,16 @@ dependencies:
|
|
98
112
|
name: simplecov
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- - "
|
115
|
+
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.17.
|
117
|
+
version: 0.17.1
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- - "
|
122
|
+
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.17.
|
124
|
+
version: 0.17.1
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: simplecov-console
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: 0.5.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
description: A simple way to configure a healthcheck route for a Rails application
|
126
154
|
email:
|
127
155
|
- lincolnrodrs@gmail.com
|
@@ -145,7 +173,7 @@ homepage: https://github.com/linqueta/rails-healthcheck
|
|
145
173
|
licenses:
|
146
174
|
- MIT
|
147
175
|
metadata: {}
|
148
|
-
post_install_message:
|
176
|
+
post_install_message:
|
149
177
|
rdoc_options: []
|
150
178
|
require_paths:
|
151
179
|
- lib
|
@@ -160,9 +188,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
188
|
- !ruby/object:Gem::Version
|
161
189
|
version: '0'
|
162
190
|
requirements: []
|
163
|
-
|
164
|
-
|
165
|
-
signing_key:
|
191
|
+
rubygems_version: 3.1.2
|
192
|
+
signing_key:
|
166
193
|
specification_version: 4
|
167
194
|
summary: Healthcheck route for a Rails application
|
168
195
|
test_files: []
|