rails-healthcheck 1.1.3 → 1.4.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 +4 -4
- data/README.md +82 -66
- data/app/controllers/healthcheck/healthchecks_controller.rb +9 -21
- data/lib/generators/healthcheck/install_generator.rb +9 -3
- data/lib/healthcheck.rb +14 -2
- data/lib/healthcheck/configuration.rb +1 -1
- data/lib/healthcheck/response/base.rb +23 -0
- data/lib/healthcheck/response/error.rb +21 -0
- data/lib/healthcheck/response/success.rb +21 -0
- data/lib/healthcheck/version.rb +1 -1
- metadata +29 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5cf78b04593281cfd2e3018a79703e07aadc3d2a4ace5cc2d972f7ad083705
|
4
|
+
data.tar.gz: d0559dc632284d6f0a7f853632998973e6f2937974b1e20606a55851e1cd7c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e1c73e1314bd9731e0f81f4aa45364490e64b9fbdb3339b93506337c9778a76172347af086fe7cb834f5e5740cb63df9203968554685febaaf0e65e21c1e5b
|
7
|
+
data.tar.gz: 453b5a2ce77392ad5b1763d3e56b386d2a078c2fc3d9f950e30b673b331f1400a4f966228141de6cb2ee7a31eef09d022d68901abe2ff1e31c024867a6a13321
|
data/README.md
CHANGED
@@ -1,19 +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
|
-
[![Test Coverage][code_climate_test_coverage_image]][code_climate_test_coverage_page]
|
7
4
|
|
8
5
|
A simple way to configure a healthcheck route in Rails applications
|
9
6
|
|
10
7
|
## Table of Contents
|
8
|
+
|
11
9
|
- [Getting started](#getting-started)
|
12
10
|
- [Installation](#installation)
|
13
11
|
- [Settings](#settings)
|
14
|
-
- [
|
12
|
+
- [Custom Response](#custom-response)
|
13
|
+
- [Verbose](#verbose)
|
15
14
|
- [Ignoring logs](#ignoring-logs)
|
16
15
|
- [Lograge](#lograge)
|
16
|
+
- [Datadog](#datadog)
|
17
17
|
- [Requests Examples](#requests-examples)
|
18
18
|
- [Contributing](#contributing)
|
19
19
|
- [License](#license)
|
@@ -34,7 +34,7 @@ and run the command bellow to create the initializer:
|
|
34
34
|
rails generate healthcheck:install
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
### Settings
|
38
38
|
|
39
39
|
You can set the settings in the initializer file (_config/initializers/healthcheck.rb_):
|
40
40
|
|
@@ -48,41 +48,81 @@ Healthcheck.configure do |config|
|
|
48
48
|
config.route = '/healthcheck'
|
49
49
|
config.method = :get
|
50
50
|
|
51
|
+
# -- Custom Response --
|
52
|
+
# config.custom = lambda { |controller, checker|
|
53
|
+
# return controller.render(plain: 'Everything is awesome!') unless checker.errored?
|
54
|
+
# controller.verbose? ? controller.verbose_error(checker) : controller.head_error
|
55
|
+
# }
|
56
|
+
|
51
57
|
# -- Checks --
|
52
|
-
# config.add_check :database,
|
53
|
-
# config.add_check :migrations
|
54
|
-
# config.add_check :cache,
|
58
|
+
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
|
59
|
+
# config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
|
60
|
+
# config.add_check :cache, -> { Rails.cache.read('some_key') }
|
55
61
|
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
|
56
62
|
end
|
57
63
|
```
|
58
64
|
|
59
|
-
###
|
65
|
+
### Custom Response
|
66
|
+
|
67
|
+
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:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
Healthcheck.configure do |config|
|
71
|
+
# ...
|
72
|
+
|
73
|
+
# -- Custom Response --
|
74
|
+
config.custom = lambda { |controller, checker|
|
75
|
+
controller.render json: { field_name: 'my custom field value' } unless checker.errored?
|
76
|
+
...
|
77
|
+
}
|
78
|
+
|
79
|
+
# ...
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
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.
|
84
|
+
|
85
|
+
### Verbose
|
86
|
+
|
87
|
+
You can enable verbose responses setting `config.verbose = true`.
|
88
|
+
|
89
|
+
- On success
|
90
|
+
|
91
|
+
```json
|
92
|
+
{
|
93
|
+
"code": 200,
|
94
|
+
"status": {
|
95
|
+
"migrations": "OK",
|
96
|
+
"environments": "OK"
|
97
|
+
}
|
98
|
+
}
|
99
|
+
```
|
60
100
|
|
61
|
-
|
101
|
+
- On error
|
62
102
|
|
63
103
|
```json
|
64
104
|
{
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
+
]
|
78
118
|
}
|
79
119
|
```
|
80
120
|
|
81
121
|
## Ignoring logs
|
82
122
|
|
83
|
-
|
123
|
+
If you want to ignore Healthcheck request logs, you can use these options:
|
84
124
|
|
85
|
-
|
125
|
+
### [Lograge](https://github.com/roidrage/lograge)
|
86
126
|
|
87
127
|
```ruby
|
88
128
|
# config/environments/production.rb
|
@@ -93,6 +133,18 @@ Rails.application.configure do
|
|
93
133
|
end
|
94
134
|
```
|
95
135
|
|
136
|
+
### [Datadog](https://github.com/roidrage/lograge)
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# config/environments/production.rb
|
140
|
+
|
141
|
+
filter = Datadog::Pipeline::SpanFilter.new do |span|
|
142
|
+
span.name == 'rack.request' && span.get_tag('http.url') == Healthcheck.configuration.route
|
143
|
+
end
|
144
|
+
|
145
|
+
Datadog::Pipeline.before_flush(filter)
|
146
|
+
```
|
147
|
+
|
96
148
|
### Requests Examples
|
97
149
|
|
98
150
|
- Success
|
@@ -101,54 +153,22 @@ end
|
|
101
153
|
curl -i localhost:3000/healthcheck
|
102
154
|
|
103
155
|
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
156
|
```
|
116
157
|
|
117
158
|
- Error
|
159
|
+
|
118
160
|
```shell
|
119
161
|
curl -i localhost:3000/healthcheck
|
120
162
|
|
121
163
|
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
164
|
```
|
134
165
|
|
135
166
|
- Error (Verbose)
|
167
|
+
|
136
168
|
```shell
|
137
169
|
curl -i localhost:3000/healthcheck
|
138
170
|
|
139
171
|
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
172
|
{"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
|
153
173
|
```
|
154
174
|
|
@@ -172,11 +192,7 @@ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trac
|
|
172
192
|
[code_of_conduct_page]: https://github.com/linqueta/rails-healthcheck/blob/master/CODE_OF_CONDUCT.md
|
173
193
|
[mit_license_page]: https://opensource.org/licenses/MIT
|
174
194
|
[contributor_convenant_page]: http://contributor-covenant.org
|
175
|
-
[travis_status_image]: https://travis-ci.org/linqueta/rails-healthcheck.svg?branch=master
|
176
|
-
[travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
|
177
|
-
[code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
|
178
|
-
[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
195
|
[gem_version_image]: https://badge.fury.io/rb/rails-healthcheck.svg
|
182
|
-
[gem_version_page]: https://
|
196
|
+
[gem_version_page]: https://badge.fury.io/rb/rails-healthcheck
|
197
|
+
[checker_url]: https://github.com/linqueta/rails-healthcheck/blob/master/lib/healthcheck/checker.rb
|
198
|
+
[healthcheck_controller_url]: https://github.com/linqueta/rails-healthcheck/blob/master/app/controllers/healthcheck/healthchecks_controller.rb
|
@@ -1,31 +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
|
-
|
8
|
-
return head Healthcheck.configuration.success unless checker.errored?
|
9
|
-
|
10
|
-
verbose? ? verbose_error(checker) : head_error
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
8
|
+
return Healthcheck.custom!(self) if Healthcheck.custom?
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
code: Healthcheck.configuration.error,
|
23
|
-
errors: checker.errors.as_json
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
def verbose?
|
28
|
-
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!
|
29
17
|
end
|
30
18
|
end
|
31
19
|
end
|
@@ -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
|
+
# return controller.render(plain: 'Everything is awesome!') unless checker.errored?
|
24
|
+
# controller.verbose? ? controller.verbose_error(checker) : controller.head_error
|
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.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
|
-
|
29
|
+
Router.mount(router)
|
26
30
|
end
|
27
31
|
|
28
32
|
def check
|
29
|
-
|
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
|
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.4.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-05-16 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,14 +58,14 @@ 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
70
|
name: rspec-rails
|
57
71
|
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
|
@@ -152,6 +166,9 @@ files:
|
|
152
166
|
- lib/healthcheck/configuration.rb
|
153
167
|
- lib/healthcheck/engine.rb
|
154
168
|
- lib/healthcheck/error.rb
|
169
|
+
- lib/healthcheck/response/base.rb
|
170
|
+
- lib/healthcheck/response/error.rb
|
171
|
+
- lib/healthcheck/response/success.rb
|
155
172
|
- lib/healthcheck/router.rb
|
156
173
|
- lib/healthcheck/version.rb
|
157
174
|
- lib/rails-healthcheck.rb
|
@@ -159,7 +176,7 @@ homepage: https://github.com/linqueta/rails-healthcheck
|
|
159
176
|
licenses:
|
160
177
|
- MIT
|
161
178
|
metadata: {}
|
162
|
-
post_install_message:
|
179
|
+
post_install_message:
|
163
180
|
rdoc_options: []
|
164
181
|
require_paths:
|
165
182
|
- lib
|
@@ -175,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
192
|
version: '0'
|
176
193
|
requirements: []
|
177
194
|
rubygems_version: 3.1.2
|
178
|
-
signing_key:
|
195
|
+
signing_key:
|
179
196
|
specification_version: 4
|
180
197
|
summary: Healthcheck route for a Rails application
|
181
198
|
test_files: []
|