mini_check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +11 -0
- data/LICENSE.md +20 -0
- data/README.md +73 -0
- data/Rakefile +1 -0
- data/lib/mini_check/check.rb +44 -0
- data/lib/mini_check/checks_collection.rb +24 -0
- data/lib/mini_check/rack_app.rb +52 -0
- data/lib/mini_check/version.rb +3 -0
- data/lib/mini_check.rb +8 -0
- data/mini_check.gemspec +23 -0
- data/spec/helper.rb +24 -0
- data/spec/mini_check/check_spec.rb +137 -0
- data/spec/mini_check/checks_collection_spec.rb +77 -0
- data/spec/mini_check/rack_app_spec.rb +102 -0
- data/spec/mini_check_spec.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZThjMjY1Mzg1NWYyZDg0YjcyODE4Y2ZmMmQxNzI0NDY3YjIzYzQ5ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTQ5YzMwZGZhMDZkNWYzNmEyYzliYThjNzAzOWZiZTQ1MTMzNDY4NA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTAwNGRlMjI5ZGFmNGU0Y2VhOTUyYTM5NWVmZTQ1NzZkOGI5Mzg0NWY1ZjM2
|
10
|
+
M2EzNTlkZTZhZjNjNDRlYWQwMTE3ODljMmNhZDQ1OTM5MWMyMWYzNGE3ZGQ1
|
11
|
+
NTYzODgwNjEyMGJkNjE5NzE4YTVmNTBiMjllMjc4ODBlNjY3MGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGQwOTJkMWRkNDI5N2JlYmRhNzU4M2E3NmFmNDE3Nzg1NDc1ZDRiMGI1ZTkw
|
14
|
+
YzkyNjQ0ZGZkYzM5NjkxODAxNTJlYWU0NDA2NGU0NTI1N2MzNDNjNWRhODU5
|
15
|
+
ZGUzZDExY2I5ZGI4MzUzMDA1OWIwYTA4NmQzNDdjYmE4Yzg4Mzc=
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Manuel Morales, Workshare ltd., et al.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# MiniCheck
|
2
|
+
|
3
|
+
MiniCheck provides a simple Rack application for adding simple health checks to your app.
|
4
|
+
The JSON output is similar to the one provided by the [Metrics](http://metrics.codahale.com/) Java library.
|
5
|
+
It was started at [Workshare ltd.](http://www.workshare.com) as an easy way of providing monitoring to our Rack based applciations.
|
6
|
+
|
7
|
+
|
8
|
+
## Quick Start
|
9
|
+
|
10
|
+
Install the gem with the usual `gem install mini_check`.
|
11
|
+
Build a new Rack app and register some checks
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
MyHealthCheck = MiniCheck::RackApp.new(path: '/healthcheck')
|
15
|
+
MyHealthCheck.register('health.redis_client'){ MyApp.redis_client.connected? }
|
16
|
+
MyHealthCheck.register('health.db_connection'){ MyApp.db_connection.fetch('show tables').to_a }
|
17
|
+
```
|
18
|
+
|
19
|
+
Mount it in your `config.ru`:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
run Rack::Cascade.new([
|
23
|
+
MyHealthCheck,
|
24
|
+
MyApp,
|
25
|
+
])
|
26
|
+
```
|
27
|
+
|
28
|
+
If you now visit `http://localhost:XXXX/healthcheck` you should get something like:
|
29
|
+
|
30
|
+
```json
|
31
|
+
{
|
32
|
+
"health.db_connection": {
|
33
|
+
"healthy": true
|
34
|
+
},
|
35
|
+
"health.redis_client": {
|
36
|
+
"healthy": true
|
37
|
+
}
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
The registered lambdas should do any of the following things:
|
42
|
+
|
43
|
+
* Return true if the check was successful.
|
44
|
+
* Return false if not.
|
45
|
+
* Raise an exception which will be understood as not healthy. Find an example of the output below:
|
46
|
+
|
47
|
+
```json
|
48
|
+
{
|
49
|
+
"health.db_connection": {
|
50
|
+
"healthy": false,
|
51
|
+
"error": {
|
52
|
+
"message": "Mysql2::Error: MySQL server has gone away",
|
53
|
+
"stack": [
|
54
|
+
"/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/adapters/mysql2.rb:77:in `query'",
|
55
|
+
"/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/adapters/mysql2.rb:77:in `block in _execute'",
|
56
|
+
"/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/database/logging.rb:37:in `log_yield'",
|
57
|
+
"..."
|
58
|
+
]
|
59
|
+
}
|
60
|
+
},
|
61
|
+
"health.redis_client": {
|
62
|
+
"healthy": true
|
63
|
+
}
|
64
|
+
}
|
65
|
+
```
|
66
|
+
|
67
|
+
The http status code will be 200 if all checks are healthy and 500 otherwise.
|
68
|
+
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
Released under the MIT License. See the [LICENSE](LICENSE.md) file for further details.
|
73
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module MiniCheck
|
2
|
+
class Check
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :healthy
|
5
|
+
attr_accessor :action
|
6
|
+
attr_accessor :exception
|
7
|
+
|
8
|
+
def initialize args = {}, &block
|
9
|
+
args = {name: args} if !args.is_a?(Hash)
|
10
|
+
args[:action] = block if block_given?
|
11
|
+
|
12
|
+
set_attributes args
|
13
|
+
end
|
14
|
+
|
15
|
+
def healthy?
|
16
|
+
!!healthy
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
begin
|
21
|
+
self.healthy = action.call
|
22
|
+
self.exception = nil
|
23
|
+
rescue Exception => e
|
24
|
+
self.healthy = false
|
25
|
+
self.exception = e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_hash
|
30
|
+
{}.tap do |h|
|
31
|
+
h[:healthy] = healthy?
|
32
|
+
h[:error] = {message: exception.message, stack: exception.backtrace} if exception
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def set_attributes args = {}
|
39
|
+
args.each do |k,v|
|
40
|
+
send("#{k}=", v)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MiniCheck
|
2
|
+
class ChecksCollection < Array
|
3
|
+
def to_hash
|
4
|
+
resp = {}
|
5
|
+
each.map do |check|
|
6
|
+
resp[check.name] = check.to_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
resp
|
10
|
+
end
|
11
|
+
|
12
|
+
def healthy?
|
13
|
+
!detect{|c| !c.healthy? }
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
each{|c| c.run }
|
18
|
+
end
|
19
|
+
|
20
|
+
def register name, &block
|
21
|
+
self.<< Check.new(name, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module MiniCheck
|
2
|
+
class RackApp
|
3
|
+
attr_accessor :checks
|
4
|
+
attr_accessor :path
|
5
|
+
|
6
|
+
def initialize args = {}
|
7
|
+
set_attributes args
|
8
|
+
end
|
9
|
+
|
10
|
+
def checks
|
11
|
+
@checks ||= ChecksCollection.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def call env
|
15
|
+
case "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
|
16
|
+
when "GET #{path}"
|
17
|
+
checks.run
|
18
|
+
[status, headers, [body]]
|
19
|
+
else
|
20
|
+
[404, headers, []]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def register name, &block
|
25
|
+
checks.register name, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_attributes args = {}
|
31
|
+
args.each do |k,v|
|
32
|
+
send("#{k}=", v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def headers
|
37
|
+
{'Content-Type' => 'application/json'}
|
38
|
+
end
|
39
|
+
|
40
|
+
def body
|
41
|
+
checks.to_hash.to_json
|
42
|
+
end
|
43
|
+
|
44
|
+
def generally_healthy?
|
45
|
+
checks.healthy?
|
46
|
+
end
|
47
|
+
|
48
|
+
def status
|
49
|
+
generally_healthy? ? 200 : 500
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/mini_check.rb
ADDED
data/mini_check.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mini_check/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mini_check'
|
8
|
+
spec.version = MiniCheck::VERSION
|
9
|
+
spec.authors = ['Manuel Morales']
|
10
|
+
spec.email = ['manuelmorales@gmail.com']
|
11
|
+
spec.description = %q{MiniCheck provides a simple Rack application for adding simple health checks to your app.}
|
12
|
+
spec.summary = %q{MiniCheck provides a simple Rack application for adding simple health checks to your app.}
|
13
|
+
spec.homepage = 'https://github.com/workshare/mini-check'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_runtime_dependency 'json'
|
23
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rspec'
|
13
|
+
require 'pry'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color_enabled = true
|
17
|
+
config.tty = true
|
18
|
+
config.formatter = :documentation # :documentation, :progress, :html, :textmate
|
19
|
+
end
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift File.expand_path('lib')
|
22
|
+
require 'mini_check'
|
23
|
+
|
24
|
+
$LOAD_PATH.unshift File.expand_path('spec/support')
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
shared_examples_for 'check' do
|
4
|
+
it{ should respond_to(:to_hash) }
|
5
|
+
it{ should respond_to(:name) }
|
6
|
+
it{ should respond_to(:healthy?) }
|
7
|
+
it{ should respond_to(:run) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe MiniCheck::Check do
|
11
|
+
subject{ MiniCheck::Check.new name: name, action: action }
|
12
|
+
let(:name){ 'my_check' }
|
13
|
+
let(:action){ proc{ true } }
|
14
|
+
let(:exception){ Exception.new('My message') }
|
15
|
+
|
16
|
+
it_behaves_like 'check'
|
17
|
+
|
18
|
+
describe 'initialize' do
|
19
|
+
it 'allows passing attributes as a hash' do
|
20
|
+
check = MiniCheck::Check.new name: name, action: action
|
21
|
+
expect(check.name).to eq(name)
|
22
|
+
expect(check.action).to eq(action)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'allows building by name and proc' do
|
26
|
+
check = MiniCheck::Check.new(name, &action)
|
27
|
+
|
28
|
+
expect(check.name).to eq(name)
|
29
|
+
expect(check.action).to eq(action)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'run' do
|
34
|
+
it 'calls the action' do
|
35
|
+
action.should receive(:call)
|
36
|
+
subject.run
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when the action returns an object (success)' do
|
40
|
+
before :each do
|
41
|
+
allow(action).to receive(:call).and_return(Object.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets the healthy? to true' do
|
45
|
+
subject.healthy = nil
|
46
|
+
subject.run
|
47
|
+
expect(subject.healthy?).to eq(true)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'blanks the exception' do
|
51
|
+
subject.exception = Exception.new
|
52
|
+
subject.run
|
53
|
+
expect(subject.exception).to be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the action returns false' do
|
58
|
+
before :each do
|
59
|
+
allow(action).to receive(:call).and_return(false)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'sets the healthy? to false' do
|
63
|
+
subject.healthy = true
|
64
|
+
subject.run
|
65
|
+
expect(subject.healthy?).to eq(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'blanks the exception' do
|
69
|
+
subject.exception = Exception.new
|
70
|
+
subject.run
|
71
|
+
expect(subject.exception).to be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when the action raises an exception' do
|
76
|
+
before :each do
|
77
|
+
allow(action).to receive(:call).and_raise(exception)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'sets the healthy? to false' do
|
81
|
+
subject.healthy = true
|
82
|
+
subject.run
|
83
|
+
expect(subject.healthy?).to eq(false)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'sets the exception to the exception' do
|
87
|
+
subject.exception = nil
|
88
|
+
subject.run
|
89
|
+
expect(subject.exception).to be(exception)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'to_hash' do
|
95
|
+
context 'when the run was successful' do
|
96
|
+
before :each do
|
97
|
+
allow(action).to receive(:call).and_return(Object.new)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns the basic healthy hash' do
|
101
|
+
subject.run
|
102
|
+
expect(subject.to_hash).to eq(healthy: true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when the action returns false' do
|
107
|
+
before :each do
|
108
|
+
allow(action).to receive(:call).and_return(false)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns the basic healthy hash' do
|
112
|
+
subject.run
|
113
|
+
expect(subject.to_hash).to eq(healthy: false)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when the action raises an exception' do
|
118
|
+
before :each do
|
119
|
+
exception.stub(backtrace: ['a'])
|
120
|
+
allow(action).to receive(:call).and_raise(exception)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns the hash with error' do
|
124
|
+
subject.run
|
125
|
+
expect(subject.to_hash).to eq(
|
126
|
+
{
|
127
|
+
:healthy => false,
|
128
|
+
:error => {
|
129
|
+
:message => exception.message,
|
130
|
+
:stack => exception.backtrace,
|
131
|
+
}
|
132
|
+
}
|
133
|
+
)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
shared_examples_for 'checks collection' do
|
4
|
+
it{ should respond_to(:to_hash) }
|
5
|
+
it{ should respond_to(:healthy?) }
|
6
|
+
it{ should respond_to(:<<) }
|
7
|
+
it{ should respond_to(:run) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe MiniCheck::ChecksCollection do
|
11
|
+
it_behaves_like 'checks collection'
|
12
|
+
|
13
|
+
let(:check_hash){ {healthy: true} }
|
14
|
+
let(:check){ build_check(name: 'my_check') }
|
15
|
+
|
16
|
+
def build_check args = {}
|
17
|
+
stubs = {healthy?: true, to_hash: check_hash, run: true}
|
18
|
+
@name_counter ||= 0
|
19
|
+
stubs[:name] = "name_#{@name_counter += 1}"
|
20
|
+
stubs.merge! args
|
21
|
+
|
22
|
+
double(stubs[:name], stubs)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'to_hash' do
|
26
|
+
it 'uses the name as key' do
|
27
|
+
subject << check_1 = build_check
|
28
|
+
subject << check_2 = build_check
|
29
|
+
|
30
|
+
expected_hash = {
|
31
|
+
check_1.name => check_hash,
|
32
|
+
check_2.name => check_hash,
|
33
|
+
}
|
34
|
+
|
35
|
+
expect(subject.to_hash).to eq(expected_hash)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'healthy?' do
|
40
|
+
it 'is true when all are true' do
|
41
|
+
subject << build_check(healthy?: true)
|
42
|
+
subject << build_check(healthy?: true)
|
43
|
+
subject << build_check(healthy?: true)
|
44
|
+
|
45
|
+
expect(subject.healthy?).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is true when one is false' do
|
49
|
+
subject << build_check(healthy?: true)
|
50
|
+
subject << build_check(healthy?: false)
|
51
|
+
subject << build_check(healthy?: true)
|
52
|
+
|
53
|
+
expect(subject.healthy?).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'run' do
|
58
|
+
it 'runs each of the checks' do
|
59
|
+
subject << check
|
60
|
+
|
61
|
+
expect(check).to receive(:run)
|
62
|
+
subject.run
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'register' do
|
67
|
+
it 'adds a new check to the collection' do
|
68
|
+
name = 'asd'
|
69
|
+
block = proc{}
|
70
|
+
|
71
|
+
expect(MiniCheck::Check).to receive(:new).with(name, &block).and_return(check)
|
72
|
+
subject.register(name, &block)
|
73
|
+
expect(subject.last).to be(check)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
describe MiniCheck::RackApp do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
subject{ MiniCheck::RackApp.new checks: checks, path: '/health'}
|
8
|
+
let(:app){ subject }
|
9
|
+
let(:checks_hash){ {'my_check' => {'health' => true}} }
|
10
|
+
let(:checks){ double(:healthy? => true, :to_hash => checks_hash, :<< => true, :run => true) }
|
11
|
+
|
12
|
+
def status
|
13
|
+
last_response.status
|
14
|
+
end
|
15
|
+
|
16
|
+
def headers
|
17
|
+
last_response.headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
last_response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def body_json
|
25
|
+
JSON.parse(body)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe :call do
|
29
|
+
it 'returns status, headers, body' do
|
30
|
+
get '/'
|
31
|
+
expect(status).to be_a(Fixnum)
|
32
|
+
expect(headers).to be_a(Hash)
|
33
|
+
expect(body).to be_a(String)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'unknown path' do
|
37
|
+
it 'returns status 404' do
|
38
|
+
get '/blahblah'
|
39
|
+
expect(status).to eq(404)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'unknown verb' do
|
44
|
+
it 'returns status 404' do
|
45
|
+
post '/health'
|
46
|
+
expect(status).to eq(404)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'GET /health' do
|
51
|
+
def do_request
|
52
|
+
get '/health'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns status 200' do
|
56
|
+
do_request
|
57
|
+
expect(status).to eq(200)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns content type json' do
|
61
|
+
do_request
|
62
|
+
expect(headers['Content-Type']).to eq('application/json')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns JSON body' do
|
66
|
+
do_request
|
67
|
+
expect(JSON.parse(body)).to eq(checks_hash)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'calls run on the checks' do
|
71
|
+
expect(checks).to receive(:run).and_return(true)
|
72
|
+
do_request
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns each check' do
|
76
|
+
expect(checks).to receive(:healthy?).and_return(true)
|
77
|
+
do_request
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'has status 500 when one check is failing' do
|
81
|
+
expect(checks).to receive(:healthy?).and_return(true)
|
82
|
+
do_request
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'register' do
|
88
|
+
it 'forwards to checks' do
|
89
|
+
name = 'asd'
|
90
|
+
block = proc{}
|
91
|
+
expect(checks).to receive(:register).with(name, &block)
|
92
|
+
subject.register(name, &block)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
## MOCKS ##
|
97
|
+
|
98
|
+
describe 'checks' do
|
99
|
+
subject{ checks }
|
100
|
+
it_behaves_like 'checks collection'
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mini_check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manuel Morales
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: MiniCheck provides a simple Rack application for adding simple health
|
42
|
+
checks to your app.
|
43
|
+
email:
|
44
|
+
- manuelmorales@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.md
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/mini_check.rb
|
56
|
+
- lib/mini_check/check.rb
|
57
|
+
- lib/mini_check/checks_collection.rb
|
58
|
+
- lib/mini_check/rack_app.rb
|
59
|
+
- lib/mini_check/version.rb
|
60
|
+
- mini_check.gemspec
|
61
|
+
- spec/helper.rb
|
62
|
+
- spec/mini_check/check_spec.rb
|
63
|
+
- spec/mini_check/checks_collection_spec.rb
|
64
|
+
- spec/mini_check/rack_app_spec.rb
|
65
|
+
- spec/mini_check_spec.rb
|
66
|
+
homepage: https://github.com/workshare/mini-check
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.1.11
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: MiniCheck provides a simple Rack application for adding simple health checks
|
90
|
+
to your app.
|
91
|
+
test_files:
|
92
|
+
- spec/helper.rb
|
93
|
+
- spec/mini_check/check_spec.rb
|
94
|
+
- spec/mini_check/checks_collection_spec.rb
|
95
|
+
- spec/mini_check/rack_app_spec.rb
|
96
|
+
- spec/mini_check_spec.rb
|