big_brother 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,15 @@
1
1
  module BigBrother
2
2
  class HealthFetcher
3
3
  def self.current_health(address, port, path)
4
- http_response = EventMachine::HttpRequest.new("http://#{address}:#{port}#{path}").get
4
+ response = EventMachine::HttpRequest.new("http://#{address}:#{port}#{path}").get
5
+ response.response_header.status == 200 ? _parse_health(response) : 0
6
+ end
5
7
 
6
- if http_response.response_header.has_key?('X_HEALTH')
7
- http_response.response_header['X_HEALTH'].to_i
8
+ def self._parse_health(response)
9
+ if response.response_header.has_key?('X_HEALTH')
10
+ response.response_header['X_HEALTH'].to_i
8
11
  else
9
- http_response.response.slice(/Health: (\d+)/, 1).to_i
12
+ response.response.slice(/Health: (\d+)/, 1).to_i
10
13
  end
11
14
  end
12
15
  end
@@ -1,3 +1,3 @@
1
1
  module BigBrother
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,7 +5,7 @@ describe BigBrother::HealthFetcher do
5
5
  run_in_reactor
6
6
 
7
7
  it "returns its health" do
8
- StubServer.new(<<-HTTP, 0.25)
8
+ StubServer.new(<<-HTTP)
9
9
  HTTP/1.0 200 OK
10
10
  Connection: close
11
11
 
@@ -14,8 +14,18 @@ HTTP
14
14
  BigBrother::HealthFetcher.current_health("127.0.0.1", 8081, "/test/status").should == 59
15
15
  end
16
16
 
17
+ it "returns 0 when the HTTP status code is not 200" do
18
+ StubServer.new(<<-HTTP)
19
+ HTTP/1.0 503 OK
20
+ Connection: close
21
+
22
+ Health: 19
23
+ HTTP
24
+ BigBrother::HealthFetcher.current_health("127.0.0.1", 8081, "/test/status").should == 0
25
+ end
26
+
17
27
  it "returns 0 for an unknown service" do
18
- StubServer.new(<<-HTTP, 0.25)
28
+ StubServer.new(<<-HTTP)
19
29
  HTTP/1.0 503 Service Unavailable
20
30
  Connection: close
21
31
  HTTP
@@ -27,7 +37,7 @@ HTTP
27
37
  end
28
38
 
29
39
  it "returns the health if it is passed in a header" do
30
- StubServer.new(<<-HTTP, 0.25)
40
+ StubServer.new(<<-HTTP)
31
41
  HTTP/1.0 200 OK
32
42
  Connection: close
33
43
  X-Health: 61
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_brother
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-16 00:00:00.000000000 Z
12
+ date: 2012-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin
16
- requirement: &70175345459640 !ruby/object:Gem::Requirement
16
+ requirement: &70147105239120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70175345459640
24
+ version_requirements: *70147105239120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: async-rack
27
- requirement: &70175345458880 !ruby/object:Gem::Requirement
27
+ requirement: &70147105238560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.5.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70175345458880
35
+ version_requirements: *70147105238560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &70175345458360 !ruby/object:Gem::Requirement
38
+ requirement: &70147105237960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70175345458360
46
+ version_requirements: *70147105237960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack-fiber_pool
49
- requirement: &70175345457700 !ruby/object:Gem::Requirement
49
+ requirement: &70147105237200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.9'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70175345457700
57
+ version_requirements: *70147105237200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: eventmachine
60
- requirement: &70175345456980 !ruby/object:Gem::Requirement
60
+ requirement: &70147105236460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>'
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 1.0.0.beta.100
69
69
  type: :runtime
70
70
  prerelease: false
71
- version_requirements: *70175345456980
71
+ version_requirements: *70147105236460
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: em-http-request
74
- requirement: &70175345455800 !ruby/object:Gem::Requirement
74
+ requirement: &70147105235180 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '1.0'
80
80
  type: :runtime
81
81
  prerelease: false
82
- version_requirements: *70175345455800
82
+ version_requirements: *70147105235180
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: em-synchrony
85
- requirement: &70175345454760 !ruby/object:Gem::Requirement
85
+ requirement: &70147105234240 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: '1.0'
91
91
  type: :runtime
92
92
  prerelease: false
93
- version_requirements: *70175345454760
93
+ version_requirements: *70147105234240
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: em-resolv-replace
96
- requirement: &70175345453880 !ruby/object:Gem::Requirement
96
+ requirement: &70147105233120 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: '1.1'
102
102
  type: :runtime
103
103
  prerelease: false
104
- version_requirements: *70175345453880
104
+ version_requirements: *70147105233120
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: em-syslog
107
- requirement: &70175345452920 !ruby/object:Gem::Requirement
107
+ requirement: &70147105232280 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ~>
@@ -112,10 +112,10 @@ dependencies:
112
112
  version: 0.0.2
113
113
  type: :runtime
114
114
  prerelease: false
115
- version_requirements: *70175345452920
115
+ version_requirements: *70147105232280
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: rspec
118
- requirement: &70175345452120 !ruby/object:Gem::Requirement
118
+ requirement: &70147105231800 !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
121
121
  - - ~>
@@ -123,10 +123,10 @@ dependencies:
123
123
  version: 2.9.0
124
124
  type: :development
125
125
  prerelease: false
126
- version_requirements: *70175345452120
126
+ version_requirements: *70147105231800
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: rack-test
129
- requirement: &70175345451620 !ruby/object:Gem::Requirement
129
+ requirement: &70147105231220 !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
132
132
  - - ~>
@@ -134,10 +134,10 @@ dependencies:
134
134
  version: 0.6.1
135
135
  type: :development
136
136
  prerelease: false
137
- version_requirements: *70175345451620
137
+ version_requirements: *70147105231220
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: rake
140
- requirement: &70175345451080 !ruby/object:Gem::Requirement
140
+ requirement: &70147105230600 !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
143
143
  - - ! '>='
@@ -145,10 +145,10 @@ dependencies:
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
- version_requirements: *70175345451080
148
+ version_requirements: *70147105230600
149
149
  - !ruby/object:Gem::Dependency
150
150
  name: rake_commit
151
- requirement: &70175345450240 !ruby/object:Gem::Requirement
151
+ requirement: &70147105229780 !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
154
154
  - - ~>
@@ -156,10 +156,10 @@ dependencies:
156
156
  version: '0.13'
157
157
  type: :development
158
158
  prerelease: false
159
- version_requirements: *70175345450240
159
+ version_requirements: *70147105229780
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: vagrant
162
- requirement: &70175345449640 !ruby/object:Gem::Requirement
162
+ requirement: &70147105229320 !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements:
165
165
  - - ! '>='
@@ -167,7 +167,7 @@ dependencies:
167
167
  version: '0'
168
168
  type: :development
169
169
  prerelease: false
170
- version_requirements: *70175345449640
170
+ version_requirements: *70147105229320
171
171
  description: IPVS backend supervisor
172
172
  email:
173
173
  - code@getbraintree.com