server_health_check-rack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/server_health_check-rack.rb +1 -0
- data/lib/server_health_check/rack.rb +1 -0
- data/lib/server_health_check_rack.rb +8 -0
- data/lib/server_health_check_rack/checks.rb +59 -0
- data/lib/server_health_check_rack/config.rb +29 -0
- data/lib/server_health_check_rack/health_check.rb +33 -0
- data/lib/server_health_check_rack/middleware.rb +35 -0
- data/lib/server_health_check_rack/version.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad2aea3b6299d7dde8395261e60262e3298f1284
|
4
|
+
data.tar.gz: 58db36d58aa8a8e4d171753483182aa2ddf3f8bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac7b17e14c448cfc16798a72a9ce56e6d904edc2546694bebe7c9d9ddd43640c5dc10c2e97d06f44a3f1bf3c3edb7ac5a000bda32ec5364bd5ef771ee11ba09a
|
7
|
+
data.tar.gz: dc0fe38d59c6a938a410645a68c5c6830189cadb20a659cb2aaf896dbb3d569b350f7519ea5b89abc2449ca61bb48320e0a2855ab4263057915e7ba335bccf49
|
@@ -0,0 +1 @@
|
|
1
|
+
require "server_health_check_rack"
|
@@ -0,0 +1 @@
|
|
1
|
+
require "server_health_check_rack"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "server_health_check_rack/version"
|
2
|
+
|
3
|
+
module ServerHealthCheckRack
|
4
|
+
autoload :Checks, "server_health_check_rack/checks"
|
5
|
+
autoload :Config, "server_health_check_rack/config"
|
6
|
+
autoload :HealthCheck, "server_health_check_rack/health_check"
|
7
|
+
autoload :Middleware, "server_health_check_rack/middleware"
|
8
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "set"
|
2
|
+
|
3
|
+
module ServerHealthCheckRack
|
4
|
+
class Checks
|
5
|
+
class << self
|
6
|
+
def all_checks
|
7
|
+
raise ArgumentError, "Please configure server_health_check-rack!" if @checks.nil?
|
8
|
+
@checks.keys
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply_checks(server_health_check, checks)
|
12
|
+
raise ArgumentError, "Please configure server_health_check-rack!" if @checks.nil?
|
13
|
+
checks = Set.new(checks)
|
14
|
+
|
15
|
+
@checks.each do |name, check|
|
16
|
+
next unless checks.include?(name)
|
17
|
+
check.call(server_health_check)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def check(name, &block)
|
22
|
+
add_check name do |server_health_check|
|
23
|
+
server_health_check.check!(name, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_active_record!
|
28
|
+
add_check "active_record" do |server_health_check|
|
29
|
+
server_health_check.active_record!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_redis!(host: nil, port: 6379)
|
34
|
+
add_check "redis" do |server_health_check|
|
35
|
+
server_health_check.redis! host: host, port: port
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_aws_s3!(bucket = nil)
|
40
|
+
add_check "aws_s3" do |server_health_check|
|
41
|
+
server_health_check.aws_s3! bucket
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_aws_creds!
|
46
|
+
add_check "aws_creds" do |server_health_check|
|
47
|
+
server_health_check.aws_creds!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def add_check(name, &block)
|
54
|
+
@checks ||= {}
|
55
|
+
@checks[name] = block
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ServerHealthCheckRack
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
attr_accessor :logger
|
5
|
+
|
6
|
+
def path=(value)
|
7
|
+
@path = value
|
8
|
+
@path.sub!(/\/\z/, "") if @path
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
@path ||= "/health"
|
13
|
+
end
|
14
|
+
|
15
|
+
def path?(rack_path_info)
|
16
|
+
return false unless rack_path_info.start_with?(path)
|
17
|
+
rack_path_info =~ /\A#{Regexp.quote(path)}(?:[\/?]|\z)/
|
18
|
+
end
|
19
|
+
|
20
|
+
def path_to_health_checks(rack_path_info)
|
21
|
+
raise ArgumentError, "Invalid health check path: #{rack_path_info}" unless path?(rack_path_info)
|
22
|
+
rack_path_info = rack_path_info.sub(/\?.*/, "")
|
23
|
+
rack_path_info.sub!(/\/\z/, "")
|
24
|
+
return :all if rack_path_info == path
|
25
|
+
[rack_path_info[/\/([^\/]*)\z/, 1]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "server_health_check"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module ServerHealthCheckRack
|
5
|
+
class HealthCheck
|
6
|
+
def initialize(*checks)
|
7
|
+
@check = ServerHealthCheck.new(logger: ServerHealthCheckRack::Config.logger)
|
8
|
+
ServerHealthCheckRack::Checks.apply_checks(@check, checks)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all
|
12
|
+
new(*ServerHealthCheckRack::Checks.all_checks)
|
13
|
+
end
|
14
|
+
|
15
|
+
def http_status
|
16
|
+
if @check.ok?
|
17
|
+
200
|
18
|
+
else
|
19
|
+
500
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
{
|
25
|
+
status: @check.results
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json
|
30
|
+
to_h.to_json
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ServerHealthCheckRack
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if ServerHealthCheckRack::Config.path?(env["PATH_INFO"])
|
9
|
+
check = health_check(env["PATH_INFO"])
|
10
|
+
[check.http_status, response_headers, [check.to_json]]
|
11
|
+
else
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def health_check(rack_path_info)
|
19
|
+
checks = ServerHealthCheckRack::Config.path_to_health_checks(rack_path_info)
|
20
|
+
|
21
|
+
if checks == :all
|
22
|
+
ServerHealthCheckRack::HealthCheck.all
|
23
|
+
else
|
24
|
+
ServerHealthCheckRack::HealthCheck.new(*checks)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def response_headers
|
29
|
+
{
|
30
|
+
"Cache-Control" => "max-age=0, private, must-revalidate",
|
31
|
+
"Content-Type" => "application/json"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: server_health_check-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Virata-Stone
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: server_health_check
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.14'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.14'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '5.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.0'
|
75
|
+
description: Health check for Rack apps checking things like active record, redis,
|
76
|
+
and AWS.
|
77
|
+
email:
|
78
|
+
- mjstone@on-site.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- lib/server_health_check-rack.rb
|
84
|
+
- lib/server_health_check/rack.rb
|
85
|
+
- lib/server_health_check_rack.rb
|
86
|
+
- lib/server_health_check_rack/checks.rb
|
87
|
+
- lib/server_health_check_rack/config.rb
|
88
|
+
- lib/server_health_check_rack/health_check.rb
|
89
|
+
- lib/server_health_check_rack/middleware.rb
|
90
|
+
- lib/server_health_check_rack/version.rb
|
91
|
+
homepage: https://github.com/on-site/server_health_check-rack
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Healthcheck for Rack apps.
|
115
|
+
test_files: []
|