rack-ecg 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/{main.yml → test.yml} +3 -3
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -3
- data/Gemfile +2 -1
- data/README.md +110 -60
- data/Rakefile +4 -3
- data/docker-compose.yml +18 -0
- data/examples/basic.ru +3 -2
- data/examples/checks.ru +3 -2
- data/examples/git_revision_check_replacement.ru +28 -0
- data/examples/hook.ru +3 -3
- data/examples/mounted_path.ru +3 -2
- data/examples/parameters.ru +7 -6
- data/examples/stand_alone.ru +2 -1
- data/lib/rack/ecg/check/active_record_connection.rb +1 -0
- data/lib/rack/ecg/check/error.rb +12 -3
- data/lib/rack/ecg/check/git_revision.rb +5 -0
- data/lib/rack/ecg/check/http.rb +12 -3
- data/lib/rack/ecg/check/migration_version.rb +1 -0
- data/lib/rack/ecg/check/redis_connection.rb +15 -5
- data/lib/rack/ecg/check/sequel_connection.rb +2 -1
- data/lib/rack/ecg/check/static.rb +52 -0
- data/lib/rack/ecg/check.rb +3 -1
- data/lib/rack/ecg/check_factory.rb +1 -0
- data/lib/rack/ecg/check_registry.rb +1 -0
- data/lib/rack/ecg/version.rb +2 -1
- data/lib/rack/ecg.rb +1 -0
- data/lib/rack-ecg.rb +2 -1
- data/rack-ecg.gemspec +10 -8
- metadata +64 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d08e1fb5c31c7f5883cbf1b698b207ce837980d511f35f7d7c32300067d5c4
|
4
|
+
data.tar.gz: 88688776e3d95f7b040b0701d9955830bfa833c6ec44e8bcf6a1ce647a30d7a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c0db20e6bf5cfab2e64252ecce8d6f38a240d6356813929a134c8b1dc7fec25cb663b756230b9b81087fef1cef05c196be31258b699181b210a0c75877651b
|
7
|
+
data.tar.gz: e77ddb23c3b406fb3e51621364a38be99e3ef5fdb3a0fb91fb850fa21add92415a0e1e47539619fa5c148701eb076782d3de555ef63de15ec7286e48388e983e
|
@@ -1,4 +1,4 @@
|
|
1
|
-
name:
|
1
|
+
name: test
|
2
2
|
|
3
3
|
on: [push,pull_request]
|
4
4
|
|
@@ -6,7 +6,7 @@ jobs:
|
|
6
6
|
test:
|
7
7
|
strategy:
|
8
8
|
matrix:
|
9
|
-
ruby: [2.
|
9
|
+
ruby: ["2.6", "2.7", "3.0", "3.1"]
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
name: Test (Ruby ${{ matrix.ruby }})
|
12
12
|
steps:
|
@@ -17,6 +17,6 @@ jobs:
|
|
17
17
|
ruby-version: ${{ matrix.ruby }}
|
18
18
|
- name: Run the default task
|
19
19
|
run: |
|
20
|
-
gem install bundler -v 2.
|
20
|
+
gem install bundler -v 2.3.7
|
21
21
|
bundle install
|
22
22
|
bundle exec rake
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.9
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [0.2.0] - 2022-02-21
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- The `static` check, which uses the provided check parameters to return the same result every time.
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- **Breaking**: The Redis check now requires being configured with an instance of the Redis client, via the named `instance` parameter
|
17
|
+
- **Deprecated**: The `git_revision` check will be removed in rack-ecg version 1.0.0. For a suggested replacement, [see the GitRevision Check Replacement example](./examples/gitrevision_check_replacement.ru), which uses the `static` check to memoize the value.
|
18
|
+
|
19
|
+
### Removed
|
20
|
+
|
21
|
+
- **Breaking:** Dropped support for Ruby versions < 2.6.0
|
22
|
+
|
8
23
|
## [0.1.0] - 2020-12-16
|
9
24
|
|
10
25
|
### Added
|
@@ -59,11 +74,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
59
74
|
- `git_revision` check to return the current git revision
|
60
75
|
- `migration_version` check to return the current ActiveRecord migration version
|
61
76
|
|
62
|
-
[Unreleased]: https://github.com/envato/rack-ecg/compare/v0.
|
63
|
-
[0.
|
77
|
+
[Unreleased]: https://github.com/envato/rack-ecg/compare/v0.2.0...HEAD
|
78
|
+
[0.2.0]: https://github.com/envato/rack-ecg/compare/v0.1.0...v0.2.0
|
79
|
+
[0.1.0]: https://github.com/envato/rack-ecg/compare/v0.0.5...v0.1.0
|
64
80
|
[0.0.5]: https://github.com/envato/rack-ecg/compare/v0.0.4...v0.0.5
|
65
81
|
[0.0.4]: https://github.com/envato/rack-ecg/compare/v0.0.3...v0.0.4
|
66
82
|
[0.0.3]: https://github.com/envato/rack-ecg/compare/v0.0.2...v0.0.3
|
67
83
|
[0.0.2]: https://github.com/envato/rack-ecg/compare/v0.0.1...v0.0.2
|
68
84
|
[0.0.1]: https://github.com/envato/rack-ecg/releases/tag/v0.0.1
|
69
|
-
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ check endpoint, with minimal configuration.
|
|
17
17
|
|
18
18
|
## Development Status
|
19
19
|
|
20
|
-
[![Build Status](https://github.com/envato/rack-ecg/workflows/
|
20
|
+
[![Build Status](https://github.com/envato/rack-ecg/workflows/test/badge.svg?branch=main)](https://github.com/envato/rack-ecg/actions?query=branch%3Amain)
|
21
21
|
|
22
22
|
`Rack::ECG` is extracted from production code in use at
|
23
23
|
[Envato](http://envato.com). However, it is undergoing early development, and
|
@@ -28,7 +28,7 @@ APIs and features are almost certain to be in flux.
|
|
28
28
|
Add this to your application's `Gemfile`:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
gem 'rack-ecg', '~> 0.0
|
31
|
+
gem 'rack-ecg', '~> 0.2.0`
|
32
32
|
```
|
33
33
|
|
34
34
|
Then run `bundle install`.
|
@@ -73,99 +73,149 @@ status if any of the checks fail.
|
|
73
73
|
|
74
74
|
## Configuration
|
75
75
|
|
76
|
-
There are options that can be passed to `use Rack::ECG` to customise how it
|
77
|
-
works.
|
76
|
+
There are options that can be passed to `use Rack::ECG` to customise how it works.
|
78
77
|
|
79
|
-
###
|
80
|
-
Out of the box `Rack::ECG` doesn't do much and just checks that
|
81
|
-
HTTP responses can be returned. There are a number of built in checks that
|
82
|
-
`Rack::ECG` can be told to do (more to come)
|
83
|
-
- `:git_revision` - this assumes your code is deployed via git and exists in a
|
84
|
-
git repo, and that the `git` command can access it
|
85
|
-
- `:migration_version` - this assumes you are using ActiveRecord migrations. It
|
86
|
-
queries the `schema_versions` table and tells you what version the database is
|
87
|
-
at.
|
88
|
-
- `:active_record` - this checks if an ActiveRecord connection is active.
|
89
|
-
- `:redis` - this checks if a Redis connection is active.
|
78
|
+
### Checks
|
90
79
|
|
91
|
-
|
80
|
+
By default, `Rack::ECG` indicates that the service is reponsive via a `http` check. Additional checks are included in this gem, and can be enabled by passing their configuration to the `checks` parameter. To enable a check, add its name, and optionally configuration, to the `checks` array:
|
92
81
|
|
93
82
|
```ruby
|
94
|
-
use Rack::ECG, checks: [
|
83
|
+
use Rack::ECG, checks: [
|
84
|
+
# no configuration required, or allowed
|
85
|
+
:http,
|
86
|
+
# passing configuration options
|
87
|
+
[:static, { name: "app", value: "my-cool-app" }],
|
88
|
+
# some checks can be used multiple times
|
89
|
+
[:static, { name: "env", value: Rails.env }],
|
90
|
+
]
|
95
91
|
```
|
96
92
|
|
93
|
+
#### `active_record`
|
94
|
+
|
95
|
+
Requires a configured ActiveRecord connection. Does not support configuration. Indicates whether the connection to the default database is currently open. On success, returns something in the following format:
|
96
|
+
|
97
|
+
```json
|
98
|
+
{
|
99
|
+
"active_record": {
|
100
|
+
"status": "ok",
|
101
|
+
"value": true
|
102
|
+
}
|
103
|
+
}
|
97
104
|
```
|
98
|
-
|
105
|
+
|
106
|
+
#### `error`
|
107
|
+
|
108
|
+
Does not support configuration. Always returns the following:
|
109
|
+
|
110
|
+
```json
|
111
|
+
{
|
112
|
+
"error": {
|
113
|
+
"status": "error",
|
114
|
+
"value": "PC LOAD ERROR"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
#### `git_revision`
|
120
|
+
|
121
|
+
**Deprecated**: will be removed in version 1.0.0. [See the GitRevision Check Replacement example](./examples/git_revision_check_replacement.ru), which uses the `static` check to memoize the value.
|
122
|
+
|
123
|
+
Requires the `git` executable on path, and that the application's working directory is within a Git repository. Does not support configuration. On success, returns something in the following format:
|
124
|
+
|
125
|
+
```json
|
126
|
+
{
|
127
|
+
"git_revision": {
|
128
|
+
"status": "ok",
|
129
|
+
"value": "dc840f9d5563e6e5a8b34da29c298764e3046039"
|
130
|
+
}
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
#### `http`
|
135
|
+
|
136
|
+
Automatically included, and does not support configuration. Always returns the following:
|
137
|
+
|
138
|
+
```json
|
99
139
|
{
|
100
140
|
"http": {
|
101
141
|
"status": "ok",
|
102
142
|
"value": "online"
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
143
|
+
}
|
144
|
+
}
|
145
|
+
```
|
146
|
+
|
147
|
+
#### `migration_version`
|
148
|
+
|
149
|
+
Requires a configured ActiveRecord connection, and that ActiveRecord migrations are in use. Does not support configuration. Queries the `schema_versions` table on the default database to report the current migration version. On success, returns something in the following format:
|
150
|
+
|
151
|
+
```json
|
152
|
+
{
|
108
153
|
"migration_version": {
|
109
154
|
"status": "ok",
|
110
|
-
"value": "
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
155
|
+
"value": "20210506024055"
|
156
|
+
}
|
157
|
+
}
|
158
|
+
```
|
159
|
+
|
160
|
+
#### `redis`
|
161
|
+
|
162
|
+
Requires the Redis gem. Requires configuration, an instance of a Redis client. Indicates whether the Redis client passed in is currently connected to the Redis database. On success, returns something in the following format:
|
163
|
+
|
164
|
+
```json
|
165
|
+
{
|
116
166
|
"redis": {
|
117
167
|
"status": "ok",
|
118
|
-
"value":
|
168
|
+
"value": true
|
119
169
|
}
|
120
170
|
}
|
121
171
|
```
|
122
172
|
|
123
|
-
####
|
124
|
-
|
173
|
+
#### `sequel`
|
174
|
+
|
175
|
+
Requires the Sequel gem. Requires configuration, and can be configured multiple times. Indicates whether a (new) connection can be established to the configured Sequel database.
|
176
|
+
|
177
|
+
Given the following configuration:
|
125
178
|
|
126
179
|
```ruby
|
127
|
-
|
180
|
+
{
|
181
|
+
connection: "sqlite://events.db",
|
182
|
+
name: "events", # must be unique per sequel check
|
183
|
+
}
|
128
184
|
```
|
129
185
|
|
130
|
-
|
131
|
-
|
186
|
+
Returns the something in the following format on success:
|
187
|
+
|
188
|
+
```json
|
132
189
|
{
|
133
|
-
"
|
134
|
-
"status": "ok",
|
135
|
-
"value": "online"
|
136
|
-
},
|
137
|
-
"sequel": {
|
190
|
+
"sequel_events": {
|
138
191
|
"status": "ok",
|
139
|
-
"value":
|
192
|
+
"value": true
|
140
193
|
}
|
141
194
|
}
|
142
195
|
```
|
143
196
|
|
144
|
-
|
197
|
+
#### `static`
|
198
|
+
|
199
|
+
Returns the same value every time. Requires configuration, and can be configured multiple times.
|
200
|
+
|
201
|
+
Given the following configuration:
|
145
202
|
|
146
203
|
```ruby
|
147
|
-
|
148
|
-
:
|
149
|
-
|
150
|
-
|
151
|
-
]
|
204
|
+
{
|
205
|
+
name: "image_build_url", # must be unique per static check
|
206
|
+
success: true, # default value
|
207
|
+
status: Rack::ECG::Check::Status::OK, # optional, overrides `success`
|
208
|
+
value: ENV["IMAGE_BUILD_URL"],
|
209
|
+
}
|
152
210
|
```
|
153
211
|
|
154
|
-
|
155
|
-
$ curl http://localhost:9292/_ecg
|
212
|
+
Returns the something in the following format:
|
156
213
|
|
214
|
+
```json
|
157
215
|
{
|
158
|
-
"
|
159
|
-
"status": "ok",
|
160
|
-
"value": "online"
|
161
|
-
},
|
162
|
-
"sequel_events": {
|
163
|
-
"status": "ok",
|
164
|
-
"value": "true"
|
165
|
-
},
|
166
|
-
"sequel_projections": {
|
216
|
+
"image_build_url": {
|
167
217
|
"status": "ok",
|
168
|
-
"value": "
|
218
|
+
"value": "https://example.com/pipelines/my-cool-app/builds/1234"
|
169
219
|
}
|
170
220
|
}
|
171
221
|
```
|
@@ -195,7 +245,7 @@ More examples are provided in [/examples](https://github.com/envato/rack-ecg/tre
|
|
195
245
|
|
196
246
|
## Requirements
|
197
247
|
|
198
|
-
- Ruby >= 2.
|
248
|
+
- Ruby >= 2.6
|
199
249
|
- Rack
|
200
250
|
- To use optional `git_revision` check, your deployed code needs to be in a git repo, and
|
201
251
|
`git` command must be accessible on the server
|
data/Rakefile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "bundler/gem_tasks"
|
3
4
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "rubocop/rake_task"
|
7
|
+
require "yard"
|
7
8
|
|
8
9
|
RSpec::Core::RakeTask.new(:spec)
|
9
10
|
RuboCop::RakeTask.new(:rubocop)
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# for running tests across different versions locally
|
2
|
+
|
3
|
+
version: "3"
|
4
|
+
services:
|
5
|
+
ruby30: &ruby30
|
6
|
+
image: ruby:3.0
|
7
|
+
volumes:
|
8
|
+
- ./:/app
|
9
|
+
command: bash -c 'gem update --system && cd /app && { ! [ -f Gemfile.lock ] || rm Gemfile.lock; } && bundle install && bundle exec rake'
|
10
|
+
ruby27:
|
11
|
+
<<: *ruby30
|
12
|
+
image: ruby:2.7
|
13
|
+
ruby26:
|
14
|
+
<<: *ruby30
|
15
|
+
image: ruby:2.6
|
16
|
+
ruby25:
|
17
|
+
<<: *ruby30
|
18
|
+
image: ruby:2.5
|
data/examples/basic.ru
CHANGED
data/examples/checks.ru
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/ecg"
|
4
|
+
|
5
|
+
# This example behaves just like the deprecated GitRevision check, except that the value is memoized.
|
6
|
+
# i.e. "Fetching the git revision" shouldn't show up for every `GET /_ecg` request.
|
7
|
+
#
|
8
|
+
# Also consider writing the git revision to a file, or storing it in an environment variable, so it can found more
|
9
|
+
# efficiently and with fewer dependencies.
|
10
|
+
|
11
|
+
def git_revision
|
12
|
+
puts "Fetching the git revision"
|
13
|
+
|
14
|
+
_stdin, stdout, stderr, wait_thread = Open3.popen3("git rev-parse HEAD")
|
15
|
+
|
16
|
+
success = wait_thread.value.success?
|
17
|
+
|
18
|
+
status = success ? Rack::ECG::Check::Status::OK : Rack::ECG::Check::Status::ERROR
|
19
|
+
|
20
|
+
value = success ? stdout.read : stderr.read
|
21
|
+
value = value.strip
|
22
|
+
|
23
|
+
{ name: :git_revision, status: status, value: value }
|
24
|
+
end
|
25
|
+
|
26
|
+
use(Rack::ECG, { checks: [[:static, git_revision]] })
|
27
|
+
|
28
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
data/examples/hook.ru
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rack/ecg"
|
4
4
|
|
5
5
|
log_check_results = proc do |success, checks|
|
6
6
|
next if success
|
7
7
|
|
8
8
|
checks.each do |check_name, check_status|
|
9
|
-
next unless check_status[:status] ==
|
9
|
+
next unless check_status[:status] == "error"
|
10
10
|
|
11
11
|
puts "Check #{check_name} failed: #{check_status[:value]}"
|
12
12
|
end
|
@@ -14,4 +14,4 @@ end
|
|
14
14
|
|
15
15
|
use(Rack::ECG, checks: [:git_revision, :migration_version], hook: log_check_results)
|
16
16
|
|
17
|
-
run(->(_env) { [200, {}, [
|
17
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
data/examples/mounted_path.ru
CHANGED
data/examples/parameters.ru
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
2
|
+
|
3
|
+
require "rack/ecg"
|
4
|
+
require "sequel"
|
5
|
+
require "sqlite3"
|
5
6
|
|
6
7
|
use(Rack::ECG, checks: [
|
7
8
|
:http,
|
8
|
-
[:sequel, { connection:
|
9
|
-
[:sequel, { connection:
|
9
|
+
[:sequel, { connection: "sqlite://events.db", name: "events" }],
|
10
|
+
[:sequel, { connection: "sqlite://projections.db", name: "projections" }],
|
10
11
|
])
|
11
12
|
|
12
|
-
run(->
|
13
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
data/examples/stand_alone.ru
CHANGED
data/lib/rack/ecg/check/error.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./static"
|
4
|
+
|
2
5
|
module Rack
|
3
6
|
class ECG
|
4
7
|
module Check
|
5
8
|
# @!method initialize
|
6
9
|
# Always returns a basic error for testing purposes.
|
7
|
-
class Error
|
8
|
-
|
9
|
-
|
10
|
+
class Error < Static
|
11
|
+
STATIC_PARAMETERS = {
|
12
|
+
name: :error,
|
13
|
+
success: false,
|
14
|
+
value: "PC LOAD LETTER",
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super(STATIC_PARAMETERS)
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
@@ -1,7 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Rack
|
3
4
|
class ECG
|
4
5
|
module Check
|
6
|
+
# @deprecated This check requires the presence of the git executable, and executes it every time to determine the
|
7
|
+
# current revision. Consider checking the revision at initialization time, and returning it via a {Static} check
|
8
|
+
# instead.
|
9
|
+
#
|
5
10
|
# @!method initialize
|
6
11
|
# Returns the SHA1 of the current commit, as reported by the git
|
7
12
|
# executable.
|
data/lib/rack/ecg/check/http.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./static"
|
4
|
+
|
2
5
|
module Rack
|
3
6
|
class ECG
|
4
7
|
module Check
|
5
8
|
# @!method initialize
|
6
9
|
# Always returns a success.
|
7
|
-
class Http
|
8
|
-
|
9
|
-
|
10
|
+
class Http < Static
|
11
|
+
STATIC_PARAMETERS = {
|
12
|
+
name: :http,
|
13
|
+
success: true,
|
14
|
+
value: "online",
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super(STATIC_PARAMETERS)
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
@@ -1,19 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Rack
|
3
4
|
class ECG
|
4
5
|
module Check
|
5
6
|
# @!method initialize
|
6
|
-
# Checks whether the
|
7
|
-
# database.
|
7
|
+
# Checks whether the given Redis client is currently connected to the
|
8
|
+
# database as identified by the ++instance++ option.
|
8
9
|
#
|
9
|
-
#
|
10
|
+
# @option parameters instance [Redis] The Redis client
|
10
11
|
class RedisConnection
|
12
|
+
attr_reader :redis_instance
|
13
|
+
|
14
|
+
def initialize(parameters = {})
|
15
|
+
@redis_instance = parameters[:instance]
|
16
|
+
end
|
17
|
+
|
11
18
|
def result
|
12
19
|
value = ""
|
13
20
|
status = Status::OK
|
14
21
|
begin
|
15
|
-
if
|
16
|
-
|
22
|
+
if redis_instance.nil?
|
23
|
+
status = Status::ERROR
|
24
|
+
value = "Redis instance parameters not found"
|
25
|
+
elsif defined?(::Redis)
|
26
|
+
value = redis_instance.connected?
|
17
27
|
status = value ? Status::OK : Status::ERROR
|
18
28
|
else
|
19
29
|
status = Status::ERROR
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Rack
|
3
4
|
class ECG
|
4
5
|
module Check
|
@@ -41,7 +42,7 @@ module Rack
|
|
41
42
|
|
42
43
|
def result_key
|
43
44
|
if name
|
44
|
-
"sequel #{name.downcase}".gsub(/\W+/,
|
45
|
+
"sequel #{name.downcase}".gsub(/\W+/, "_")
|
45
46
|
else
|
46
47
|
"sequel"
|
47
48
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class ECG
|
5
|
+
module Check
|
6
|
+
class Static
|
7
|
+
# Always returns the provided ++value++ under the ++name++ key, with the result set by ++status++.
|
8
|
+
#
|
9
|
+
# @example Return "Hello, world!" under ++static++
|
10
|
+
# use(Rack::ECG, { checks: [[:static, { value: "Hello, world!" }]] })
|
11
|
+
#
|
12
|
+
# @example Return "Paper jam in tray 2" as an error under ++printer_status++
|
13
|
+
# use(Rack::ECG, {
|
14
|
+
# checks: [
|
15
|
+
# [
|
16
|
+
# :static,
|
17
|
+
# {
|
18
|
+
# value: "Paper jam in tray 2",
|
19
|
+
# success: false, # or status: Rack::ECG::Check::Status::ERROR
|
20
|
+
# name: :printer_status,
|
21
|
+
# },
|
22
|
+
# ],
|
23
|
+
# ],
|
24
|
+
# })
|
25
|
+
#
|
26
|
+
# @option parameters value [Object] (nil) Result value
|
27
|
+
# @option parameters status [Status::ERROR, Status::OK, nil] (nil) Result status (takes precedence over
|
28
|
+
# ++success++)
|
29
|
+
# @option parameters success [Boolean] (true) Whether the result is successful
|
30
|
+
# @option parameters name [Symbol, #to_sym] (:static) Key for the check result in the response
|
31
|
+
def initialize(parameters)
|
32
|
+
parameters ||= {}
|
33
|
+
|
34
|
+
@name = parameters.fetch(:name, :static).to_sym
|
35
|
+
@value = parameters.fetch(:value, nil)
|
36
|
+
|
37
|
+
@status = if parameters.key?(:status)
|
38
|
+
parameters[:status]
|
39
|
+
else
|
40
|
+
parameters.fetch(:success, true) ? Status::OK : Status::ERROR
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def result
|
45
|
+
Result.new(@name, @status, @value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
CheckRegistry.instance.register(:static, Static)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/rack/ecg/check.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "rack/ecg/check_registry"
|
4
|
+
require "rack/ecg/check/active_record_connection"
|
3
5
|
require "rack/ecg/check/error"
|
4
6
|
require "rack/ecg/check/git_revision"
|
5
7
|
require "rack/ecg/check/http"
|
6
8
|
require "rack/ecg/check/migration_version"
|
7
|
-
require "rack/ecg/check/active_record_connection"
|
8
9
|
require "rack/ecg/check/redis_connection"
|
9
10
|
require "rack/ecg/check/sequel_connection"
|
11
|
+
require "rack/ecg/check/static"
|
10
12
|
|
11
13
|
module Rack
|
12
14
|
class ECG
|
data/lib/rack/ecg/version.rb
CHANGED
data/lib/rack/ecg.rb
CHANGED
data/lib/rack-ecg.rb
CHANGED
data/rack-ecg.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Rack::ECG::VERSION
|
9
9
|
spec.authors = ["Envato", "Julian Doherty"]
|
10
10
|
spec.email = ["julian@envato.com"]
|
11
|
-
spec.summary =
|
11
|
+
spec.summary = "Rack middleware serving a health check page"
|
12
12
|
spec.description = <<-EOF
|
13
13
|
rack-ecg allows you to serve a page that shows you facts about your deployed
|
14
14
|
app to allow you to check that everything is running as it should: git
|
@@ -30,16 +30,18 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
33
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
34
34
|
|
35
35
|
spec.add_runtime_dependency("rack")
|
36
36
|
|
37
|
-
spec.add_development_dependency("
|
38
|
-
spec.add_development_dependency("
|
39
|
-
spec.add_development_dependency("rspec", "~> 3.10.0")
|
37
|
+
spec.add_development_dependency("bundler", "~> 2.3.7")
|
38
|
+
spec.add_development_dependency("pry", "~> 0.14.1")
|
40
39
|
spec.add_development_dependency("rack-test", "~> 1.1.0")
|
41
|
-
spec.add_development_dependency("
|
42
|
-
spec.add_development_dependency("rubocop-shopify", "~> 1.0.0")
|
43
|
-
spec.add_development_dependency("yard", "~> 0.9.24")
|
40
|
+
spec.add_development_dependency("rake", "~> 13.0")
|
44
41
|
spec.add_development_dependency("redcarpet", "~> 3.5.0")
|
42
|
+
spec.add_development_dependency("rspec", "~> 3.11.0")
|
43
|
+
spec.add_development_dependency("rubocop-rake", "> 0")
|
44
|
+
spec.add_development_dependency("rubocop-rspec", "> 0")
|
45
|
+
spec.add_development_dependency("rubocop-shopify", "~> 2.4.0")
|
46
|
+
spec.add_development_dependency("yard", "~> 0.9.24")
|
45
47
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-ecg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Envato
|
8
8
|
- Julian Doherty
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -26,117 +26,145 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 2.3.7
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 2.3.7
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: pry
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 0.14.1
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 0.14.1
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: rack-test
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 1.1.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 1.1.0
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: rake
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '13.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: '13.0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: redcarpet
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
90
|
+
version: 3.5.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
97
|
+
version: 3.5.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: rspec
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 3.11.0
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 3.11.0
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: rubocop-rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rubocop-shopify
|
114
142
|
requirement: !ruby/object:Gem::Requirement
|
115
143
|
requirements:
|
116
144
|
- - "~>"
|
117
145
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
146
|
+
version: 2.4.0
|
119
147
|
type: :development
|
120
148
|
prerelease: false
|
121
149
|
version_requirements: !ruby/object:Gem::Requirement
|
122
150
|
requirements:
|
123
151
|
- - "~>"
|
124
152
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
153
|
+
version: 2.4.0
|
126
154
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
155
|
+
name: yard
|
128
156
|
requirement: !ruby/object:Gem::Requirement
|
129
157
|
requirements:
|
130
158
|
- - "~>"
|
131
159
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
160
|
+
version: 0.9.24
|
133
161
|
type: :development
|
134
162
|
prerelease: false
|
135
163
|
version_requirements: !ruby/object:Gem::Requirement
|
136
164
|
requirements:
|
137
165
|
- - "~>"
|
138
166
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
167
|
+
version: 0.9.24
|
140
168
|
description: |2
|
141
169
|
rack-ecg allows you to serve a page that shows you facts about your deployed
|
142
170
|
app to allow you to check that everything is running as it should: git
|
@@ -147,7 +175,8 @@ executables: []
|
|
147
175
|
extensions: []
|
148
176
|
extra_rdoc_files: []
|
149
177
|
files:
|
150
|
-
- ".github/
|
178
|
+
- ".github/dependabot.yml"
|
179
|
+
- ".github/workflows/test.yml"
|
151
180
|
- ".gitignore"
|
152
181
|
- ".rspec"
|
153
182
|
- ".rubocop.yml"
|
@@ -161,8 +190,10 @@ files:
|
|
161
190
|
- Rakefile
|
162
191
|
- bin/console
|
163
192
|
- bin/setup
|
193
|
+
- docker-compose.yml
|
164
194
|
- examples/basic.ru
|
165
195
|
- examples/checks.ru
|
196
|
+
- examples/git_revision_check_replacement.ru
|
166
197
|
- examples/hook.ru
|
167
198
|
- examples/mounted_path.ru
|
168
199
|
- examples/parameters.ru
|
@@ -177,6 +208,7 @@ files:
|
|
177
208
|
- lib/rack/ecg/check/migration_version.rb
|
178
209
|
- lib/rack/ecg/check/redis_connection.rb
|
179
210
|
- lib/rack/ecg/check/sequel_connection.rb
|
211
|
+
- lib/rack/ecg/check/static.rb
|
180
212
|
- lib/rack/ecg/check_factory.rb
|
181
213
|
- lib/rack/ecg/check_registry.rb
|
182
214
|
- lib/rack/ecg/version.rb
|
@@ -188,7 +220,7 @@ metadata:
|
|
188
220
|
homepage_uri: https://github.com/envato/rack-ecg
|
189
221
|
source_code_uri: https://github.com/envato/rack-ecg
|
190
222
|
changelog_uri: https://github.com/envato/rack-ecg/blob/main/CHANGELOG.md
|
191
|
-
post_install_message:
|
223
|
+
post_install_message:
|
192
224
|
rdoc_options: []
|
193
225
|
require_paths:
|
194
226
|
- lib
|
@@ -196,15 +228,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
228
|
requirements:
|
197
229
|
- - ">="
|
198
230
|
- !ruby/object:Gem::Version
|
199
|
-
version: 2.
|
231
|
+
version: 2.6.0
|
200
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
233
|
requirements:
|
202
234
|
- - ">="
|
203
235
|
- !ruby/object:Gem::Version
|
204
236
|
version: '0'
|
205
237
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
207
|
-
signing_key:
|
238
|
+
rubygems_version: 3.0.3.1
|
239
|
+
signing_key:
|
208
240
|
specification_version: 4
|
209
241
|
summary: Rack middleware serving a health check page
|
210
242
|
test_files: []
|