rack-ecg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +171 -0
- data/Rakefile +7 -0
- data/examples/basic.ru +6 -0
- data/examples/checks.ru +6 -0
- data/examples/mounted_path.ru +6 -0
- data/lib/rack-ecg.rb +1 -0
- data/lib/rack/ecg.rb +80 -0
- data/lib/rack/ecg/version.rb +5 -0
- data/rack-ecg.gemspec +28 -0
- data/spec/rack_middleware_spec.rb +146 -0
- data/spec/spec_helper.rb +23 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15da50402ccd3b3dcc2efab39fcdfde5a320931f
|
4
|
+
data.tar.gz: b0ee8b09dd75d9f25796c70a31e7477c320c38e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8da335a59221c75231ca7bc618748c59a2926a4a3a15326ff0246a10b19b1bcd7e2f118218f78f80adcacb65d2b4b8420f4843373805470f1fdcc77635b9a4bd
|
7
|
+
data.tar.gz: ba2660ec5a305e5758cee866aa0c8e466256209b82d8ad8999742b00deb739a5b8fde4cfa9a8a3153f329c2a91142273a1785e8642a84f2d58db9604ae1d4b98
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.5
|
6
|
+
- 2.2.1
|
7
|
+
- ruby-head
|
8
|
+
- jruby
|
9
|
+
notifications:
|
10
|
+
webhooks:
|
11
|
+
urls:
|
12
|
+
- https://webhooks.gitter.im/e/b627d6a74f88be59d0b9
|
13
|
+
on_success: change # options: [always|never|change] default: always
|
14
|
+
on_failure: always # options: [always|never|change] default: always
|
15
|
+
on_start: false # default: false - rbx-2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Envato
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
# Rack::ECG
|
2
|
+
|
3
|
+
An easy to configure Rack middleware for Ruby web apps to provide a simple
|
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.
|
6
|
+
|
7
|
+
(it's ECG as in electrocardiogram - as in the machine that monitors how your
|
8
|
+
heart works)
|
9
|
+
|
10
|
+
## Features
|
11
|
+
- simple 1 line to drop into your `config.ru` or `config/application.rb` file to
|
12
|
+
set up
|
13
|
+
- reports git revision status
|
14
|
+
- reports ActiveRecord migration schema version
|
15
|
+
- reports errors if any check can't be executed for whatever reason
|
16
|
+
- JSON output
|
17
|
+
|
18
|
+
## Development Status [![travis ci build](https://api.travis-ci.org/envato/rack-ecg.svg)](https://travis-ci.org/envato/rack-ecg)
|
19
|
+
|
20
|
+
`Rack::ECG` is extracted from production code in use at
|
21
|
+
[Envato](http://envato.com). However, it is undergoing early development, and
|
22
|
+
APIs and features are almost certain to be in flux.
|
23
|
+
|
24
|
+
## Getting Started
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'rack-ecg'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
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
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# config/application.rb
|
46
|
+
# ...
|
47
|
+
config.middleware.use Rack::ECG
|
48
|
+
# ...
|
49
|
+
```
|
50
|
+
|
51
|
+
### Rack
|
52
|
+
|
53
|
+
In Rack apps, you can add `Rack::ECG` to your `config.ru`
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# config.ru
|
57
|
+
require 'rack/ecg'
|
58
|
+
|
59
|
+
use Rack::ECG
|
60
|
+
|
61
|
+
run MyRackApp
|
62
|
+
```
|
63
|
+
|
64
|
+
You can now hit your app and get a basic health check response from `Rack::ECG`
|
65
|
+
|
66
|
+
```
|
67
|
+
$ curl http://localhost:9292/_ecg
|
68
|
+
{
|
69
|
+
"http": {
|
70
|
+
"status": "ok",
|
71
|
+
"value": "online"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
`/_ecg` will return a `200` HTTP status if all the checks are OK, or `500`
|
77
|
+
status if any of the checks fail.
|
78
|
+
|
79
|
+
|
80
|
+
## Configuration
|
81
|
+
|
82
|
+
There are options that can be passed to `use Rack::ECG` to customise how it
|
83
|
+
works.
|
84
|
+
|
85
|
+
### `checks`
|
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.
|
94
|
+
|
95
|
+
So using `git_revision` and `migration_version` would look like:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
use Rack::ECG, checks: [:git_revision, :migration_version]
|
99
|
+
```
|
100
|
+
|
101
|
+
```
|
102
|
+
$ curl http://localhost:9292/_ecg
|
103
|
+
{
|
104
|
+
"http": {
|
105
|
+
"status": "ok",
|
106
|
+
"value": "online"
|
107
|
+
},
|
108
|
+
"git_revision": {
|
109
|
+
"status": "ok",
|
110
|
+
"value": "fb16e2c3b88af671c42880e6977bba34d7b05ba6\n"
|
111
|
+
},
|
112
|
+
"migration_version": {
|
113
|
+
"status": "ok",
|
114
|
+
"value": "20150319050250"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
### `at`
|
120
|
+
|
121
|
+
By default `Rack::ECG` is mapped to a URL of `/_ecg`, you can set this to
|
122
|
+
a different path by setting the `at` option. e.g.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
use Rack::ECG, at: "/health_check"
|
126
|
+
```
|
127
|
+
|
128
|
+
More examples are provided in [/examples](https://github.com/envato/rack-ecg/tree/master/examples)
|
129
|
+
|
130
|
+
## Requirements
|
131
|
+
- Ruby >= 1.9.3 (this may be increased to Ruby >= 2.0 if it makes sense to use
|
132
|
+
Ruby 2.0 features)
|
133
|
+
- Rack
|
134
|
+
- To use optional `git_revision` check, your deployed code needs to be in a git repo, and
|
135
|
+
`git` command must be accessible on the server
|
136
|
+
- To use optional `migration_version` check, you must be using ActiveRecord and
|
137
|
+
migrations stored in `schema_versions` table
|
138
|
+
|
139
|
+
## Contact
|
140
|
+
|
141
|
+
- [github project](https://github.com/envato/rack-ecg)
|
142
|
+
- [gitter chat room ![Join the chat at
|
143
|
+
https://gitter.im/envato/rack-ecg](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/envato/rack-ecg)
|
144
|
+
- Bug reports and feature requests are via [github issues](https://github.com/envato/rack-ecg/issues)
|
145
|
+
|
146
|
+
## Maintainers
|
147
|
+
|
148
|
+
- [Julian Doherty](https://github.com/madlep)
|
149
|
+
|
150
|
+
## License
|
151
|
+
|
152
|
+
`Rack::ECG` uses MIT license. See
|
153
|
+
[`LICENSE.txt`](https://github.com/envato/rack-ecg/blob/master/LICENSE.txt) for
|
154
|
+
details.
|
155
|
+
|
156
|
+
## Code of conduct
|
157
|
+
|
158
|
+
We welcome contribution from everyone. Read more about it in
|
159
|
+
[`CODE_OF_CONDUCT.md`](https://github.com/envato/rack-ecg/blob/master/CODE_OF_CONDUCT.md)
|
160
|
+
|
161
|
+
## Contributing
|
162
|
+
|
163
|
+
For bug fixes, documentation changes, and small features:
|
164
|
+
|
165
|
+
1. Fork it ( https://github.com/[my-github-username]/rack-ecg/fork )
|
166
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
167
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
168
|
+
4. Push to the branch (git push origin my-new-feature)
|
169
|
+
5. Create a new Pull Request
|
170
|
+
|
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
|
data/Rakefile
ADDED
data/examples/basic.ru
ADDED
data/examples/checks.ru
ADDED
data/lib/rack-ecg.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/ecg'
|
data/lib/rack/ecg.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "rack/ecg/version"
|
2
|
+
require "json"
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class ECG
|
7
|
+
DEFAULT_MOUNT_AT = "/_ecg"
|
8
|
+
DEFAULT_CHECKS = [ :check_http ]
|
9
|
+
|
10
|
+
def initialize(app, options={})
|
11
|
+
@app = app
|
12
|
+
option_checks = options.delete(:checks) || []
|
13
|
+
option_checks = option_checks.map{|check| "check_#{check}".to_sym }
|
14
|
+
@checks = DEFAULT_CHECKS + option_checks
|
15
|
+
@at = options.delete(:at) || DEFAULT_MOUNT_AT
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
if env["PATH_INFO"] == @at
|
20
|
+
|
21
|
+
check_results = @checks.inject({}){|results, check_method| results.merge(send(check_method)) }
|
22
|
+
|
23
|
+
response_status = check_results.any?{|check| check[1][:status] == "error" } ? 500 : 200
|
24
|
+
|
25
|
+
response_headers = {
|
26
|
+
"X-Rack-ECG-Version" => Rack::ECG::VERSION,
|
27
|
+
"Content-Type" => "application/json"
|
28
|
+
}
|
29
|
+
|
30
|
+
response_body = JSON.pretty_generate(check_results)
|
31
|
+
|
32
|
+
[response_status, response_headers, [response_body]]
|
33
|
+
else
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def check_http
|
40
|
+
# if rack-ecg is serving a request - http is obviously working so far...
|
41
|
+
# this is basically a "hello-world"
|
42
|
+
{http: {status: "ok", value: "online" } }
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_error
|
46
|
+
# this always fails. mainly for testing
|
47
|
+
{error: {status: "error", value: "PC LOAD LETTER" } }
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_git_revision
|
51
|
+
_stdin, stdout, stderr, wait_thread = Open3.popen3("git rev-parse HEAD")
|
52
|
+
|
53
|
+
success = wait_thread.value.success?
|
54
|
+
status = success ? "ok" : "error"
|
55
|
+
value = success ? stdout.read : stderr.read
|
56
|
+
value = value.strip
|
57
|
+
{git_revision: {status: status, value: value} }
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_migration_version
|
61
|
+
value = ""
|
62
|
+
status = "ok"
|
63
|
+
begin
|
64
|
+
if defined?(ActiveRecord)
|
65
|
+
connection = ActiveRecord::Base.connection
|
66
|
+
result_set = connection.execute("select max(version) as version from schema_migrations")
|
67
|
+
version = result_set.first
|
68
|
+
value = version["version"]
|
69
|
+
else
|
70
|
+
status = "error"
|
71
|
+
value = "ActiveRecord not found"
|
72
|
+
end
|
73
|
+
rescue => e
|
74
|
+
status = "error"
|
75
|
+
value = e.message
|
76
|
+
end
|
77
|
+
{migration_version: {status: status, value: value} }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/rack-ecg.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/ecg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-ecg"
|
8
|
+
spec.version = Rack::ECG::VERSION
|
9
|
+
spec.authors = ["Envato", "Julian Doherty"]
|
10
|
+
spec.email = ["julian@envato.com"]
|
11
|
+
spec.summary = %q{Rack middleware serving a health check page}
|
12
|
+
spec.description = %q{rack-ecg allows you to serve a page that shows you facts about your deployed app to allow you to check that everything is running as it should: git revision, database migrations, and more}
|
13
|
+
spec.homepage = "https://github.com/envato/rack-ecg"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rack"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2.0"
|
26
|
+
spec.add_development_dependency "rack-test", "~> 0.6.3"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10.1"
|
28
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
RSpec.describe "when used as middleware" do
|
5
|
+
let(:app) {
|
6
|
+
opts = options
|
7
|
+
Rack::Builder.new do
|
8
|
+
use Rack::ECG, opts
|
9
|
+
run lambda {|env|
|
10
|
+
if env["PATH_INFO"] == "/hello/world"
|
11
|
+
[200, {}, ["Hello, World"]]
|
12
|
+
else
|
13
|
+
[404, {}, ["Goodbye, World"]]
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
}
|
18
|
+
let(:options) {
|
19
|
+
{} # empty default
|
20
|
+
}
|
21
|
+
|
22
|
+
context "main app" do
|
23
|
+
it "responds OK for normal requests" do
|
24
|
+
get "/hello/world"
|
25
|
+
expect(last_response).to be_ok
|
26
|
+
end
|
27
|
+
|
28
|
+
it "doesn't include an X-Rack-ECG-Version custom header" do
|
29
|
+
get "/hello/world"
|
30
|
+
expect(last_response.header["X-Rack-ECG-Version"]).to be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "ecg app" do
|
35
|
+
it "responds " do
|
36
|
+
get "/_ecg"
|
37
|
+
expect(last_response).to be_ok
|
38
|
+
end
|
39
|
+
|
40
|
+
it "includes an X-Rack-ECG-Version custom header" do
|
41
|
+
get "/_ecg"
|
42
|
+
expect(last_response.header["X-Rack-ECG-Version"]).to eq(Rack::ECG::VERSION)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when `at` config option is set" do
|
46
|
+
let(:options) {
|
47
|
+
{at: "/health_check"}
|
48
|
+
}
|
49
|
+
|
50
|
+
it "responds from that path" do
|
51
|
+
get "/health_check"
|
52
|
+
expect(last_response.header["X-Rack-ECG-Version"]).to eq(Rack::ECG::VERSION)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when all checks pass" do
|
57
|
+
it "has a success error code" do
|
58
|
+
get "_ecg"
|
59
|
+
expect(last_response.status).to eq(200)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when a checks errors" do
|
64
|
+
let(:options) {
|
65
|
+
{ checks: [:error] }
|
66
|
+
}
|
67
|
+
it "has a success error code" do
|
68
|
+
get "_ecg"
|
69
|
+
expect(last_response.status).to eq(500)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "git revision" do
|
74
|
+
let(:options) {
|
75
|
+
{ checks: [:git_revision] }
|
76
|
+
}
|
77
|
+
context "when available" do
|
78
|
+
let(:sha) { "cafe1234" }
|
79
|
+
it "is reported" do
|
80
|
+
expect(Open3).to receive(:popen3).
|
81
|
+
with("git rev-parse HEAD").
|
82
|
+
and_return([
|
83
|
+
nil, # stdin
|
84
|
+
StringIO.new(sha + "\n"), # stdout
|
85
|
+
StringIO.new(), # stderr
|
86
|
+
double(value: double(Process::Status, success?: true)) # wait thread & process status
|
87
|
+
])
|
88
|
+
get "/_ecg"
|
89
|
+
expect(json_body["git_revision"]["status"]).to eq("ok")
|
90
|
+
expect(json_body["git_revision"]["value"]).to eq(sha)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when not available" do
|
95
|
+
let(:error_message) { "git had a sad" }
|
96
|
+
it "is reported" do
|
97
|
+
expect(Open3).to receive(:popen3).
|
98
|
+
with("git rev-parse HEAD").
|
99
|
+
and_return([
|
100
|
+
nil, # stdin
|
101
|
+
StringIO.new(), # stdout
|
102
|
+
StringIO.new(error_message + "\n"), # stderr
|
103
|
+
double(value: double(Process::Status, success?: false)) # wait thread & process status
|
104
|
+
])
|
105
|
+
get "/_ecg"
|
106
|
+
expect(json_body["git_revision"]["status"]).to eq("error")
|
107
|
+
expect(json_body["git_revision"]["value"]).to eq("git had a sad")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "migration version" do
|
113
|
+
let(:options) {
|
114
|
+
{ checks: [:migration_version] }
|
115
|
+
}
|
116
|
+
context "when availabile" do
|
117
|
+
it "is reported" do
|
118
|
+
class ActiveRecord
|
119
|
+
class Base
|
120
|
+
def self.connection
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
version = "123456"
|
125
|
+
connection = double("connection")
|
126
|
+
expect(ActiveRecord::Base).to receive(:connection).and_return(connection)
|
127
|
+
expect(connection).to receive(:execute).
|
128
|
+
with("select max(version) as version from schema_migrations").
|
129
|
+
and_return([{"version" => version}])
|
130
|
+
get "/_ecg"
|
131
|
+
expect(json_body["migration_version"]["status"]).to eq("ok")
|
132
|
+
expect(json_body["migration_version"]["value"]).to eq(version)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when not available" do
|
137
|
+
it "is reported" do
|
138
|
+
Object.send(:remove_const, :ActiveRecord) if defined?(ActiveRecord)
|
139
|
+
get "/_ecg"
|
140
|
+
expect(json_body["migration_version"]["status"]).to eq("error")
|
141
|
+
expect(json_body["migration_version"]["value"]).to eq("ActiveRecord not found")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'rack/ecg'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.disable_monkey_patching!
|
15
|
+
|
16
|
+
config.warnings = true
|
17
|
+
|
18
|
+
config.include Rack::Test::Methods
|
19
|
+
|
20
|
+
def json_body
|
21
|
+
@json_body ||= JSON.parse(last_response.body)
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-ecg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Envato
|
8
|
+
- Julian Doherty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.7'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.7'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.2.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.2.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rack-test
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.6.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.6.3
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: pry
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.10.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.10.1
|
98
|
+
description: 'rack-ecg allows you to serve a page that shows you facts about your
|
99
|
+
deployed app to allow you to check that everything is running as it should: git
|
100
|
+
revision, database migrations, and more'
|
101
|
+
email:
|
102
|
+
- julian@envato.com
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- ".rspec"
|
109
|
+
- ".travis.yml"
|
110
|
+
- CODE_OF_CONDUCT.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- examples/basic.ru
|
116
|
+
- examples/checks.ru
|
117
|
+
- examples/mounted_path.ru
|
118
|
+
- lib/rack-ecg.rb
|
119
|
+
- lib/rack/ecg.rb
|
120
|
+
- lib/rack/ecg/version.rb
|
121
|
+
- rack-ecg.gemspec
|
122
|
+
- spec/rack_middleware_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/envato/rack-ecg
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.4.5
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Rack middleware serving a health check page
|
148
|
+
test_files:
|
149
|
+
- spec/rack_middleware_spec.rb
|
150
|
+
- spec/spec_helper.rb
|