rack-haproxy_status 0.8.1 → 0.9.0
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.
- checksums.yaml +4 -4
- data/lib/rack/haproxy_status.rb +17 -6
- data/lib/rack/haproxy_status/version.rb +1 -1
- data/spec/rack-haproxy_status_spec.rb +29 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b99c7892b98ab925a0840e7742eece6a125e2330
|
4
|
+
data.tar.gz: 9b399ab748ccd22c484ff4d062561025f037194f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bda358c25493572ecd740ea2856456765188ea81b6b0b73d70824de2cd7961f015b288392074e2f4b5b3eeb6e2be7a465443ed4c5d95c00b10ed67983be1c6d
|
7
|
+
data.tar.gz: b7e16a5ab89ddeea4baed733e0e419aa79caaf7bba7716859b3a5a4e4b90b36ea460d19e0bb445d43e179c1481e359e3e7f8a72fc809209af9125ebb67a5866a
|
data/lib/rack/haproxy_status.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rack/haproxy_status/version"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
module Rack
|
4
5
|
module HaproxyStatus
|
@@ -7,17 +8,23 @@ module Rack
|
|
7
8
|
|
8
9
|
VALID_STATES = %w(on off)
|
9
10
|
|
10
|
-
def initialize(path:, io: ::File)
|
11
|
+
def initialize(path:, io: ::File, extra_checks: [])
|
11
12
|
@path = path
|
12
13
|
@io = io
|
14
|
+
@extra_checks = extra_checks
|
13
15
|
end
|
14
16
|
|
15
17
|
def call(env)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
balancer_member = balancer_member?
|
19
|
+
extra_checks_all_successful = extra_checks_all_successful?
|
20
|
+
http_code = balancer_member && extra_checks_all_successful ? 200 : 503
|
21
|
+
status = extra_checks_all_successful ? 'ok' : 'error'
|
22
|
+
|
23
|
+
[
|
24
|
+
http_code,
|
25
|
+
{'Content-Type' => 'application/json'},
|
26
|
+
[JSON.generate(status: status, member: balancer_member?)]
|
27
|
+
]
|
21
28
|
rescue InvalidStatus
|
22
29
|
[500, {'Content-Type' => 'application/json'}, ['{"status": "unknown status"}']]
|
23
30
|
end
|
@@ -29,6 +36,10 @@ module Rack
|
|
29
36
|
raise InvalidStatus, "Invalid state: #{state}" unless VALID_STATES.include?(state)
|
30
37
|
state == "on"
|
31
38
|
end
|
39
|
+
|
40
|
+
def extra_checks_all_successful?
|
41
|
+
@extra_checks.map { |check| check.call() }.all?
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
end
|
@@ -3,7 +3,8 @@ require 'json'
|
|
3
3
|
|
4
4
|
describe Rack::HaproxyStatus::Endpoint do
|
5
5
|
let(:disk) { double("File", read: "on") }
|
6
|
-
let(:
|
6
|
+
let(:extra_checks) { [] }
|
7
|
+
let(:response) { described_class.new(path: 'config/status', io: disk, extra_checks: extra_checks).call({}) }
|
7
8
|
let(:response_status) { response[0] }
|
8
9
|
let(:response_headers) { response[1] }
|
9
10
|
let(:response_body) { response[2] }
|
@@ -31,4 +32,31 @@ describe Rack::HaproxyStatus::Endpoint do
|
|
31
32
|
expect(response_status).to eq(500)
|
32
33
|
end
|
33
34
|
end
|
35
|
+
|
36
|
+
describe 'extra_checks that succeed' do
|
37
|
+
let(:extra_checks) { [Proc.new { true }] }
|
38
|
+
|
39
|
+
it 'should be in the balancer' do
|
40
|
+
expect(response_status).to eq(200)
|
41
|
+
expect(result.fetch('status')).to eq('ok')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'extra_checks that fail' do
|
46
|
+
let(:extra_checks) { [Proc.new { 3 == 2 }] }
|
47
|
+
|
48
|
+
it 'should not be in the balancer' do
|
49
|
+
expect(response_status).to eq(503)
|
50
|
+
expect(result.fetch('status')).to eq('error')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'extra_checks that partially fail' do
|
55
|
+
let(:extra_checks) { [Proc.new { 3 == 3 }, Proc.new { 3 == 2 }] }
|
56
|
+
|
57
|
+
it 'should not be in the balancer' do
|
58
|
+
expect(response_status).to eq(503)
|
59
|
+
expect(result.fetch('status')).to eq('error')
|
60
|
+
end
|
61
|
+
end
|
34
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-haproxy_status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,10 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.5.2
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: Tiny mountable app that returns an HTTP state based on contents of a file.
|
96
96
|
test_files:
|
97
97
|
- spec/rack-haproxy_status_spec.rb
|
98
|
-
has_rdoc:
|