litmus_paper 0.8.2 → 0.8.3
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/lib/litmus_paper/app.rb +5 -1
- data/lib/litmus_paper/health.rb +12 -3
- data/lib/litmus_paper/service.rb +2 -3
- data/lib/litmus_paper/status_file.rb +8 -8
- data/lib/litmus_paper/version.rb +1 -1
- data/lib/litmus_paper.rb +0 -1
- data/spec/litmus_paper/app_spec.rb +23 -6
- data/spec/litmus_paper/service_spec.rb +4 -4
- data/spec/litmus_paper/status_file_spec.rb +4 -4
- metadata +2 -3
- data/lib/litmus_paper/forced_health.rb +0 -22
data/lib/litmus_paper/app.rb
CHANGED
@@ -5,9 +5,10 @@ module LitmusPaper
|
|
5
5
|
get "/" do
|
6
6
|
output = "Litmus Paper #{LitmusPaper::VERSION}\n\n"
|
7
7
|
output += "Services monitored:\n"
|
8
|
+
output += " Service ( Health / Measured Health )\n"
|
8
9
|
LitmusPaper.services.each do |service_name, service|
|
9
10
|
health = service.current_health
|
10
|
-
output += "* #{service_name} (#{health.value})"
|
11
|
+
output += "* #{service_name} ( #{health.value} / #{health.measured_health} )"
|
11
12
|
if health.forced?
|
12
13
|
output += " - forced: #{service.current_health.summary}"
|
13
14
|
end
|
@@ -48,6 +49,9 @@ module LitmusPaper
|
|
48
49
|
|
49
50
|
headers = {"X-Health" => health.value.to_s}
|
50
51
|
body = "Health: #{health.value}\n"
|
52
|
+
if health.forced?
|
53
|
+
body << "Measured Health: #{health.measured_health}\n"
|
54
|
+
end
|
51
55
|
body << health.summary
|
52
56
|
|
53
57
|
if health.forced?
|
data/lib/litmus_paper/health.rb
CHANGED
@@ -3,10 +3,11 @@ module LitmusPaper
|
|
3
3
|
|
4
4
|
attr_reader :summary
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(forced = :none, summary = "")
|
7
7
|
@value = 0
|
8
8
|
@dependencies_available = true
|
9
|
-
@summary =
|
9
|
+
@summary = summary
|
10
|
+
@forced = forced
|
10
11
|
end
|
11
12
|
|
12
13
|
def ok?
|
@@ -14,10 +15,18 @@ module LitmusPaper
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def forced?
|
17
|
-
|
18
|
+
@forced != :none
|
18
19
|
end
|
19
20
|
|
20
21
|
def value
|
22
|
+
if forced?
|
23
|
+
return @forced == :up ? 100 : 0
|
24
|
+
end
|
25
|
+
|
26
|
+
measured_health
|
27
|
+
end
|
28
|
+
|
29
|
+
def measured_health
|
21
30
|
return 0 unless @dependencies_available
|
22
31
|
@value
|
23
32
|
end
|
data/lib/litmus_paper/service.rb
CHANGED
@@ -8,9 +8,8 @@ module LitmusPaper
|
|
8
8
|
|
9
9
|
def current_health
|
10
10
|
forced_health = _determine_forced_health
|
11
|
-
return forced_health unless forced_health.nil?
|
12
11
|
|
13
|
-
health = LitmusPaper::Health.new
|
12
|
+
health = forced_health ? forced_health : LitmusPaper::Health.new
|
14
13
|
@dependencies.each do |dependency|
|
15
14
|
health.ensure(dependency)
|
16
15
|
end
|
@@ -35,7 +34,7 @@ module LitmusPaper
|
|
35
34
|
|
36
35
|
def _determine_forced_health
|
37
36
|
_health_files.map do |status_file|
|
38
|
-
|
37
|
+
LitmusPaper::Health.new(status_file.forced, status_file.content) if status_file.exists?
|
39
38
|
end.compact.first
|
40
39
|
end
|
41
40
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
module LitmusPaper
|
2
2
|
class StatusFile
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :forced
|
4
4
|
|
5
5
|
def self.global_down_file
|
6
|
-
new("global_down",
|
6
|
+
new("global_down", :down)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.global_up_file
|
10
|
-
new("global_up",
|
10
|
+
new("global_up", :up)
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.service_down_file(service_name)
|
14
|
-
new("#{service_name}_down",
|
14
|
+
new("#{service_name}_down", :down)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.service_up_file(service_name)
|
18
|
-
new("#{service_name}_up",
|
18
|
+
new("#{service_name}_up", :up)
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.priority_check_order_for_service(service_name)
|
@@ -27,13 +27,13 @@ module LitmusPaper
|
|
27
27
|
]
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(filename,
|
30
|
+
def initialize(filename, forced)
|
31
31
|
@path = File.join(LitmusPaper.data_directory, filename)
|
32
|
-
@
|
32
|
+
@forced = forced
|
33
33
|
end
|
34
34
|
|
35
35
|
def content
|
36
|
-
File.read(@path).chomp
|
36
|
+
File.read(@path).chomp + "\n"
|
37
37
|
end
|
38
38
|
|
39
39
|
def create(reason)
|
data/lib/litmus_paper/version.rb
CHANGED
data/lib/litmus_paper.rb
CHANGED
@@ -31,7 +31,6 @@ require 'litmus_paper/dependency/http'
|
|
31
31
|
require 'litmus_paper/dependency/script'
|
32
32
|
require 'litmus_paper/dependency/tcp'
|
33
33
|
require 'litmus_paper/health'
|
34
|
-
require 'litmus_paper/forced_health'
|
35
34
|
require 'litmus_paper/logger'
|
36
35
|
require 'litmus_paper/metric/available_memory'
|
37
36
|
require 'litmus_paper/metric/big_brother_service'
|
@@ -35,7 +35,7 @@ describe LitmusPaper::App do
|
|
35
35
|
get "/"
|
36
36
|
|
37
37
|
last_response.status.should == 200
|
38
|
-
last_response.body.should include("* test (0)\n")
|
38
|
+
last_response.body.should include("* test ( 0 / 0 )\n")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "includes the status if forced" do
|
@@ -48,8 +48,8 @@ describe LitmusPaper::App do
|
|
48
48
|
get "/"
|
49
49
|
|
50
50
|
last_response.status.should == 200
|
51
|
-
last_response.body.should include("* another (0) - forced: Down for testing\n")
|
52
|
-
last_response.body.should include("* test (100) - forced: Up for testing\n")
|
51
|
+
last_response.body.should include("* another ( 0 / 0 ) - forced: Down for testing\n")
|
52
|
+
last_response.body.should include("* test ( 100 / 0 ) - forced: Up for testing\n")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -212,8 +212,23 @@ describe LitmusPaper::App do
|
|
212
212
|
last_response.body.should match(/Down for testing/)
|
213
213
|
end
|
214
214
|
|
215
|
-
it "
|
216
|
-
test_service = LitmusPaper::Service.new('test', [
|
215
|
+
it "still reports the health, dependencies, and metrics when forced down" do
|
216
|
+
test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
|
217
|
+
LitmusPaper.services['test'] = test_service
|
218
|
+
|
219
|
+
LitmusPaper::StatusFile.service_down_file("test").create("Down for testing")
|
220
|
+
|
221
|
+
get "/test/status"
|
222
|
+
|
223
|
+
last_response.status.should == 503
|
224
|
+
last_response.headers["X-Health-Forced"].should == "down"
|
225
|
+
last_response.body.should match(/Measured Health: 100\n/)
|
226
|
+
last_response.body.should match(/AlwaysAvailableDependency: OK\n/)
|
227
|
+
last_response.body.should match(/Metric::ConstantMetric\(100\): 100\n/)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "still reports the health, dependencies, and metrics when forced up" do
|
231
|
+
test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [LitmusPaper::Metric::ConstantMetric.new(100)])
|
217
232
|
LitmusPaper.services['test'] = test_service
|
218
233
|
|
219
234
|
LitmusPaper::StatusFile.service_up_file("test").create("Up for testing")
|
@@ -222,7 +237,9 @@ describe LitmusPaper::App do
|
|
222
237
|
|
223
238
|
last_response.status.should == 200
|
224
239
|
last_response.headers["X-Health-Forced"].should == "up"
|
225
|
-
last_response.body.should match(/
|
240
|
+
last_response.body.should match(/Measured Health: 100\n/)
|
241
|
+
last_response.body.should match(/AlwaysAvailableDependency: OK\n/)
|
242
|
+
last_response.body.should match(/Metric::ConstantMetric\(100\): 100\n/)
|
226
243
|
end
|
227
244
|
|
228
245
|
it "is 'service available' when an up file exists" do
|
@@ -26,7 +26,7 @@ describe LitmusPaper::Service do
|
|
26
26
|
LitmusPaper::StatusFile.service_down_file("test").create("Down for testing")
|
27
27
|
|
28
28
|
service.current_health.value.should == 0
|
29
|
-
service.current_health.summary.should
|
29
|
+
service.current_health.summary.should match(/Down for testing/)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "is 0 when a global down file exists" do
|
@@ -37,7 +37,7 @@ describe LitmusPaper::Service do
|
|
37
37
|
LitmusPaper::StatusFile.global_down_file.create("Down for testing")
|
38
38
|
|
39
39
|
service.current_health.value.should == 0
|
40
|
-
service.current_health.summary.should
|
40
|
+
service.current_health.summary.should match(/Down for testing/)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "is 100 when an up file exists" do
|
@@ -48,7 +48,7 @@ describe LitmusPaper::Service do
|
|
48
48
|
LitmusPaper::StatusFile.service_up_file("test").create("Up for testing")
|
49
49
|
|
50
50
|
service.current_health.value.should == 100
|
51
|
-
service.current_health.summary.should
|
51
|
+
service.current_health.summary.should match(/Up for testing/)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "is 100 when a global up file exists" do
|
@@ -59,7 +59,7 @@ describe LitmusPaper::Service do
|
|
59
59
|
LitmusPaper::StatusFile.global_up_file.create("Up for testing")
|
60
60
|
|
61
61
|
service.current_health.value.should == 100
|
62
|
-
service.current_health.summary.should
|
62
|
+
service.current_health.summary.should match(/Up for testing/)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -3,23 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe LitmusPaper::StatusFile do
|
4
4
|
describe "create" do
|
5
5
|
it "creates a file" do
|
6
|
-
status_file = LitmusPaper::StatusFile.new("foo",
|
6
|
+
status_file = LitmusPaper::StatusFile.new("foo", :up)
|
7
7
|
status_file.create("for testing")
|
8
8
|
|
9
9
|
status_file.exists?.should == true
|
10
10
|
end
|
11
11
|
|
12
12
|
it "writes the content" do
|
13
|
-
status_file = LitmusPaper::StatusFile.new("foo",
|
13
|
+
status_file = LitmusPaper::StatusFile.new("foo", :up)
|
14
14
|
status_file.create("for testing")
|
15
15
|
|
16
|
-
status_file.content.should
|
16
|
+
status_file.content.should match(/for testing/)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "delete" do
|
21
21
|
it "removes the file" do
|
22
|
-
status_file = LitmusPaper::StatusFile.new("foo",
|
22
|
+
status_file = LitmusPaper::StatusFile.new("foo", :up)
|
23
23
|
status_file.create("for testing")
|
24
24
|
|
25
25
|
status_file.exists?.should be_true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litmus_paper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -191,7 +191,6 @@ files:
|
|
191
191
|
- lib/litmus_paper/dependency/http.rb
|
192
192
|
- lib/litmus_paper/dependency/script.rb
|
193
193
|
- lib/litmus_paper/dependency/tcp.rb
|
194
|
-
- lib/litmus_paper/forced_health.rb
|
195
194
|
- lib/litmus_paper/health.rb
|
196
195
|
- lib/litmus_paper/logger.rb
|
197
196
|
- lib/litmus_paper/metric/available_memory.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module LitmusPaper
|
2
|
-
class ForcedHealth
|
3
|
-
attr_reader :summary
|
4
|
-
|
5
|
-
def initialize(health, summary)
|
6
|
-
@health = health
|
7
|
-
@summary = summary
|
8
|
-
end
|
9
|
-
|
10
|
-
def value
|
11
|
-
@health
|
12
|
-
end
|
13
|
-
|
14
|
-
def ok?
|
15
|
-
@health > 0
|
16
|
-
end
|
17
|
-
|
18
|
-
def forced?
|
19
|
-
true
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|