rack-ecg 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/test.yml +22 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +84 -0
- data/Gemfile +3 -1
- data/README.md +170 -52
- data/Rakefile +12 -2
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +18 -0
- data/examples/basic.ru +5 -3
- data/examples/checks.ru +5 -3
- data/examples/git_revision_check_replacement.ru +28 -0
- data/examples/hook.ru +17 -0
- data/examples/mounted_path.ru +5 -3
- data/examples/parameters.ru +13 -0
- data/examples/stand_alone.ru +4 -2
- data/lib/rack/ecg/check/active_record_connection.rb +33 -0
- data/lib/rack/ecg/check/error.rb +15 -6
- data/lib/rack/ecg/check/git_revision.rb +10 -2
- data/lib/rack/ecg/check/http.rb +15 -6
- data/lib/rack/ecg/check/migration_version.rb +8 -4
- data/lib/rack/ecg/check/redis_connection.rb +44 -0
- data/lib/rack/ecg/check/sequel_connection.rb +55 -0
- data/lib/rack/ecg/check/static.rb +52 -0
- data/lib/rack/ecg/check.rb +31 -1
- data/lib/rack/ecg/check_factory.rb +29 -0
- data/lib/rack/ecg/check_registry.rb +26 -3
- data/lib/rack/ecg/version.rb +4 -1
- data/lib/rack/ecg.rb +32 -31
- data/lib/rack-ecg.rb +3 -1
- data/rack-ecg.gemspec +33 -14
- metadata +113 -29
- data/.travis.yml +0 -28
- data/gemfiles/rack_v1.gemfile +0 -4
- data/spec/rack_middleware_spec.rb +0 -162
- data/spec/spec_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby: ["2.6", "2.7", "3.0", "3.1"]
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
name: Test (Ruby ${{ matrix.ruby }})
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- name: Run the default task
|
19
|
+
run: |
|
20
|
+
gem install bundler -v 2.3.7
|
21
|
+
bundle install
|
22
|
+
bundle exec rake
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
4
|
+
# any parameters. The file can be placed either in your home
|
5
|
+
# directory or in some project directory.
|
6
|
+
#
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
9
|
+
#
|
10
|
+
# See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
|
11
|
+
|
12
|
+
inherit_gem:
|
13
|
+
rubocop-shopify: rubocop.yml
|
14
|
+
|
15
|
+
AllCops:
|
16
|
+
Exclude:
|
17
|
+
- 'vendor/**/*'
|
18
|
+
|
19
|
+
Naming/FileName:
|
20
|
+
Exclude:
|
21
|
+
- 'lib/rack-ecg.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.9
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--files lib/**/*.rb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
|
+
|
6
|
+
## [Unreleased]
|
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
|
+
|
23
|
+
## [0.1.0] - 2020-12-16
|
24
|
+
|
25
|
+
### Added
|
26
|
+
|
27
|
+
- YARD-based gem documentation
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- **Breaking**: The Rack::ECG initializer now uses named options, instead of an options hash.
|
32
|
+
|
33
|
+
If you manually initialized an instance, you may need to use the `**` operator to pass these options. (e.g. `Rack::ECG.new(nil, **options)`)
|
34
|
+
|
35
|
+
### Removed
|
36
|
+
|
37
|
+
- **Breaking:** Dropped support for Ruby versions < 2.5.0
|
38
|
+
|
39
|
+
## [0.0.5] - 2017-05-12
|
40
|
+
|
41
|
+
### Added
|
42
|
+
|
43
|
+
- A new `sequel` check (#8), which checks if the Sequel database connection is active.
|
44
|
+
|
45
|
+
## [0.0.4] - 2017-05-04
|
46
|
+
|
47
|
+
### Added
|
48
|
+
|
49
|
+
- A new `active_record` check (#7), which checks if the ActiveRecord connection is active.
|
50
|
+
- A new `redis` check (#7), which checks if the Redis connection is active.
|
51
|
+
|
52
|
+
## [0.0.3] - 2017-02-13
|
53
|
+
|
54
|
+
### Added
|
55
|
+
|
56
|
+
- Accept a `hook` in configuration, which is run when all check results have been gathered (#6)
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
|
60
|
+
- Resolved an issue with the migration version check and MySQL connections (#3)
|
61
|
+
|
62
|
+
## [0.0.2] - 2015-06-17
|
63
|
+
|
64
|
+
### Added
|
65
|
+
|
66
|
+
- Support running Rack::ECG as a standalone application
|
67
|
+
- Support adding checks via the `CheckRegistry`
|
68
|
+
|
69
|
+
## [0.0.1] - 2015-04-09
|
70
|
+
|
71
|
+
### Added
|
72
|
+
|
73
|
+
- Base middleware to use in Rails or Rack apps
|
74
|
+
- `git_revision` check to return the current git revision
|
75
|
+
- `migration_version` check to return the current ActiveRecord migration version
|
76
|
+
|
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
|
80
|
+
[0.0.5]: https://github.com/envato/rack-ecg/compare/v0.0.4...v0.0.5
|
81
|
+
[0.0.4]: https://github.com/envato/rack-ecg/compare/v0.0.3...v0.0.4
|
82
|
+
[0.0.3]: https://github.com/envato/rack-ecg/compare/v0.0.2...v0.0.3
|
83
|
+
[0.0.2]: https://github.com/envato/rack-ecg/compare/v0.0.1...v0.0.2
|
84
|
+
[0.0.1]: https://github.com/envato/rack-ecg/releases/tag/v0.0.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
# Rack::ECG
|
2
2
|
|
3
|
-
|
4
|
-
health check endpoint that tells you vital life signs about your app. All
|
5
|
-
without the boilerplate service checking code you've written 10 times before.
|
3
|
+
[![Gem version](https://img.shields.io/gem/v/rack-ecg)][gem-page] [![Rubydoc](https://img.shields.io/badge/docs-rubydoc-success)][rubydoc]
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
Rack middleware for Ruby web apps, providing a simple and extensible health
|
6
|
+
check endpoint, with minimal configuration.
|
7
|
+
|
8
|
+
> Electrocardiogram (ECG): A recording of the electrical activity of the heart.
|
9
9
|
|
10
10
|
## Features
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
- Start with a single line in your `config.ru` or `config/application.rb` file.
|
13
13
|
- reports git revision status
|
14
14
|
- reports ActiveRecord migration schema version
|
15
15
|
- reports errors if any check can't be executed for whatever reason
|
16
16
|
- JSON output
|
17
17
|
|
18
|
-
## Development Status
|
18
|
+
## Development Status
|
19
|
+
|
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)
|
19
21
|
|
20
22
|
`Rack::ECG` is extracted from production code in use at
|
21
23
|
[Envato](http://envato.com). However, it is undergoing early development, and
|
@@ -23,23 +25,15 @@ APIs and features are almost certain to be in flux.
|
|
23
25
|
|
24
26
|
## Getting Started
|
25
27
|
|
26
|
-
Add this
|
28
|
+
Add this to your application's `Gemfile`:
|
27
29
|
|
28
30
|
```ruby
|
29
|
-
gem 'rack-ecg'
|
31
|
+
gem 'rack-ecg', '~> 0.2.0`
|
30
32
|
```
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
$ bundle
|
35
|
-
|
36
|
-
Or install it yourself as:
|
37
|
-
|
38
|
-
$ gem install rack-ecg
|
34
|
+
Then run `bundle install`.
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
In Rails you can add `Rack::ECG` to your `config/application.rb` as a middleware
|
36
|
+
In Rails you can add `Rack::ECG` to your `config/application.rb` as a middleware:
|
43
37
|
|
44
38
|
```ruby
|
45
39
|
# config/application.rb
|
@@ -48,9 +42,7 @@ config.middleware.use Rack::ECG
|
|
48
42
|
# ...
|
49
43
|
```
|
50
44
|
|
51
|
-
|
52
|
-
|
53
|
-
In Rack apps, you can add `Rack::ECG` to your `config.ru`
|
45
|
+
In Rack apps, you can add `Rack::ECG` to your `config.ru`:
|
54
46
|
|
55
47
|
```ruby
|
56
48
|
# config.ru
|
@@ -61,6 +53,8 @@ use Rack::ECG
|
|
61
53
|
run MyRackApp
|
62
54
|
```
|
63
55
|
|
56
|
+
## Usage
|
57
|
+
|
64
58
|
You can now hit your app and get a basic health check response from `Rack::ECG`
|
65
59
|
|
66
60
|
```
|
@@ -79,39 +73,149 @@ status if any of the checks fail.
|
|
79
73
|
|
80
74
|
## Configuration
|
81
75
|
|
82
|
-
There are options that can be passed to `use Rack::ECG` to customise how it
|
83
|
-
works.
|
76
|
+
There are options that can be passed to `use Rack::ECG` to customise how it works.
|
84
77
|
|
85
|
-
###
|
86
|
-
Out of the box `Rack::ECG` doesn't do much and just checks that
|
87
|
-
HTTP responses can be returned. There are a number of built in checks that
|
88
|
-
`Rack::ECG` can be told to do (more to come)
|
89
|
-
- `:git_revision` - this assumes your code is deployed via git and exists in a
|
90
|
-
git repo, and that the `git` command can access it
|
91
|
-
- `:migration_version` - this assumes you are using ActiveRecord migrations. It
|
92
|
-
queries the `schema_versions` table and tells you what version the database is
|
93
|
-
at.
|
78
|
+
### Checks
|
94
79
|
|
95
|
-
|
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:
|
96
81
|
|
97
82
|
```ruby
|
98
|
-
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
|
+
]
|
99
91
|
```
|
100
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
|
+
}
|
101
104
|
```
|
102
|
-
|
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
|
103
139
|
{
|
104
140
|
"http": {
|
105
141
|
"status": "ok",
|
106
142
|
"value": "online"
|
107
|
-
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
+
{
|
112
153
|
"migration_version": {
|
113
154
|
"status": "ok",
|
114
|
-
"value": "
|
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
|
+
{
|
166
|
+
"redis": {
|
167
|
+
"status": "ok",
|
168
|
+
"value": true
|
169
|
+
}
|
170
|
+
}
|
171
|
+
```
|
172
|
+
|
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:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
{
|
181
|
+
connection: "sqlite://events.db",
|
182
|
+
name: "events", # must be unique per sequel check
|
183
|
+
}
|
184
|
+
```
|
185
|
+
|
186
|
+
Returns the something in the following format on success:
|
187
|
+
|
188
|
+
```json
|
189
|
+
{
|
190
|
+
"sequel_events": {
|
191
|
+
"status": "ok",
|
192
|
+
"value": true
|
193
|
+
}
|
194
|
+
}
|
195
|
+
```
|
196
|
+
|
197
|
+
#### `static`
|
198
|
+
|
199
|
+
Returns the same value every time. Requires configuration, and can be configured multiple times.
|
200
|
+
|
201
|
+
Given the following configuration:
|
202
|
+
|
203
|
+
```ruby
|
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
|
+
}
|
210
|
+
```
|
211
|
+
|
212
|
+
Returns the something in the following format:
|
213
|
+
|
214
|
+
```json
|
215
|
+
{
|
216
|
+
"image_build_url": {
|
217
|
+
"status": "ok",
|
218
|
+
"value": "https://example.com/pipelines/my-cool-app/builds/1234"
|
115
219
|
}
|
116
220
|
}
|
117
221
|
```
|
@@ -125,11 +229,23 @@ a different path by setting the `at` option. e.g.
|
|
125
229
|
use Rack::ECG, at: "/health_check"
|
126
230
|
```
|
127
231
|
|
128
|
-
|
232
|
+
### `hook`
|
233
|
+
|
234
|
+
The `hook` option takes a `Proc` or equivalent, and calls it after the checks
|
235
|
+
have run, but before the response is complete.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
use Rack::ECG, hook: Proc.new { |success, _checks| puts "Is healthy? #{success}" }
|
239
|
+
```
|
240
|
+
|
241
|
+
- `success`: whether the response will indicate success
|
242
|
+
- `checks`: an array of the check names and values
|
243
|
+
|
244
|
+
More examples are provided in [/examples](https://github.com/envato/rack-ecg/tree/main/examples)
|
129
245
|
|
130
246
|
## Requirements
|
131
|
-
|
132
|
-
|
247
|
+
|
248
|
+
- Ruby >= 2.6
|
133
249
|
- Rack
|
134
250
|
- To use optional `git_revision` check, your deployed code needs to be in a git repo, and
|
135
251
|
`git` command must be accessible on the server
|
@@ -145,24 +261,24 @@ migrations stored in `schema_versions` table
|
|
145
261
|
|
146
262
|
## Maintainers
|
147
263
|
|
148
|
-
- [
|
149
|
-
- [Warren Seen](https://github.com/warrenseen)
|
264
|
+
- [Liam Dawson](https://github.com/liamdawson)
|
150
265
|
|
151
|
-
##
|
266
|
+
## Contributors
|
152
267
|
|
268
|
+
- [Tao Guo](https://github.com/taoza)
|
153
269
|
- [Julian Doherty](https://github.com/madlep)
|
154
270
|
- [Warren Seen](https://github.com/warrenseen)
|
155
271
|
|
156
272
|
## License
|
157
273
|
|
158
274
|
`Rack::ECG` uses MIT license. See
|
159
|
-
[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/
|
275
|
+
[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/main/LICENSE.txt) for
|
160
276
|
details.
|
161
277
|
|
162
278
|
## Code of conduct
|
163
279
|
|
164
280
|
We welcome contribution from everyone. Read more about it in
|
165
|
-
[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/
|
281
|
+
[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/main/CODE_OF_CONDUCT.md)
|
166
282
|
|
167
283
|
## Contributing
|
168
284
|
|
@@ -178,7 +294,7 @@ For larger new features: Do everything as above, but first also make contact wit
|
|
178
294
|
|
179
295
|
## About
|
180
296
|
|
181
|
-
This project is maintained by the [Envato engineering team][webuild] and funded by [Envato][envato].
|
297
|
+
This project is maintained by the [Envato engineering team][webuild] and funded by [Envato][envato].
|
182
298
|
|
183
299
|
[<img src="http://opensource.envato.com/images/envato-oss-readme-logo.png" alt="Envato logo">][envato]
|
184
300
|
|
@@ -188,3 +304,5 @@ Encouraging the use and creation of open source software is one of the ways we s
|
|
188
304
|
[envato]: https://envato.com?utm_source=github
|
189
305
|
[oss]: http://opensource.envato.com//?utm_source=github
|
190
306
|
[careers]: http://careers.envato.com/?utm_source=github
|
307
|
+
[gem-page]: https://rubygems.org/gems/rack-ecg
|
308
|
+
[rubydoc]: https://www.rubydoc.info/gems/rack-ecg/
|
data/Rakefile
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
|
3
|
-
require
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "rubocop/rake_task"
|
7
|
+
require "yard"
|
4
8
|
|
5
9
|
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
RuboCop::RakeTask.new(:rubocop)
|
11
|
+
YARD::Rake::YardocTask.new
|
12
|
+
|
13
|
+
task(default: [:rubocop, :spec, :yard])
|
6
14
|
|
7
|
-
task
|
15
|
+
task(:watch_docs) do
|
16
|
+
sh "yard server --reload"
|
17
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rack-ecg"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
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
@@ -1,5 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "rack/ecg"
|
4
4
|
|
5
|
-
|
5
|
+
use(Rack::ECG, checks: [:git_revision, :migration_version])
|
6
|
+
|
7
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
@@ -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
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/ecg"
|
4
|
+
|
5
|
+
log_check_results = proc do |success, checks|
|
6
|
+
next if success
|
7
|
+
|
8
|
+
checks.each do |check_name, check_status|
|
9
|
+
next unless check_status[:status] == "error"
|
10
|
+
|
11
|
+
puts "Check #{check_name} failed: #{check_status[:value]}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
use(Rack::ECG, checks: [:git_revision, :migration_version], hook: log_check_results)
|
16
|
+
|
17
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
data/examples/mounted_path.ru
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/ecg"
|
4
|
+
require "sequel"
|
5
|
+
require "sqlite3"
|
6
|
+
|
7
|
+
use(Rack::ECG, checks: [
|
8
|
+
:http,
|
9
|
+
[:sequel, { connection: "sqlite://events.db", name: "events" }],
|
10
|
+
[:sequel, { connection: "sqlite://projections.db", name: "projections" }],
|
11
|
+
])
|
12
|
+
|
13
|
+
run(->(_env) { [200, {}, ["Hello, World"]] })
|
data/examples/stand_alone.ru
CHANGED