rails-healthcheck 1.3.0 → 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 +36 -25
- data/app/controllers/healthcheck/healthchecks_controller.rb +9 -22
- data/lib/generators/healthcheck/install_generator.rb +2 -2
- data/lib/healthcheck.rb +14 -2
- 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 +5 -2
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,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
|
13
|
+
- [Verbose](#verbose)
|
15
14
|
- [Ignoring logs](#ignoring-logs)
|
16
15
|
- [Lograge](#lograge)
|
17
|
-
- [Datadog](#
|
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
|
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
|
85
|
+
### Verbose
|
86
|
+
|
87
|
+
You can enable verbose responses setting `config.verbose = true`.
|
87
88
|
|
88
|
-
|
89
|
+
- On success
|
89
90
|
|
90
91
|
```json
|
91
92
|
{
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
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
|
-
|
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,14 +1,14 @@
|
|
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
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
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
|