litmus_paper 0.8.5 → 0.8.6
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.rb +2 -0
- data/lib/litmus_paper/app.rb +1 -14
- data/lib/litmus_paper/dependency/file_contents.rb +1 -1
- data/lib/litmus_paper/dependency/haproxy_backends.rb +5 -2
- data/lib/litmus_paper/dependency/http.rb +4 -1
- data/lib/litmus_paper/dependency/script.rb +4 -1
- data/lib/litmus_paper/dependency/tcp.rb +4 -1
- data/lib/litmus_paper/terminal_output.rb +43 -0
- data/lib/litmus_paper/version.rb +1 -1
- data/litmus_paper.gemspec +1 -0
- data/spec/litmus_paper/app_spec.rb +4 -3
- data/spec/litmus_paper/dependency/file_contents_spec.rb +6 -0
- data/spec/litmus_paper/dependency/haproxy_backends_spec.rb +6 -0
- data/spec/litmus_paper/dependency/http_spec.rb +6 -0
- data/spec/litmus_paper/dependency/script_spec.rb +6 -0
- data/spec/litmus_paper/dependency/tcp_spec.rb +14 -0
- metadata +20 -3
data/lib/litmus_paper.rb
CHANGED
@@ -4,6 +4,7 @@ require 'net/https'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'forwardable'
|
6
6
|
require 'English'
|
7
|
+
require 'colorize'
|
7
8
|
|
8
9
|
# Ruby's stock DNS resolution, by default, blocks the entire Ruby VM from
|
9
10
|
# processing while the lookup is happening, because it calls out to the native
|
@@ -38,6 +39,7 @@ require 'litmus_paper/metric/constant_metric'
|
|
38
39
|
require 'litmus_paper/metric/cpu_load'
|
39
40
|
require 'litmus_paper/service'
|
40
41
|
require 'litmus_paper/status_file'
|
42
|
+
require 'litmus_paper/terminal_output'
|
41
43
|
require 'litmus_paper/version'
|
42
44
|
|
43
45
|
module LitmusPaper
|
data/lib/litmus_paper/app.rb
CHANGED
@@ -3,20 +3,7 @@ module LitmusPaper
|
|
3
3
|
disable :show_exceptions
|
4
4
|
|
5
5
|
get "/" do
|
6
|
-
|
7
|
-
max_service_length = (LitmusPaper.services.keys << "Service").max { |a, b| a.length <=> b.length }.length
|
8
|
-
output += sprintf " %-#{max_service_length}s %6s [%s] [%s]\n", "", "", "Measured", "Forced"
|
9
|
-
output += sprintf " %-#{max_service_length}s %6s [%s] [%s]\n", "Service", "Health", "Health".center(8), "Reason"
|
10
|
-
LitmusPaper.services.each do |service_name, service|
|
11
|
-
health = service.current_health
|
12
|
-
output += sprintf "* %-#{max_service_length}s %6s", service_name, health.value
|
13
|
-
if health.forced?
|
14
|
-
output += sprintf " %10s %s", health.measured_health, service.current_health.forced_reason
|
15
|
-
end
|
16
|
-
output += "\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
_text 200, output
|
6
|
+
_text 200, LitmusPaper::TerminalOutput.service_status
|
20
7
|
end
|
21
8
|
|
22
9
|
delete "/down" do
|
@@ -14,12 +14,15 @@ module LitmusPaper
|
|
14
14
|
backend = _find_backend(stats, @cluster)
|
15
15
|
|
16
16
|
if backend['status'] != 'UP'
|
17
|
-
LitmusPaper.logger.info("
|
17
|
+
LitmusPaper.logger.info("HAProxy available check failed, #{@cluster} backend is #{backend['status']}")
|
18
18
|
return false
|
19
19
|
end
|
20
20
|
return true
|
21
21
|
rescue Timeout::Error
|
22
|
-
LitmusPaper.logger.info("
|
22
|
+
LitmusPaper.logger.info("HAProxy available check timed out for #{@cluster}")
|
23
|
+
false
|
24
|
+
rescue => e
|
25
|
+
LitmusPaper.logger.info("HAProxy available check failed for #{@cluster} with #{e.message}")
|
23
26
|
false
|
24
27
|
end
|
25
28
|
|
@@ -18,7 +18,10 @@ module LitmusPaper
|
|
18
18
|
LitmusPaper.logger.info("Available check to #{@uri} did not match #{@expected_content}") unless matches
|
19
19
|
|
20
20
|
success && matches
|
21
|
-
rescue
|
21
|
+
rescue Timeout::Error
|
22
|
+
LitmusPaper.logger.info("Timeout fetching #{@uri}")
|
23
|
+
false
|
24
|
+
rescue => e
|
22
25
|
LitmusPaper.logger.info("Available check to #{@uri} failed with #{e.message}")
|
23
26
|
false
|
24
27
|
end
|
@@ -24,9 +24,12 @@ module LitmusPaper
|
|
24
24
|
script_status.success?
|
25
25
|
end
|
26
26
|
rescue Timeout::Error
|
27
|
-
LitmusPaper.logger.info("
|
27
|
+
LitmusPaper.logger.info("Timeout running command: '#{@command}'")
|
28
28
|
kill_and_reap_script(@script_pid)
|
29
29
|
false
|
30
|
+
rescue => e
|
31
|
+
LitmusPaper.logger.info("Available check to #{@uri} failed with #{e.message}")
|
32
|
+
false
|
30
33
|
end
|
31
34
|
|
32
35
|
def kill_and_reap_script(pid)
|
@@ -12,7 +12,10 @@ module LitmusPaper
|
|
12
12
|
socket.close
|
13
13
|
end
|
14
14
|
true
|
15
|
-
rescue
|
15
|
+
rescue Timeout::Error
|
16
|
+
LitmusPaper.logger.info("Timeout connecting #{@ip}:#{@port}")
|
17
|
+
false
|
18
|
+
rescue => e
|
16
19
|
LitmusPaper.logger.info("TCP available check to #{@ip}:#{@port} failed with #{e.message}")
|
17
20
|
false
|
18
21
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module LitmusPaper
|
3
|
+
class TerminalOutput
|
4
|
+
def self.service_status
|
5
|
+
max_service_length = (LitmusPaper.services.keys << "Service").max { |a, b| a.length <=> b.length }.length
|
6
|
+
|
7
|
+
output = "Litmus Paper #{LitmusPaper::VERSION}\n"
|
8
|
+
output += sprintf(" %s │ %s │ %s │ %s\n", "Service".ljust(max_service_length), "Reported", "Measured", "Health")
|
9
|
+
output += sprintf(" %s │ %s │ %s │ %s\n", "Name".ljust(max_service_length), "Health".ljust(8), "Health".ljust(8), "Forced?")
|
10
|
+
output += "─" * (max_service_length + 2) + "┴" + "─" * 10 + "┴" + "─" * 10 + "┴" + "─" * 9 + "\n"
|
11
|
+
|
12
|
+
LitmusPaper.services.each do |service_name, service|
|
13
|
+
health = service.current_health
|
14
|
+
measured_health = health.measured_health.to_s.rjust(3)
|
15
|
+
reported_health = health.value.to_s.rjust(3)
|
16
|
+
service_forced = if health.forced?
|
17
|
+
"Yes: #{health.forced_reason}"
|
18
|
+
else
|
19
|
+
"No"
|
20
|
+
end
|
21
|
+
output += sprintf("* %-#{max_service_length}s %s %s %s\n",
|
22
|
+
service_name,
|
23
|
+
reported_health.center(8).colorize(_health_color(health.value)),
|
24
|
+
measured_health.center(8),
|
25
|
+
service_forced,
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
return output
|
30
|
+
end
|
31
|
+
|
32
|
+
def self._health_color(health)
|
33
|
+
if health == 0
|
34
|
+
return :red
|
35
|
+
elsif health < 80
|
36
|
+
return :yellow
|
37
|
+
else
|
38
|
+
return :green
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/litmus_paper/version.rb
CHANGED
data/litmus_paper.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency "remote_syslog_logger", "~> 1.0.3"
|
22
22
|
gem.add_dependency "popen4", "~> 0.1.2"
|
23
23
|
gem.add_dependency "unicorn", "~> 4.6.2"
|
24
|
+
gem.add_dependency "colorize"
|
24
25
|
|
25
26
|
gem.add_development_dependency "rspec", "~> 2.9.0"
|
26
27
|
gem.add_development_dependency "rack-test", "~> 0.6.1"
|
@@ -35,7 +35,8 @@ describe LitmusPaper::App do
|
|
35
35
|
get "/"
|
36
36
|
|
37
37
|
last_response.status.should == 200
|
38
|
-
last_response.body.should
|
38
|
+
last_response.body.should include('test')
|
39
|
+
last_response.body.should include('0')
|
39
40
|
end
|
40
41
|
|
41
42
|
it "includes the status if forced" do
|
@@ -48,8 +49,8 @@ describe LitmusPaper::App do
|
|
48
49
|
get "/"
|
49
50
|
|
50
51
|
last_response.status.should == 200
|
51
|
-
last_response.body.should
|
52
|
-
last_response.body.should
|
52
|
+
last_response.body.should include('Down for testing')
|
53
|
+
last_response.body.should include('Up for testing')
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -21,6 +21,12 @@ describe LitmusPaper::Dependency::FileContents do
|
|
21
21
|
check = LitmusPaper::Dependency::FileContents.new("/dev/zero", /^timeout$/, :timeout => 1)
|
22
22
|
check.should_not be_available
|
23
23
|
end
|
24
|
+
|
25
|
+
it "logs exceptions and returns false" do
|
26
|
+
check = LitmusPaper::Dependency::FileContents.new("/tmp/this_file_does_not_exist", /^foo$/)
|
27
|
+
LitmusPaper.logger.should_receive(:info)
|
28
|
+
check.should_not be_available
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
describe "to_s" do
|
@@ -17,6 +17,12 @@ describe LitmusPaper::Dependency::HaproxyBackends do
|
|
17
17
|
haproxy = LitmusPaper::Dependency::HaproxyBackends.new("/tmp/stub-haproxy-stats", "orange_cluster")
|
18
18
|
haproxy.should_not be_available
|
19
19
|
end
|
20
|
+
|
21
|
+
it "logs exceptions and returns false" do
|
22
|
+
haproxy = LitmusPaper::Dependency::HaproxyBackends.new("/dev/null", "yellow_cluster")
|
23
|
+
LitmusPaper.logger.should_receive(:info)
|
24
|
+
haproxy.should_not be_available
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
describe "timeouts" do
|
@@ -124,6 +124,12 @@ describe LitmusPaper::Dependency::HTTP do
|
|
124
124
|
check = LitmusPaper::Dependency::HTTP.new("#{@url}/sleep/2", :timeout_seconds => 1)
|
125
125
|
check.should_not be_available
|
126
126
|
end
|
127
|
+
|
128
|
+
it "logs exceptions and returns false" do
|
129
|
+
check = LitmusPaper::Dependency::HTTP.new('http://127.0.0.1:7777')
|
130
|
+
LitmusPaper.logger.should_receive(:info)
|
131
|
+
check.should_not be_available
|
132
|
+
end
|
127
133
|
end
|
128
134
|
|
129
135
|
describe "to_s" do
|
@@ -30,6 +30,12 @@ describe LitmusPaper::Dependency::Script do
|
|
30
30
|
check = LitmusPaper::Dependency::Script.new("ls | grep missing")
|
31
31
|
check.should_not be_available
|
32
32
|
end
|
33
|
+
|
34
|
+
it "logs exceptions and returns false" do
|
35
|
+
check = LitmusPaper::Dependency::Script.new("command_not_found")
|
36
|
+
LitmusPaper.logger.should_receive(:info)
|
37
|
+
check.should_not be_available
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
describe "to_s" do
|
@@ -24,6 +24,20 @@ describe LitmusPaper::Dependency::TCP do
|
|
24
24
|
check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3334)
|
25
25
|
check.should_not be_available
|
26
26
|
end
|
27
|
+
|
28
|
+
it "is false when the request times out" do
|
29
|
+
TCPSocket.stub(:new) do
|
30
|
+
sleep(5)
|
31
|
+
end
|
32
|
+
check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3334, :timeout_seconds => 1)
|
33
|
+
check.should_not be_available
|
34
|
+
end
|
35
|
+
|
36
|
+
it "logs exceptions and returns false" do
|
37
|
+
check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3334)
|
38
|
+
LitmusPaper.logger.should_receive(:info)
|
39
|
+
check.should_not be_available
|
40
|
+
end
|
27
41
|
end
|
28
42
|
|
29
43
|
describe "to_s" do
|
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.6
|
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:
|
12
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 4.6.2
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: colorize
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: rspec
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +215,7 @@ files:
|
|
199
215
|
- lib/litmus_paper/metric/cpu_load.rb
|
200
216
|
- lib/litmus_paper/service.rb
|
201
217
|
- lib/litmus_paper/status_file.rb
|
218
|
+
- lib/litmus_paper/terminal_output.rb
|
202
219
|
- lib/litmus_paper/version.rb
|
203
220
|
- litmus_paper.gemspec
|
204
221
|
- spec/litmus_paper/app_spec.rb
|
@@ -254,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
271
|
version: '0'
|
255
272
|
requirements: []
|
256
273
|
rubyforge_project:
|
257
|
-
rubygems_version: 1.8.
|
274
|
+
rubygems_version: 1.8.23
|
258
275
|
signing_key:
|
259
276
|
specification_version: 3
|
260
277
|
summary: Backend health tester for HA Services, partner project of big_brother
|