rack-ecg 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +22 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +69 -0
- data/Gemfile +1 -0
- data/README.md +118 -31
- data/Rakefile +10 -1
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/examples/basic.ru +3 -3
- data/examples/checks.ru +3 -3
- data/examples/hook.ru +17 -0
- data/examples/mounted_path.ru +3 -3
- data/examples/parameters.ru +12 -0
- data/examples/stand_alone.ru +4 -0
- data/lib/rack-ecg.rb +1 -0
- data/lib/rack/ecg.rb +37 -55
- data/lib/rack/ecg/check.rb +45 -0
- data/lib/rack/ecg/check/active_record_connection.rb +32 -0
- data/lib/rack/ecg/check/error.rb +16 -0
- data/lib/rack/ecg/check/git_revision.rb +26 -0
- data/lib/rack/ecg/check/http.rb +16 -0
- data/lib/rack/ecg/check/migration_version.rb +32 -0
- data/lib/rack/ecg/check/redis_connection.rb +34 -0
- data/lib/rack/ecg/check/sequel_connection.rb +54 -0
- data/lib/rack/ecg/check_factory.rb +28 -0
- data/lib/rack/ecg/check_registry.rb +43 -0
- data/lib/rack/ecg/version.rb +3 -1
- data/rack-ecg.gemspec +31 -14
- metadata +91 -31
- data/.travis.yml +0 -15
- data/spec/rack_middleware_spec.rb +0 -146
- 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: daea3d8ff855b734db9fc65f7ed6859114f1a89e095d06f7c26f907d011b65e9
|
4
|
+
data.tar.gz: b311a75d0c8555c21e9db5633bbbf3dc7304fd8dc42497dfeb9957edeb1f9233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cd8743e07657aaaf35ff83fde2d38d3ba836b0b2a2b439260f0547c6ce173d065e9812f46d1915811fc6bf41eb2ec2c30285d492639f5d75970167d36078b8e
|
7
|
+
data.tar.gz: f52644422ecd24cf6e072b4ddd5bd8edcc1de2a8653f65d2d0e230f9bea91fd5dfe18a1b96a035aa86aec61a125440d4a94125fc0b7c9a33c0e2665231ec4bd6
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby: [2.5, 2.6, 2.7]
|
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.2.1
|
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.5.8
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--files lib/**/*.rb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,69 @@
|
|
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.1.0] - 2020-12-16
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- YARD-based gem documentation
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- **Breaking**: The Rack::ECG initializer now uses named options, instead of an options hash.
|
17
|
+
|
18
|
+
If you manually initialized an instance, you may need to use the `**` operator to pass these options. (e.g. `Rack::ECG.new(nil, **options)`)
|
19
|
+
|
20
|
+
### Removed
|
21
|
+
|
22
|
+
- **Breaking:** Dropped support for Ruby versions < 2.5.0
|
23
|
+
|
24
|
+
## [0.0.5] - 2017-05-12
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- A new `sequel` check (#8), which checks if the Sequel database connection is active.
|
29
|
+
|
30
|
+
## [0.0.4] - 2017-05-04
|
31
|
+
|
32
|
+
### Added
|
33
|
+
|
34
|
+
- A new `active_record` check (#7), which checks if the ActiveRecord connection is active.
|
35
|
+
- A new `redis` check (#7), which checks if the Redis connection is active.
|
36
|
+
|
37
|
+
## [0.0.3] - 2017-02-13
|
38
|
+
|
39
|
+
### Added
|
40
|
+
|
41
|
+
- Accept a `hook` in configuration, which is run when all check results have been gathered (#6)
|
42
|
+
|
43
|
+
### Fixed
|
44
|
+
|
45
|
+
- Resolved an issue with the migration version check and MySQL connections (#3)
|
46
|
+
|
47
|
+
## [0.0.2] - 2015-06-17
|
48
|
+
|
49
|
+
### Added
|
50
|
+
|
51
|
+
- Support running Rack::ECG as a standalone application
|
52
|
+
- Support adding checks via the `CheckRegistry`
|
53
|
+
|
54
|
+
## [0.0.1] - 2015-04-09
|
55
|
+
|
56
|
+
### Added
|
57
|
+
|
58
|
+
- Base middleware to use in Rails or Rack apps
|
59
|
+
- `git_revision` check to return the current git revision
|
60
|
+
- `migration_version` check to return the current ActiveRecord migration version
|
61
|
+
|
62
|
+
[Unreleased]: https://github.com/envato/rack-ecg/compare/v0.1.0...HEAD
|
63
|
+
[0.1.0]: https://github.com/envato/rack-ecg/compare/v0.0.5...v0.1.0
|
64
|
+
[0.0.5]: https://github.com/envato/rack-ecg/compare/v0.0.4...v0.0.5
|
65
|
+
[0.0.4]: https://github.com/envato/rack-ecg/compare/v0.0.3...v0.0.4
|
66
|
+
[0.0.3]: https://github.com/envato/rack-ecg/compare/v0.0.2...v0.0.3
|
67
|
+
[0.0.2]: https://github.com/envato/rack-ecg/compare/v0.0.1...v0.0.2
|
68
|
+
[0.0.1]: https://github.com/envato/rack-ecg/releases/tag/v0.0.1
|
69
|
+
|
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/build/badge.svg?branch=main)](https://github.com/envato/rack-ecg/actions)
|
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.0.5`
|
30
32
|
```
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
$ bundle
|
34
|
+
Then run `bundle install`.
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
$ gem install rack-ecg
|
39
|
-
|
40
|
-
### Rails
|
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
|
```
|
@@ -91,11 +85,13 @@ HTTP responses can be returned. There are a number of built in checks that
|
|
91
85
|
- `:migration_version` - this assumes you are using ActiveRecord migrations. It
|
92
86
|
queries the `schema_versions` table and tells you what version the database is
|
93
87
|
at.
|
88
|
+
- `:active_record` - this checks if an ActiveRecord connection is active.
|
89
|
+
- `:redis` - this checks if a Redis connection is active.
|
94
90
|
|
95
|
-
So using `git_revision` and `
|
91
|
+
So using `git_revision`, `migration_version`, `active_record`, and `redis` would look like:
|
96
92
|
|
97
93
|
```ruby
|
98
|
-
use Rack::ECG, checks: [:git_revision, :migration_version]
|
94
|
+
use Rack::ECG, checks: [:git_revision, :migration_version, :active_record, :redis]
|
99
95
|
```
|
100
96
|
|
101
97
|
```
|
@@ -112,6 +108,64 @@ $ curl http://localhost:9292/_ecg
|
|
112
108
|
"migration_version": {
|
113
109
|
"status": "ok",
|
114
110
|
"value": "20150319050250"
|
111
|
+
},
|
112
|
+
"active_record": {
|
113
|
+
"status": "ok",
|
114
|
+
"value": "true"
|
115
|
+
},
|
116
|
+
"redis": {
|
117
|
+
"status": "ok",
|
118
|
+
"value": "true"
|
119
|
+
}
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Checks with parameters
|
124
|
+
Some checks, such as the `sequel` check, require a parameter hash. In this case, you must provide the check as a tuple consisting of both the check name, and a hash of parameters:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
use Rack::ECG, checks: [:http, [:sequel, {connection: "sqlite://my-sqlite.db"}]]
|
128
|
+
```
|
129
|
+
|
130
|
+
```
|
131
|
+
$ curl http://localhost:9292/_ecg
|
132
|
+
{
|
133
|
+
"http": {
|
134
|
+
"status": "ok",
|
135
|
+
"value": "online"
|
136
|
+
},
|
137
|
+
"sequel": {
|
138
|
+
"status": "ok",
|
139
|
+
"value": "true"
|
140
|
+
}
|
141
|
+
}
|
142
|
+
```
|
143
|
+
|
144
|
+
Because the `sequel` check operates on a per-connection basis, you can specify multiple Sequel databases to independently check, and provide a friendly name for disambiguation purposes:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
use Rack::ECG, checks: [
|
148
|
+
:http,
|
149
|
+
[:sequel, {connection: 'sqlite://events.db', name: 'events'}],
|
150
|
+
[:sequel, {connection: 'sqlite://projections.db', name: 'projections'}]
|
151
|
+
]
|
152
|
+
```
|
153
|
+
|
154
|
+
```
|
155
|
+
$ curl http://localhost:9292/_ecg
|
156
|
+
|
157
|
+
{
|
158
|
+
"http": {
|
159
|
+
"status": "ok",
|
160
|
+
"value": "online"
|
161
|
+
},
|
162
|
+
"sequel_events": {
|
163
|
+
"status": "ok",
|
164
|
+
"value": "true"
|
165
|
+
},
|
166
|
+
"sequel_projections": {
|
167
|
+
"status": "ok",
|
168
|
+
"value": "true"
|
115
169
|
}
|
116
170
|
}
|
117
171
|
```
|
@@ -125,11 +179,23 @@ a different path by setting the `at` option. e.g.
|
|
125
179
|
use Rack::ECG, at: "/health_check"
|
126
180
|
```
|
127
181
|
|
128
|
-
|
182
|
+
### `hook`
|
183
|
+
|
184
|
+
The `hook` option takes a `Proc` or equivalent, and calls it after the checks
|
185
|
+
have run, but before the response is complete.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
use Rack::ECG, hook: Proc.new { |success, _checks| puts "Is healthy? #{success}" }
|
189
|
+
```
|
190
|
+
|
191
|
+
- `success`: whether the response will indicate success
|
192
|
+
- `checks`: an array of the check names and values
|
193
|
+
|
194
|
+
More examples are provided in [/examples](https://github.com/envato/rack-ecg/tree/main/examples)
|
129
195
|
|
130
196
|
## Requirements
|
131
|
-
|
132
|
-
|
197
|
+
|
198
|
+
- Ruby >= 2.5
|
133
199
|
- Rack
|
134
200
|
- To use optional `git_revision` check, your deployed code needs to be in a git repo, and
|
135
201
|
`git` command must be accessible on the server
|
@@ -145,18 +211,24 @@ migrations stored in `schema_versions` table
|
|
145
211
|
|
146
212
|
## Maintainers
|
147
213
|
|
214
|
+
- [Liam Dawson](https://github.com/liamdawson)
|
215
|
+
|
216
|
+
## Contributors
|
217
|
+
|
218
|
+
- [Tao Guo](https://github.com/taoza)
|
148
219
|
- [Julian Doherty](https://github.com/madlep)
|
220
|
+
- [Warren Seen](https://github.com/warrenseen)
|
149
221
|
|
150
222
|
## License
|
151
223
|
|
152
224
|
`Rack::ECG` uses MIT license. See
|
153
|
-
[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/
|
225
|
+
[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/main/LICENSE.txt) for
|
154
226
|
details.
|
155
227
|
|
156
228
|
## Code of conduct
|
157
229
|
|
158
230
|
We welcome contribution from everyone. Read more about it in
|
159
|
-
[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/
|
231
|
+
[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/main/CODE_OF_CONDUCT.md)
|
160
232
|
|
161
233
|
## Contributing
|
162
234
|
|
@@ -168,4 +240,19 @@ For bug fixes, documentation changes, and small features:
|
|
168
240
|
4. Push to the branch (git push origin my-new-feature)
|
169
241
|
5. Create a new Pull Request
|
170
242
|
|
171
|
-
For larger new features: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction
|
243
|
+
For larger new features: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction.
|
244
|
+
|
245
|
+
## About
|
246
|
+
|
247
|
+
This project is maintained by the [Envato engineering team][webuild] and funded by [Envato][envato].
|
248
|
+
|
249
|
+
[<img src="http://opensource.envato.com/images/envato-oss-readme-logo.png" alt="Envato logo">][envato]
|
250
|
+
|
251
|
+
Encouraging the use and creation of open source software is one of the ways we serve our community. See [our other projects][oss] or [come work with us][careers] where you'll find an incredibly diverse, intelligent and capable group of people who help make our company succeed and make our workplace fun, friendly and happy.
|
252
|
+
|
253
|
+
[webuild]: http://webuild.envato.com?utm_source=github
|
254
|
+
[envato]: https://envato.com?utm_source=github
|
255
|
+
[oss]: http://opensource.envato.com//?utm_source=github
|
256
|
+
[careers]: http://careers.envato.com/?utm_source=github
|
257
|
+
[gem-page]: https://rubygems.org/gems/rack-ecg
|
258
|
+
[rubydoc]: https://www.rubydoc.info/gems/rack-ecg/
|
data/Rakefile
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "bundler/gem_tasks"
|
2
3
|
|
3
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
require 'yard'
|
4
7
|
|
5
8
|
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
RuboCop::RakeTask.new(:rubocop)
|
10
|
+
YARD::Rake::YardocTask.new
|
6
11
|
|
7
|
-
task :
|
12
|
+
task(default: [:rubocop, :spec, :yard])
|
13
|
+
|
14
|
+
task(:watch_docs) do
|
15
|
+
sh "yard server --reload"
|
16
|
+
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/examples/basic.ru
CHANGED
data/examples/checks.ru
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rack/ecg'
|
2
3
|
|
3
|
-
use
|
4
|
-
use Rack::Reloader
|
4
|
+
use(Rack::ECG, checks: [:git_revision, :migration_version])
|
5
5
|
|
6
|
-
run
|
6
|
+
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']] })
|