wellness 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -3
- data/lib/wellness/checker.rb +6 -41
- data/lib/wellness/middleware.rb +45 -0
- data/lib/wellness/version.rb +1 -1
- data/lib/wellness.rb +1 -0
- data/spec/wellness/checker_spec.rb +1 -1
- data/wellness.gemspec +0 -2
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc67d265fe3b43ff86c235e0317c32e20ccd0971
|
4
|
+
data.tar.gz: d7a96511cebbaeee9926489760d3bcf7667227f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee1f255adf40cdd1f3ba90a31e28ae4f8b0fb5c9b6e9d31eb23f41c9646e71c0d53cf415ba8d9170b537a96eaea7c44fce3214aebab15c71bba0fe491b02cda3
|
7
|
+
data.tar.gz: 368f138e36a57ae792b92f9d7d6d2d934033a64219aef4686c99945c93f115bf982a096d54f09eef63b76207028d162288eb24f4497aa6f0d94e6ba003e984d4
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ redis = Wellness::Services::RedisService.new({
|
|
32
32
|
})
|
33
33
|
system.add_service('database', pg)
|
34
34
|
system.add_service('redis', redis)
|
35
|
-
config.middleware.insert_before('::ActiveRecord::QueryCache', 'Wellness::
|
35
|
+
config.middleware.insert_before('::ActiveRecord::QueryCache', 'Wellness::Middleware', system)
|
36
36
|
```
|
37
37
|
|
38
38
|
## Usage - Sinatra
|
@@ -56,7 +56,44 @@ redis = Wellness::Services::RedisService.new({
|
|
56
56
|
system.add_service('database', pg)
|
57
57
|
system.add_service('redis', redis)
|
58
58
|
|
59
|
-
use(Wellness::
|
59
|
+
use(Wellness::Middleware, system)
|
60
|
+
```
|
61
|
+
|
62
|
+
## Example Response
|
63
|
+
|
64
|
+
```json
|
65
|
+
{
|
66
|
+
"status":"UNHEALTHY",
|
67
|
+
"details":{
|
68
|
+
|
69
|
+
},
|
70
|
+
"dependencies":{
|
71
|
+
"database":{
|
72
|
+
"status":"UNHEALTHY",
|
73
|
+
"details":{
|
74
|
+
"error":"no response from ping"
|
75
|
+
}
|
76
|
+
},
|
77
|
+
"sidekiq":{
|
78
|
+
"status":"HEALTHY",
|
79
|
+
"details":{
|
80
|
+
"processed":0,
|
81
|
+
"failed":0,
|
82
|
+
"busy":0,
|
83
|
+
"enqueued":0,
|
84
|
+
"scheduled":0,
|
85
|
+
"retries":0,
|
86
|
+
"default_latency":0,
|
87
|
+
"redis":{
|
88
|
+
"uptime_in_days":"0",
|
89
|
+
"connected_clients":"1",
|
90
|
+
"used_memory_human":"979.22K",
|
91
|
+
"used_memory_peak_human":"1.02M"
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
60
97
|
```
|
61
98
|
|
62
99
|
## Custom Services
|
@@ -94,7 +131,7 @@ service = MyCustomService.new({foo: 'bar'})
|
|
94
131
|
system.add_service('some service', service)
|
95
132
|
|
96
133
|
# Load it into your rack
|
97
|
-
use(Wellness::
|
134
|
+
use(Wellness::Middleware, system)
|
98
135
|
```
|
99
136
|
|
100
137
|
## Contributing
|
data/lib/wellness/checker.rb
CHANGED
@@ -1,42 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Checker
|
4
|
-
def initialize(app, system, options={})
|
5
|
-
@app = app
|
6
|
-
@system = system
|
7
|
-
|
8
|
-
# Optional arguments
|
9
|
-
@health_status_path = options[:status_path] || '/health/status'
|
10
|
-
@health_details_path = options[:details_path] || '/health/details'
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
case env['PATH_INFO']
|
15
|
-
when @health_status_path
|
16
|
-
health_status(env)
|
17
|
-
when @health_details_path
|
18
|
-
health_details(env)
|
19
|
-
else
|
20
|
-
@app.call(env)
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require 'wellness/middleware'
|
23
2
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def health_details(env)
|
34
|
-
if @system.check
|
35
|
-
[200, {'Content-Type' => 'text/json'}, [@system.to_json]]
|
36
|
-
else
|
37
|
-
[500, {'Content-Type' => 'text/json'}, [@system.to_json]]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
3
|
+
module Wellness
|
4
|
+
# Backwards compatibility. This isn't a proper name for something that is
|
5
|
+
# supposed to be in the middleware.
|
6
|
+
Checker = Wellness::Middleware
|
7
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Wellness
|
2
|
+
|
3
|
+
# This is to be put into the Rack environment.
|
4
|
+
#
|
5
|
+
# @author Matthew A. Johnston
|
6
|
+
class Middleware
|
7
|
+
def initialize(app, system, options={})
|
8
|
+
@app = app
|
9
|
+
@system = system
|
10
|
+
|
11
|
+
# Optional arguments
|
12
|
+
@health_status_path = options[:status_path] || '/health/status'
|
13
|
+
@health_details_path = options[:details_path] || '/health/details'
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
case env['PATH_INFO']
|
18
|
+
when @health_status_path
|
19
|
+
health_status(env)
|
20
|
+
when @health_details_path
|
21
|
+
health_details(env)
|
22
|
+
else
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def health_status(env)
|
28
|
+
if @system.check
|
29
|
+
[200, {'Content-Type' => 'text/json'}, [{status: 'HEALTHY'}.to_json]]
|
30
|
+
else
|
31
|
+
[500, {'Content-Type' => 'text/json'}, [{status: 'UNHEALTHY'}.to_json]]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def health_details(env)
|
37
|
+
if @system.check
|
38
|
+
[200, {'Content-Type' => 'text/json'}, [@system.to_json]]
|
39
|
+
else
|
40
|
+
[500, {'Content-Type' => 'text/json'}, [@system.to_json]]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/wellness/version.rb
CHANGED
data/lib/wellness.rb
CHANGED
data/wellness.gemspec
CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency('rack', '~> 1.5')
|
22
|
-
|
23
21
|
spec.add_development_dependency('bundler', '~> 1.3')
|
24
22
|
spec.add_development_dependency('rake')
|
25
23
|
spec.add_development_dependency('rspec')
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wellness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rack
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.5'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.5'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +68,7 @@ files:
|
|
82
68
|
- Rakefile
|
83
69
|
- lib/wellness.rb
|
84
70
|
- lib/wellness/checker.rb
|
71
|
+
- lib/wellness/middleware.rb
|
85
72
|
- lib/wellness/services/base.rb
|
86
73
|
- lib/wellness/services/postgres_service.rb
|
87
74
|
- lib/wellness/services/redis_service.rb
|