right_support 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,12 +25,13 @@ require 'set'
25
25
  module RightSupport::Net::Balancing
26
26
 
27
27
  class EndpointsStack
28
-
29
- # Modified by Ryan Williamson on 9/28/2011 to ensure default values exist
30
- # for @yellow_states and @reset_time
31
28
  DEFAULT_YELLOW_STATES = 4
32
29
  DEFAULT_RESET_TIME = 300
33
30
 
31
+ def endpoints
32
+ @endpoints
33
+ end
34
+
34
35
  def initialize(endpoints, yellow_states=nil, reset_time=nil)
35
36
  @endpoints = Hash.new
36
37
  @yellow_states = yellow_states || DEFAULT_YELLOW_STATES
@@ -60,6 +61,18 @@ module RightSupport::Net::Balancing
60
61
  @endpoints[endpoint][:timestamp] = t1
61
62
  end
62
63
  end
64
+
65
+ # Returns a hash of endpoints and their colored health status
66
+ # Useful for logging and debugging
67
+ def get_stats
68
+ stats = {}
69
+ @endpoints.each do |k, v|
70
+ stats[k] = 'green' if v[:n_level] == 0
71
+ stats[k] = 'red' if v[:n_level] == @yellow_states
72
+ stats[k] = "yellow-#{v[:n_level]}" if v[:n_level] > 0 && v[:n_level] < @yellow_states
73
+ end
74
+ stats
75
+ end
63
76
 
64
77
  end
65
78
 
@@ -119,6 +132,11 @@ module RightSupport::Net::Balancing
119
132
  def health_check(endpoint)
120
133
  @stack.increase_state(endpoint,t0,Time.now) unless @health_check.call(endpoint)
121
134
  end
135
+
136
+ # Proxy to EndpointStack
137
+ def get_stats
138
+ @stack.get_stats
139
+ end
122
140
 
123
141
  end
124
142
  end
@@ -191,6 +191,29 @@ module RightSupport::Net
191
191
  raise NoResult, msg
192
192
  end
193
193
 
194
+ # Provide an interface so one can query the RequestBalancer for statistics on
195
+ # it's endpoints. Merely proxies the balancing policy's get_stats method. If
196
+ # no method exists in the balancing policy, a hash of endpoints with "n/a" is
197
+ # returned.
198
+ #
199
+ # Examples
200
+ #
201
+ # A RequestBalancer created with endpoints [1,2,3,4,5] and using a HealthCheck
202
+ # balancing policy may return:
203
+ #
204
+ # {5 => "yellow-3", 1 => "red", 2 => "yellow-1", 3 => "green", 4 => "yellow-2"}
205
+ #
206
+ # A RequestBalancer created with endpoints [1,2,3,4,5] and specifying no
207
+ # balancing policy or using the default RoundRobin balancing policy may return:
208
+ #
209
+ # {2 => "n/a", 1 => "n/a", 3 => "n/a"}
210
+ def get_stats
211
+ stats = {}
212
+ @endpoints.each { |endpoint| stats[endpoint] = 'n/a' }
213
+ stats = @policy.get_stats if @policy.respond_to?(:get_stats)
214
+ stats
215
+ end
216
+
194
217
  protected
195
218
 
196
219
  # Decide what to do with an exception. The decision is influenced by the :fatal
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '1.0.6'
11
- s.date = '2011-10-12'
10
+ s.version = '1.0.7'
11
+ s.date = '2011-10-13'
12
12
 
13
13
  s.authors = ['Tony Spataro']
14
14
  s.email = 'tony@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 6
10
- version: 1.0.6
9
+ - 7
10
+ version: 1.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-12 00:00:00 -07:00
18
+ date: 2011-10-13 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency