health 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/health.gemspec +27 -0
- data/lib/health.rb +31 -0
- data/lib/health/checker.rb +35 -0
- data/lib/health/checks.rb +5 -0
- data/lib/health/checks/rollout.rb +19 -0
- data/lib/health/endpoint.rb +26 -0
- data/lib/health/version.rb +3 -0
- metadata +16 -6
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
health (0.0.1)
|
5
|
+
sinatra
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
rack (1.4.1)
|
11
|
+
rack-protection (1.2.0)
|
12
|
+
rack
|
13
|
+
sinatra (1.3.3)
|
14
|
+
rack (~> 1.3, >= 1.3.6)
|
15
|
+
rack-protection (~> 1.2)
|
16
|
+
tilt (~> 1.3, >= 1.3.3)
|
17
|
+
tilt (1.3.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (>= 1.0.0)
|
24
|
+
health!
|
data/health.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "health/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "health"
|
7
|
+
s.version = Health::VERSION
|
8
|
+
s.authors = ["James Golick"]
|
9
|
+
s.email = ["jamesgolick@gmail.com"]
|
10
|
+
s.description = "Health checks for rails."
|
11
|
+
s.summary = "Health checks for rails."
|
12
|
+
s.homepage = "https://github.com/jamesgolick/health"
|
13
|
+
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.rubyforge_project = "health"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# specify any dependencies here; for example:
|
24
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
25
|
+
|
26
|
+
s.add_runtime_dependency "sinatra"
|
27
|
+
end
|
data/lib/health.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Health
|
2
|
+
autoload :Checker, "health/checker"
|
3
|
+
autoload :Checks, "health/checks"
|
4
|
+
autoload :Endpoint, "health/endpoint"
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def checker
|
8
|
+
@checker ||= Checker.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure(&block)
|
12
|
+
checker.configure(&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform(name)
|
16
|
+
checker.perform(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def names
|
20
|
+
checker.names
|
21
|
+
end
|
22
|
+
|
23
|
+
def endpoint_access_policy(&block)
|
24
|
+
if block_given?
|
25
|
+
@endpoint_access_policy = block
|
26
|
+
else
|
27
|
+
@endpoint_access_policy ||= proc { true }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Health
|
2
|
+
class Checker
|
3
|
+
def checks
|
4
|
+
@checks ||= {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure(&block)
|
8
|
+
instance_eval(&block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check(name_or_object, &block)
|
12
|
+
if name_or_object.respond_to?(:call)
|
13
|
+
checks[name_or_object.name] = name_or_object
|
14
|
+
else
|
15
|
+
checks[name_or_object] = block
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def names
|
20
|
+
checks.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform(name)
|
24
|
+
checks[name.to_sym].call.tap do |result|
|
25
|
+
assert_necessary_keys(result)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def assert_necessary_keys(result)
|
31
|
+
(result.has_key?(:ok) && result.has_key?(:output)) ||
|
32
|
+
raise("Check results MUST have :ok and :output keys.")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Health
|
2
|
+
module Checks
|
3
|
+
class Rollout
|
4
|
+
def initialize(rollout_name, rollout = $rollout)
|
5
|
+
@rollout_name = rollout_name
|
6
|
+
@rollout = rollout
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
"#{@rollout_name}_rollout"
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
{:ok => @rollout.active?(@rollout_name),
|
15
|
+
:output => @rollout.get(@rollout_name).to_hash}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
|
3
|
+
module Health
|
4
|
+
class Endpoint < Sinatra::Base
|
5
|
+
before do
|
6
|
+
content_type "application/json"
|
7
|
+
|
8
|
+
if !instance_eval(&Health.endpoint_access_policy)
|
9
|
+
halt "Access denied."
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
get "/" do
|
14
|
+
Health.names.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
get "/:name" do
|
18
|
+
pass if !Health.names.include?(params[:name].to_sym)
|
19
|
+
|
20
|
+
value = Health.perform(params[:name])
|
21
|
+
status = value[:ok] ? 200 : 500
|
22
|
+
|
23
|
+
[status, value.to_json]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-11-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70364561163080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70364561163080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sinatra
|
27
|
-
requirement: &
|
27
|
+
requirement: &70364561162660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,14 +32,24 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70364561162660
|
36
36
|
description: Health checks for rails.
|
37
37
|
email:
|
38
38
|
- jamesgolick@gmail.com
|
39
39
|
executables: []
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
|
-
files:
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- health.gemspec
|
47
|
+
- lib/health.rb
|
48
|
+
- lib/health/checker.rb
|
49
|
+
- lib/health/checks.rb
|
50
|
+
- lib/health/checks/rollout.rb
|
51
|
+
- lib/health/endpoint.rb
|
52
|
+
- lib/health/version.rb
|
43
53
|
homepage: https://github.com/jamesgolick/health
|
44
54
|
licenses: []
|
45
55
|
post_install_message:
|