right_support 2.11.3 → 2.12.1

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -0
  3. data/VERSION +1 -1
  4. data/lib/right_support/notifiers/airbrake.rb +194 -0
  5. data/lib/right_support/notifiers/base.rb +73 -0
  6. data/lib/right_support/notifiers/blacklisters/base.rb +48 -0
  7. data/lib/right_support/notifiers/blacklisters/canonical.rb +60 -0
  8. data/lib/right_support/notifiers/blacklisters/regular_expression.rb +86 -0
  9. data/{features/support/file_utils_bundler_mixin.rb → lib/right_support/notifiers/blacklisters/simple.rb} +21 -20
  10. data/lib/right_support/notifiers/blacklisters/snake_case.rb +60 -0
  11. data/lib/right_support/notifiers/blacklisters/wildcard.rb +65 -0
  12. data/lib/right_support/notifiers/blacklisters.rb +34 -0
  13. data/lib/right_support/notifiers/logger.rb +94 -0
  14. data/lib/right_support/notifiers/notification.rb +57 -0
  15. data/lib/right_support/notifiers/utilities/backtrace_decoder.rb +234 -0
  16. data/lib/right_support/notifiers/utilities.rb +29 -0
  17. data/lib/right_support/notifiers.rb +32 -0
  18. data/lib/right_support/rack/request_logger.rb +13 -9
  19. data/lib/right_support.rb +1 -0
  20. data/right_support.gemspec +19 -70
  21. metadata +17 -69
  22. data/.coveralls.yml +0 -2
  23. data/.rspec +0 -3
  24. data/.simplecov +0 -6
  25. data/.travis.yml +0 -13
  26. data/Gemfile +0 -51
  27. data/Gemfile.lock +0 -153
  28. data/features/balancer_error_handling.feature +0 -34
  29. data/features/balancer_health_check.feature +0 -33
  30. data/features/hash_tools.feature +0 -27
  31. data/features/http_client_timeout.feature +0 -19
  32. data/features/serialization.feature +0 -113
  33. data/features/step_definitions/hash_tools_steps.rb +0 -41
  34. data/features/step_definitions/http_client_steps.rb +0 -27
  35. data/features/step_definitions/request_balancer_steps.rb +0 -93
  36. data/features/step_definitions/ruby_steps.rb +0 -176
  37. data/features/step_definitions/serialization_steps.rb +0 -133
  38. data/features/step_definitions/server_steps.rb +0 -134
  39. data/features/support/env.rb +0 -148
  40. data/right_support.rconf +0 -9
  41. data/spec/config/feature_set_spec.rb +0 -83
  42. data/spec/crypto/signed_hash_spec.rb +0 -73
  43. data/spec/data/hash_tools_spec.rb +0 -602
  44. data/spec/data/mash_spec.rb +0 -313
  45. data/spec/data/token_spec.rb +0 -21
  46. data/spec/data/uuid_spec.rb +0 -45
  47. data/spec/db/cassandra_model_part1_spec.rb +0 -84
  48. data/spec/db/cassandra_model_part2_spec.rb +0 -73
  49. data/spec/db/cassandra_model_spec.rb +0 -375
  50. data/spec/fixtures/encrypted_priv_rsa.pem +0 -30
  51. data/spec/fixtures/good_priv_dsa.pem +0 -12
  52. data/spec/fixtures/good_priv_rsa.pem +0 -15
  53. data/spec/fixtures/good_pub_dsa.ssh +0 -1
  54. data/spec/fixtures/good_pub_rsa.pem +0 -5
  55. data/spec/fixtures/good_pub_rsa.ssh +0 -1
  56. data/spec/log/exception_logger_spec.rb +0 -76
  57. data/spec/log/filter_logger_spec.rb +0 -66
  58. data/spec/log/mixin_spec.rb +0 -141
  59. data/spec/log/multiplexer_spec.rb +0 -54
  60. data/spec/log/null_logger_spec.rb +0 -36
  61. data/spec/log/step_level_logger_spec.rb +0 -49
  62. data/spec/log/system_logger_spec.rb +0 -172
  63. data/spec/net/address_helper_spec.rb +0 -57
  64. data/spec/net/dns_spec.rb +0 -187
  65. data/spec/net/http_client_spec.rb +0 -181
  66. data/spec/net/lb/health_check_spec.rb +0 -417
  67. data/spec/net/lb/round_robin_spec.rb +0 -15
  68. data/spec/net/lb/sticky_spec.rb +0 -92
  69. data/spec/net/request_balancer_spec.rb +0 -690
  70. data/spec/net/s3_helper_spec.rb +0 -160
  71. data/spec/net/ssl_spec.rb +0 -42
  72. data/spec/net/string_encoder_spec.rb +0 -58
  73. data/spec/rack/log_setter_spec.rb +0 -5
  74. data/spec/rack/request_logger_spec.rb +0 -225
  75. data/spec/rack/request_tracker_spec.rb +0 -115
  76. data/spec/rack/runtime_spec.rb +0 -49
  77. data/spec/ruby/easy_singleton_spec.rb +0 -72
  78. data/spec/ruby/object_extensions_spec.rb +0 -27
  79. data/spec/ruby/string_extensions_spec.rb +0 -98
  80. data/spec/spec_helper.rb +0 -188
  81. data/spec/stats/activity_spec.rb +0 -425
  82. data/spec/stats/exceptions_spec.rb +0 -247
  83. data/spec/stats/helpers_spec.rb +0 -685
  84. data/spec/validation/openssl_spec.rb +0 -37
  85. data/spec/validation/ssh_spec.rb +0 -39
@@ -1,685 +0,0 @@
1
- #
2
- # Copyright (c) 2009-2012 RightScale Inc
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
24
-
25
- describe RightSupport::Stats do
26
-
27
- include FlexMock::ArgumentTypes
28
-
29
- before(:all) do
30
- @helpers = RightSupport::Stats
31
- @original_recent_size = RightSupport::Stats::Activity::RECENT_SIZE
32
- RightSupport::Stats::Activity.send(:remove_const, :RECENT_SIZE) # Silence warning
33
- RightSupport::Stats::Activity.const_set(:RECENT_SIZE, 10)
34
- end
35
-
36
- after(:all) do
37
- RightSupport::Stats::Activity.send(:remove_const, :RECENT_SIZE) # Silence warning
38
- RightSupport::Stats::Activity.const_set(:RECENT_SIZE, @original_recent_size)
39
- end
40
-
41
- before(:each) do
42
- pending("unreliable on Ruby 1.8 due to Hash-key ordering") if RUBY_VERSION =~ /1.8/
43
-
44
- @hr = sprintf("%02d", 13 + (Time.now.utc_offset / 3600) + (Time.now.dst? ? -1 : 0))
45
- @now = 1000000
46
- flexmock(Time).should_receive(:now).and_return(@now).by_default
47
- @exceptions = RightSupport::Stats::Exceptions.new
48
- @brokers = {"brokers"=> [{"alias" => "b0", "identity" => "rs-broker-localhost-5672", "status" => "connected",
49
- "disconnect last" => nil,"disconnects" => nil, "failure last" => nil, "failures" => nil,
50
- "retries" => nil},
51
- {"alias" => "b1", "identity" => "rs-broker-localhost-5673", "status" => "disconnected",
52
- "disconnect last" => {"elapsed" => 1000}, "disconnects" => 2,
53
- "failure last" => nil, "failures" => nil, "retries" => nil},
54
- {"alias" => "b2", "identity" => "rs-broker-localhost-5674", "status" => "failed",
55
- "disconnect last" => nil, "disconnects" => nil,
56
- "failure last" => {"elapsed" => 1000}, "failures" => 3, "retries" => 2}],
57
- "heartbeat" => nil,
58
- "exceptions" => {}}
59
- end
60
-
61
- context "percentage" do
62
- it "converts values to percentages" do
63
- stats = {"first" => 1, "second" => 4, "third" => 3}
64
- result = @helpers.percentage(stats)
65
- result.should == {"total" => 8, "percent" => {"first" => 12.5, "second" => 50.0, "third" => 37.5}}
66
- end
67
- end
68
-
69
- context "nil_if_zero" do
70
- it "converts 0 to nil" do
71
- @helpers.nil_if_zero(0).should be_nil
72
- @helpers.nil_if_zero(0.0).should be_nil
73
- @helpers.nil_if_zero(1).should == 1
74
- @helpers.nil_if_zero(1.0).should == 1.0
75
- end
76
- end
77
-
78
- context "elapsed" do
79
- it "converts elapsed time to displayable format" do
80
- @helpers.elapsed(0).should == "0 sec"
81
- @helpers.elapsed(1).should == "1 sec"
82
- @helpers.elapsed(60).should == "60 sec"
83
- @helpers.elapsed(61).should == "1 min 1 sec"
84
- @helpers.elapsed(62).should == "1 min 2 sec"
85
- @helpers.elapsed(120).should == "2 min 0 sec"
86
- @helpers.elapsed(3600).should == "60 min 0 sec"
87
- @helpers.elapsed(3601).should == "1 hr 0 min"
88
- @helpers.elapsed(3659).should == "1 hr 0 min"
89
- @helpers.elapsed(3660).should == "1 hr 1 min"
90
- @helpers.elapsed(3720).should == "1 hr 2 min"
91
- @helpers.elapsed(7200).should == "2 hr 0 min"
92
- @helpers.elapsed(7260).should == "2 hr 1 min"
93
- @helpers.elapsed(86400).should == "24 hr 0 min"
94
- @helpers.elapsed(86401).should == "1 day 0 hr 0 min"
95
- @helpers.elapsed(86459).should == "1 day 0 hr 0 min"
96
- @helpers.elapsed(86460).should == "1 day 0 hr 1 min"
97
- @helpers.elapsed(90000).should == "1 day 1 hr 0 min"
98
- @helpers.elapsed(183546).should == "2 days 2 hr 59 min"
99
- @helpers.elapsed(125.5).should == "2 min 5 sec"
100
- end
101
- end
102
-
103
- context "enough_precision" do
104
- it "converts floating point values to decimal digit string with at least two digit precision" do
105
- @helpers.enough_precision(100.5).should == "101"
106
- @helpers.enough_precision(-100.5).should == "-101"
107
- @helpers.enough_precision(100.4).should == "100"
108
- @helpers.enough_precision(-100.4).should == "-100"
109
- @helpers.enough_precision(99.0).should == "99"
110
- @helpers.enough_precision(-99.0).should == "-99"
111
- @helpers.enough_precision(10.5).should == "11"
112
- @helpers.enough_precision(-10.5).should == "-11"
113
- @helpers.enough_precision(10.4).should == "10"
114
- @helpers.enough_precision(-10.4).should == "-10"
115
- @helpers.enough_precision(9.15).should == "9.2"
116
- @helpers.enough_precision(-9.15).should == "-9.2"
117
- @helpers.enough_precision(9.1).should == "9.1"
118
- @helpers.enough_precision(-9.1).should == "-9.1"
119
- @helpers.enough_precision(1.05).should == "1.1"
120
- @helpers.enough_precision(-1.05).should == "-1.1"
121
- @helpers.enough_precision(1.01).should == "1.0"
122
- @helpers.enough_precision(-1.01).should == "-1.0"
123
- @helpers.enough_precision(1.0).should == "1.0"
124
- @helpers.enough_precision(-1.0).should == "-1.0"
125
- @helpers.enough_precision(0.995).should == "1.00"
126
- @helpers.enough_precision(-0.995).should == "-1.00"
127
- @helpers.enough_precision(0.991).should == "0.99"
128
- @helpers.enough_precision(-0.991).should == "-0.99"
129
- @helpers.enough_precision(0.0995).should == "0.100"
130
- @helpers.enough_precision(-0.0995).should == "-0.100"
131
- @helpers.enough_precision(0.0991).should == "0.099"
132
- @helpers.enough_precision(-0.0991).should == "-0.099"
133
- @helpers.enough_precision(0.00995).should == "0.0100"
134
- @helpers.enough_precision(-0.00995).should == "-0.0100"
135
- @helpers.enough_precision(0.00991).should == "0.0099"
136
- @helpers.enough_precision(-0.00991).should == "-0.0099"
137
- @helpers.enough_precision(0.000995).should == "0.00100"
138
- @helpers.enough_precision(-0.000995).should == "-0.00100"
139
- @helpers.enough_precision(0.000991).should == "0.00099"
140
- @helpers.enough_precision(-0.000991).should == "-0.00099"
141
- @helpers.enough_precision(0.0000995).should == "0.000100"
142
- @helpers.enough_precision(-0.0000995).should == "-0.000100"
143
- @helpers.enough_precision(0.0000991).should == "0.000099"
144
- @helpers.enough_precision(-0.0000991).should == "-0.000099"
145
- @helpers.enough_precision(0.0000005).should == "0.000001"
146
- @helpers.enough_precision(-0.0000005).should == "-0.000001"
147
- @helpers.enough_precision(0.0000001).should == "0"
148
- @helpers.enough_precision(-0.0000001).should == "0"
149
- @helpers.enough_precision(0.0).should == "0"
150
- @helpers.enough_precision(55).should == "55"
151
- @helpers.enough_precision(-55).should == "-55"
152
- @helpers.enough_precision({"a" => 65.0, "b" => 23.0, "c" => 12.0}).should == {"a" => "65", "b" => "23", "c" => "12"}
153
- @helpers.enough_precision({"a" => 65.0, "b" => 33.0, "c" => 2.0}).should == {"a" => "65.0", "b" => "33.0", "c" => "2.0"}
154
- @helpers.enough_precision({"a" => 10.45, "b" => 1.0, "c" => 0.011}).should == {"a" => "10.5", "b" => "1.0", "c" => "0.011"}
155
- @helpers.enough_precision({"a" => 1000.0, "b" => 0.1, "c" => 0.0, "d" => 0.0001, "e" => 0.00001, "f" => 0.0000001}).should ==
156
- {"a" => "1000.0", "b" => "0.10", "c" => "0.0", "d" => "0.00010", "e" => "0.000010", "f" => "0.0"}
157
- @helpers.enough_precision([["a", 65.0], ["b", 23.0], ["c", 12.0]]).should == [["a", "65"], ["b", "23"], ["c", "12"]]
158
- @helpers.enough_precision([["a", 65.0], ["b", 33.0], ["c", 2.0]]).should == [["a", "65.0"], ["b", "33.0"], ["c", "2.0"]]
159
- @helpers.enough_precision([["a", 10.45], ["b", 1.0], ["c", 0.011]]).should == [["a", "10.5"], ["b", "1.0"], ["c", "0.011"]]
160
- @helpers.enough_precision([["a", 1000.0], ["b", 0.1], ["c", 0.0], ["d", 0.0001], ["e", 0.00001], ["f", 0.0000001]]).should ==
161
- [["a", "1000.0"], ["b", "0.10"], ["c", "0.0"], ["d", "0.00010"], ["e", "0.000010"], ["f", "0.0"]]
162
- end
163
- end
164
-
165
- context "wrap" do
166
- it "removes extra white space before wrapping" do
167
- string = "This is a test of wrapping\nwhen there is extra white space.\n\n"
168
- RightSupport::Stats.wrap(string, [40, 50], " " * 10, /\s/).should ==
169
- "This is a test of wrapping when there \n is extra white space."
170
- end
171
-
172
- it "wraps string by breaking it into lines at the specified separator" do
173
- string = "Now is the time for all good men to come to the aid of their people."
174
- indent = " " * 4
175
- result = @helpers.wrap(string, 20, indent, / /)
176
- result.should == "Now is the time for \n" +
177
- " all good men to \n" +
178
- " come to the aid \n" +
179
- " of their people."
180
- result.split("\n").select { |l| (l.chomp.size - indent.size) > 20 }.should be_empty
181
-
182
- string = "dogs: 2, cats: 10, hippopotami: 99, bears: 1, ants: 100000"
183
- indent = "--"
184
- result = @helpers.wrap(string, 22, indent, /, /)
185
- result.should == "dogs: 2, cats: 10, \n" +
186
- "--hippopotami: 99, \n" +
187
- "--bears: 1, \n" +
188
- "--ants: 100000"
189
- result.split("\n").select { |l| (l.chomp.size - indent.size) > 22 }.should be_empty
190
- end
191
-
192
- it "wraps string by breaking into lines while ignoring encoding for color when measuring length" do
193
- string = "Now is the time for all good men to come to the aid of their people."
194
- colors = [:red, :blue, :green]
195
- c = 0
196
- string = string.split(" ").map { |s| s.send(colors[c = (c + 1) % 3]) }.join(" ")
197
- result = @helpers.wrap(string, 20, " " * 4, / /)
198
- result.gsub(/\e\[[0-9]*m/, "").should == "Now is the time for \n" +
199
- " all good men to \n" +
200
- " come to the aid \n" +
201
- " of their people."
202
- end
203
-
204
- it "wraps string by breaking into lines with multiple separators" do
205
- string = "Failed receiving from queue request on b0 (RightScale::Serializer::SerializationError: Could not load " +
206
- "packet using [RightScale::SecureSerializer] (Failed to load with RightScale::SecureSerializer " +
207
- "(RightScale::SecureSerializer::InvalidSignature: Failed signature check for signer " +
208
- "rs-instance-1368fe0b6d4663dc1c92c54e05a8c37b3bd66be7-207607183 in " +
209
- "/home/rails/right_net/shared/bundle/ruby/1.9.1/bundler/gems/right_agent-aab761e02a9e/" +
210
- "lib/right_agent/serialize/secure_serializer.rb:136:in `load')) IN /Users/leekirchhoff/" +
211
- ".rightscale/right_net/ruby/1.8/bundler/gems/right_agent-4459d22fc542/lib/right_agent/" +
212
- "serialize/serializer.rb:133:in `cascade_serializers')"
213
- result = @helpers.wrap(string, 80, "", / |\/\/|\/|::|\.|-/)
214
- result.should == "Failed receiving from queue request on b0 (RightScale::Serializer::\n" +
215
- "SerializationError: Could not load packet using [RightScale::SecureSerializer] \n" +
216
- "(Failed to load with RightScale::SecureSerializer (RightScale::\n" +
217
- "SecureSerializer::InvalidSignature: Failed signature check for signer rs-\n" +
218
- "instance-1368fe0b6d4663dc1c92c54e05a8c37b3bd66be7-207607183 in /home/rails/\n" +
219
- "right_net/shared/bundle/ruby/1.9.1/bundler/gems/right_agent-aab761e02a9e/lib/\n" +
220
- "right_agent/serialize/secure_serializer.rb:136:in `load')) IN /Users/\n" +
221
- "leekirchhoff/.rightscale/right_net/ruby/1.8/bundler/gems/right_agent-\n" +
222
- "4459d22fc542/lib/right_agent/serialize/serializer.rb:133:in \n" +
223
- "`cascade_serializers')"
224
- result.split("\n").select { |l| l.chomp.size > 80 }.should be_empty
225
- end
226
-
227
- it "can handle very large number of separations without blowing up" do
228
- RightSupport::Stats.wrap("/ " * 5000, 50, " " * 10, /\s|\//).count("\n").should == 249
229
- end
230
- end
231
-
232
- context "sort_key" do
233
- it "sorts hash by key into array with integer conversion of keys if possible" do
234
- @helpers.sort_key({"c" => 3, "a" => 1, "b" => 2}).should == [["a", 1], ["b", 2], ["c", 3]]
235
- @helpers.sort_key({3 => "c", 1 => "a", 2 => "b"}).should == [[1, "a"], [2, "b"], [3, "c"]]
236
- @helpers.sort_key({11 => "c", 9 => "a", 10 => "b"}).should == [[9, "a"], [10, "b"], [11, "c"]]
237
- @helpers.sort_key({"append_info" => 9.6, "create_new_section" => 8.5, "append_output" => 7.3, "record" => 4.7,
238
- "update_status" => 4.4,
239
- "declare" => 39.2, "list_agents" => 3.7, "update_tags" => 3.2, "append_error" => 3.0,
240
- "add_user" => 2.4, "get_boot_bundle" => 1.4, "get_repositories" => 1.4,
241
- "update_login_policy" => 1.3, "schedule_decommission" => 0.91, "update_inputs" => 0.75,
242
- "delete_queues" => 0.75, "soft_decommission" => 0.75, "remove" => 0.66,
243
- "get_login_policy" => 0.58, "ping" => 0.50, "update_entry" => 0.25, "query_tags" => 0.083,
244
- "get_decommission_bundle" => 0.083, "list_queues" => 0.083}).should ==
245
- [["add_user", 2.4], ["append_error", 3.0], ["append_info", 9.6], ["append_output", 7.3],
246
- ["create_new_section", 8.5], ["declare", 39.2], ["delete_queues", 0.75], ["get_boot_bundle", 1.4],
247
- ["get_decommission_bundle", 0.083], ["get_login_policy", 0.58], ["get_repositories", 1.4],
248
- ["list_agents", 3.7], ["list_queues", 0.083], ["ping", 0.5], ["query_tags", 0.083],
249
- ["record", 4.7], ["remove", 0.66], ["schedule_decommission", 0.91], ["soft_decommission", 0.75],
250
- ["update_entry", 0.25], ["update_inputs", 0.75],
251
- ["update_login_policy", 1.3], ["update_status", 4.4], ["update_tags", 3.2]]
252
- end
253
- end
254
-
255
- context "sort_value" do
256
- it "sorts hash by value into array" do
257
- @helpers.sort_value({"c" => 3, "a" => 2, "b" => 1}).should == [["b", 1], ["a", 2], ["c", 3]]
258
- @helpers.sort_value({"c" => 3.0, "a" => 2, "b" => 1.0}).should == [["b", 1.0], ["a", 2], ["c", 3.0]]
259
- @helpers.sort_value({"append_info" => 9.6, "create_new_section" => 8.5, "append_output" => 7.3, "record" => 4.7,
260
- "update_status" => 4.4,
261
- "declare" => 39.2, "list_agents" => 3.7, "update_tags" => 3.2, "append_error" => 3.0,
262
- "add_user" => 2.4, "get_boot_bundle" => 1.5, "get_repositories" => 1.4,
263
- "update_login_policy" => 1.3, "schedule_decommission" => 0.91, "update_inputs" => 0.77,
264
- "delete_queues" => 0.75, "soft_decommission" => 0.76, "remove" => 0.66,
265
- "get_login_policy" => 0.58, "ping" => 0.50, "update_entry" => 0.25, "query_tags" => 0.082,
266
- "get_decommission_bundle" => 0.083, "list_queues" => 0.081}).should ==
267
- [["list_queues", 0.081], ["query_tags", 0.082], ["get_decommission_bundle", 0.083],
268
- ["update_entry", 0.25], ["ping", 0.5], ["get_login_policy", 0.58], ["remove", 0.66],
269
- ["delete_queues", 0.75], ["soft_decommission", 0.76], ["update_inputs", 0.77],
270
- ["schedule_decommission", 0.91], ["update_login_policy", 1.3], ["get_repositories", 1.4],
271
- ["get_boot_bundle", 1.5], ["add_user", 2.4], ["append_error", 3.0], ["update_tags", 3.2],
272
- ["list_agents", 3.7], ["update_status", 4.4],
273
- ["record", 4.7], ["append_output", 7.3], ["create_new_section", 8.5], ["append_info", 9.6],
274
- ["declare", 39.2]]
275
- end
276
- end
277
-
278
- context "service_up_str" do
279
- it "converts service up stats to string when it is an integer" do
280
- result = @helpers.service_up_str(75)
281
- result.should == "1 min 15 sec"
282
- end
283
-
284
- it "converts service up stats to string when it is a hash" do
285
- result = @helpers.service_up_str("uptime" => 75)
286
- result.should == "1 min 15 sec"
287
- end
288
-
289
- it "converts service up stats to string that includes restarts" do
290
- result = @helpers.service_up_str("uptime" => 75, "total_uptime" => 86401, "restarts" => 10, "graceful_exits" => 10)
291
- result.should == "1 min 15 sec, restarts: 10 (up 1 day 0 hr 0 min total)"
292
- end
293
-
294
- it "converts service up stats to string that includes restarts and non-graceful exits" do
295
- result = @helpers.service_up_str("uptime" => 75, "total_uptime" => 90061, "restarts" => 10, "graceful_exits" => 8)
296
- result.should == "1 min 15 sec, restarts: 10 (2 non-graceful, up 1 day 1 hr 1 min total)"
297
- end
298
-
299
- it "converts service up stats to string that includes crashes" do
300
- flexmock(Time).should_receive(:now).and_return(1000000)
301
- result = @helpers.service_up_str("uptime" => 75, "total_uptime" => 90061, "crashes" => 1, "last_crash_time" => 996340)
302
- result.should == "1 min 15 sec, crashes: 1 (last 1 hr 1 min ago)"
303
- end
304
-
305
- it "converts service up stats to string that includes restarts and crashes" do
306
- flexmock(Time).should_receive(:now).and_return(1000000)
307
- result = @helpers.service_up_str("uptime" => 75, "total_uptime" => 90061, "restarts" => 10, "graceful_exits" => 8,
308
- "crashes" => 1, "last_crash_time" => 996340)
309
- result.should == "1 min 15 sec, restarts: 10 (2 non-graceful, up 1 day 1 hr 1 min total), crashes: 1 (last 1 hr 1 min ago)"
310
- end
311
- end
312
-
313
- context "brokers_str" do
314
- it "converts broker status to multi-line display string" do
315
- result = @helpers.brokers_str(@brokers, :name_width => 10)
316
- result.should == "brokers : b0: rs-broker-localhost-5672 connected, disconnects: none, failures: none\n" +
317
- " b1: rs-broker-localhost-5673 disconnected, disconnects: 2 (16 min 40 sec ago), failures: none\n" +
318
- " b2: rs-broker-localhost-5674 failed, disconnects: none, failures: 3 (16 min 40 sec ago w/ 2 retries)\n" +
319
- " exceptions : none\n" +
320
- " heartbeat : none\n" +
321
- " returns : none\n"
322
- end
323
-
324
- it "displays broker exceptions and returns" do
325
- @exceptions.track("testing", Exception.new("Test error"))
326
- @brokers["exceptions"] = @exceptions.stats
327
- @brokers["heartbeat"] = 60
328
- activity = RightSupport::Stats::Activity.new
329
- activity.update("no queue")
330
- activity.finish(@now - 10)
331
- activity.update("no queue consumers")
332
- activity.update("no queue consumers")
333
- flexmock(Time).should_receive(:now).and_return(1000010)
334
- @brokers["returns"] = activity.all
335
- result = @helpers.brokers_str(@brokers, :name_width => 10)
336
- result.should == "brokers : b0: rs-broker-localhost-5672 connected, disconnects: none, failures: none\n" +
337
- " b1: rs-broker-localhost-5673 disconnected, disconnects: 2 (16 min 40 sec ago), failures: none\n" +
338
- " b2: rs-broker-localhost-5674 failed, disconnects: none, failures: 3 (16 min 40 sec ago w/ 2 retries)\n" +
339
- " exceptions : testing total: 1, most recent:\n" +
340
- " (1) Mon Jan 12 #{@hr}:46:40 Exception: Test error\n" +
341
- " heartbeat : 60 sec\n" +
342
- " returns : no queue consumers: 67%, no queue: 33%, total: 3, \n" +
343
- " last: no queue consumers (10 sec ago), rate: 1.0/sec, latency: 1.0 sec\n"
344
- end
345
-
346
- it "omits exceptions from brokers if exceptions key omitted" do
347
- @brokers.delete("exceptions")
348
- @brokers["heartbeat"] = 60
349
- activity = RightSupport::Stats::Activity.new
350
- activity.update("no queue")
351
- activity.finish(@now - 10)
352
- activity.update("no queue consumers")
353
- activity.update("no queue consumers")
354
- flexmock(Time).should_receive(:now).and_return(1000010)
355
- @brokers["returns"] = activity.all
356
- result = @helpers.brokers_str(@brokers, :name_width => 10)
357
- result.should == "brokers : b0: rs-broker-localhost-5672 connected, disconnects: none, failures: none\n" +
358
- " b1: rs-broker-localhost-5673 disconnected, disconnects: 2 (16 min 40 sec ago), failures: none\n" +
359
- " b2: rs-broker-localhost-5674 failed, disconnects: none, failures: 3 (16 min 40 sec ago w/ 2 retries)\n" +
360
- " heartbeat : 60 sec\n" +
361
- " returns : no queue consumers: 67%, no queue: 33%, total: 3, \n" +
362
- " last: no queue consumers (10 sec ago), rate: 1.0/sec, latency: 1.0 sec\n"
363
- end
364
- end
365
-
366
- context "activity_str" do
367
- it 'converts activity stats to string' do
368
- activity = RightSupport::Stats::Activity.new
369
- activity.update("testing")
370
- activity.finish(@now - 10)
371
- activity.update("more testing")
372
- activity.update("more testing")
373
- activity.update("more testing")
374
- flexmock(Time).should_receive(:now).and_return(1000010)
375
- @helpers.activity_str(activity.all).should == "more testing: 75%, testing: 25%, total: 4, last: more testing (10 sec ago), " +
376
- "rate: 1.0/sec, latency: 1.0 sec"
377
- end
378
-
379
- it 'converts last activity stats to string' do
380
- activity = RightSupport::Stats::Activity.new
381
- activity.update("testing")
382
- activity.finish(@now - 10)
383
- activity.update("more testing")
384
- flexmock(Time).should_receive(:now).and_return(1000010)
385
- @helpers.last_activity_str(activity.last).should == "more testing: 10 sec ago"
386
- @helpers.last_activity_str(activity.last, single_item = true).should == "more testing (10 sec ago)"
387
- end
388
- end
389
-
390
- context "exceptions_str" do
391
- it "converts exception stats to multi-line string" do
392
- @exceptions.track("testing", Exception.new("This is a very long exception message that should be wrapped " +
393
- "so that it stays within the maximum line length"))
394
- flexmock(Time).should_receive(:now).and_return(1000010)
395
- category = "another"
396
- backtrace = ["It happened here", "Over there"]
397
- 4.times do |i|
398
- begin
399
- raise ArgumentError, "badarg"
400
- rescue Exception => e
401
- flexmock(e).should_receive(:backtrace).and_return(backtrace)
402
- @exceptions.track(category, e)
403
- backtrace.shift(1) if i == 1
404
- category = "testing" if i == 2
405
- end
406
- end
407
-
408
- result = @helpers.exceptions_str(@exceptions.stats, "----")
409
- result.should == "another total: 3, most recent:\n" +
410
- "----(1) Mon Jan 12 #{@hr}:46:50 ArgumentError: badarg IN Over there\n" +
411
- "----(2) Mon Jan 12 #{@hr}:46:50 ArgumentError: badarg IN It happened here\n" +
412
- "----testing total: 2, most recent:\n" +
413
- "----(1) Mon Jan 12 #{@hr}:46:50 ArgumentError: badarg IN Over there\n" +
414
- "----(1) Mon Jan 12 #{@hr}:46:40 Exception: This is a very long exception message that \n" +
415
- "---- should be wrapped so that it stays within the maximum line length"
416
- end
417
-
418
- it "removes embedded backtrace" do
419
- exceptions = {
420
- "receive" => {
421
- "total" => 2,
422
- "recent" => [{
423
- "type" => "RightScale::Serializer::SerializationError",
424
- "count" => 2,
425
- "when" => 1376259979,
426
- "where" => "/opt/rightscale/right_link/common/lib/common/serializer.rb:133:in `cascade_serializers'",
427
- "message" => "Could not load packet using [RightScale::SecureSerializer] " +
428
- "(Failed to load with RightScale::SecureSerializer (TypeError:\n " +
429
- "can't convert nil into String in\n /opt/rightscale/right_link/common/lib/common/security/signature.rb:56:in " +
430
- "`initialize'\n /opt/rightscale/right_link/common/lib/common/security/signature.rb:56:in " +
431
- "`new'\n /opt/\nrightscale/right_link/common/lib/common/security/signature.rb:56:in " +
432
- "`from_data'\n /opt/rightscale/right_link/common/lib/common/security/secure_serializer.rb:115:in " +
433
- "`load'\n /opt/rightscale/right_link/common/lib/\ncommon/serializer.rb:125:in `__send__'\n " +
434
- "/opt/rightscale/right_link/common/lib/common/serializer.rb:125:in `cascade_serializers'\n " +
435
- "/opt/rightscale/right_link/common/lib/common/serializer.rb:122:in `map'\n " +
436
- "/opt/\nrightscale/right_link/common/lib/common/serializer.rb:122:in `cascade_serializers'\n " +
437
- "/opt/rightscale/right_link/common/lib/common/serializer.rb:96:in `load'\n " +
438
- "/opt/rightscale/right_link/common/lib/common/broker_\nclient.rb:609:in `receive'\n " +
439
- "/opt/rightscale/right_link/common/lib/common/broker_client.rb:243:in `subscribe'\n " +
440
- "/opt/rightscale/sandbox/lib/ruby/gems/1.8/gems/amqp-0.6.7/lib/mq/queue.rb:391:in `call'\n " +
441
- "/opt/rig\nhtscale/sandbox/lib/ruby/gems/1.8/gems/amqp-0.6.7/lib/mq/queue.rb:391:in `receive'\n " +
442
- "/opt/rightscale/right_link/common/lib/common/amqp.rb:68:in `process_frame'\n " +
443
- "/opt/rightscale/sandbox/lib/ruby/gems/1.8/gems/am\nqp-0.6.7/lib/amqp/client.rb:9:in `orig_process_frame'\n " +
444
- "/opt/rightscale/right_link/common/lib/common/amqp.rb:268:in `process_frame'\n " +
445
- "/opt/rightscale/sandbox/lib/ruby/gems/1.8/gems/amqp-0.6.7/lib/amqp/client.rb:\n117:in `orig_receive_data'\n " +
446
- "/opt/rightscale/right_link/common/lib/common/amqp.rb:252:in `receive_data'\n " +
447
- "/opt/rightscale/sandbox/lib/ruby/gems/1.8/gems/eventmachine-0.12.11.5/lib/eventmachine.rb:194:in `run_mac\n" +
448
- "hine'\n /opt/rightscale/sandbox/lib/ruby/gems/1.8/gems/eventmachine-0.12.11.5/lib/eventmachine.rb:194:in `run'\n " +
449
- "/opt/rightscale/right_link/scripts/lib/agent_controller.rb:346:in `start_agent'\n " +
450
- "/opt/rightscale\n/right_link/scripts/lib/agent_controller.rb:260:in `run_cmd'\n " +
451
- "/opt/rightscale/right_link/scripts/lib/agent_controller.rb:144:in `control'\n " +
452
- "/opt/rightscale/right_link/scripts/lib/agent_controller.rb:102:in `run\n'\n " +
453
- "/opt/rightscale/right_link/scripts/rnac.rb:37)) IN " +
454
- "/opt/rightscale/right_link/common/lib/common/serializer.rb:133:in `cascade_serializers'"}]}}
455
- RightSupport::Stats.exceptions_str(exceptions, "").should ==
456
- "receive total: 2, most recent:\n" +
457
- "(2) #{Time.at(exceptions['receive']['recent'].first['when']).strftime("%a %b %d %H:%M:%S")} RightScale::Serializer::SerializationError: Could not \n" +
458
- " load packet using [RightScale::SecureSerializer] (Failed to load with \n" +
459
- " RightScale::SecureSerializer (TypeError: can't convert nil into String in /opt/\n" +
460
- " rightscale/right_link/common/lib/common/security/signature.rb:56:in \n" +
461
- " `initialize'... IN /opt/rightscale/right_link/common/lib/common/serializer.\n" +
462
- " rb:133:in `cascade_serializers'"
463
- end
464
- end
465
-
466
- context "hash_str" do
467
- it "converts nested hash into string with keys sorted numerically if possible, else alphabetically" do
468
- hash = {"dogs" => 2, "cats" => 3, "hippopotami" => 99, "bears" => 1, "ants" => 100000000, "dragons" => nil,
469
- "food" => {"apples" => "bushels", "berries" => "lots", "meat" => {"fish" => 10.54, "beef" => nil}},
470
- "versions" => { "1" => 10, "5" => 50, "10" => 100} }
471
- result = @helpers.hash_str(hash)
472
- result.should == "ants: 100000000, bears: 1, cats: 3, dogs: 2, dragons: none, " +
473
- "food: [ apples: bushels, berries: lots, meat: [ beef: none, fish: 11 ] ], " +
474
- "hippopotami: 99, versions: [ 1: 10, 5: 50, 10: 100 ]"
475
- result = @helpers.wrap(result, 24, "----", /, /)
476
- result.should == "ants: 100000000, \n" +
477
- "----bears: 1, cats: 3, \n" +
478
- "----dogs: 2, \n" +
479
- "----dragons: none, \n" +
480
- "----food: [ apples: bushels, \n" +
481
- "----berries: lots, \n" +
482
- "----meat: [ beef: none, \n" +
483
- "----fish: 11 ] ], \n" +
484
- "----hippopotami: 99, \n" +
485
- "----versions: [ 1: 10, \n" +
486
- "----5: 50, 10: 100 ]"
487
- end
488
- end
489
-
490
- context "sub_stats_str" do
491
- it "converts sub-stats to a display string" do
492
- @exceptions.track("testing", Exception.new("Test error"))
493
- activity1 = RightSupport::Stats::Activity.new
494
- activity2 = RightSupport::Stats::Activity.new
495
- activity3 = RightSupport::Stats::Activity.new
496
- activity2.update("stats")
497
- activity2.update("testing")
498
- activity2.update("more testing")
499
- activity2.update("more testing")
500
- activity2.update("more testing")
501
- activity3.update("testing forever", "id")
502
- flexmock(Time).should_receive(:now).and_return(1002800)
503
-
504
- stats = {"exceptions" => @exceptions.stats,
505
- "empty_hash" => {},
506
- "float_value" => 3.15,
507
- "some % percent" => 3.54,
508
- "some delay" => 0.125,
509
- "some time" => 0.675,
510
- "some rate" => 4.72,
511
- "some age" => 125,
512
- "activity1 %" => activity1.percentage,
513
- "activity1 last" => activity1.last,
514
- "activity2 %" => activity2.percentage,
515
- "activity2 last" => activity2.last,
516
- "activity3 last" => activity3.last,
517
- "some hash" => {"dogs" => 2, "cats" => 3, "hippopotami" => 99, "bears" => 1,
518
- "ants" => 100000000, "dragons" => nil, "leopards" => 25}}
519
-
520
- result = @helpers.sub_stats_str("my sub-stats", stats, :name_width => 13, :sub_stat_value_width => 60)
521
- result.should == "my sub-stats : activity1 % : none\n" +
522
- " activity1 last : none\n" +
523
- " activity2 % : more testing: 60%, testing: 20%, stats: 20%, total: 5\n" +
524
- " activity2 last : more testing: 46 min 40 sec ago\n" +
525
- " activity3 last : testing forever: 46 min 40 sec ago and still active\n" +
526
- " empty_hash : none\n" +
527
- " exceptions : testing total: 1, most recent:\n" +
528
- " (1) Mon Jan 12 #{@hr}:46:40 Exception: Test error\n" +
529
- " float_value : 3.2\n" +
530
- " some % : 3.5%\n" +
531
- " some age : 2 min 5 sec\n" +
532
- " some delay : 0.13 sec\n" +
533
- " some hash : ants: 100000000, bears: 1, cats: 3, dogs: 2, dragons: none, \n" +
534
- " hippopotami: 99, leopards: 25\n" +
535
- " some rate : 4.7/sec\n" +
536
- " some time : 0.68 sec\n"
537
- end
538
- end
539
-
540
- context "stats_str" do
541
- it "converts stats to a display string with special formatting for generic keys" do
542
- @exceptions.track("testing", Exception.new("Test error"))
543
- activity = RightSupport::Stats::Activity.new
544
- activity.update("testing")
545
- flexmock(Time).should_receive(:now).and_return(1000010)
546
- sub_stats = {"exceptions" => @exceptions.stats,
547
- "empty_hash" => {},
548
- "float_value" => 3.15,
549
- "activity %" => activity.percentage,
550
- "activity last" => activity.last,
551
- "some hash" => {"dogs" => 2, "cats" => 3, "hippopotami" => 99, "bears" => 1,
552
- "ants" => 100000000, "dragons" => nil, "leopards" => 25}}
553
- stats = {"stat time" => @now,
554
- "last reset time" => @now,
555
- "service uptime" => 3720,
556
- "machine uptime" => 183546,
557
- "version" => 10,
558
- "brokers" => @brokers,
559
- "hostname" => "localhost",
560
- "identity" => "unit tester",
561
- "stuff stats" => sub_stats}
562
-
563
- result = @helpers.stats_str(stats)
564
- result.should == "identity : unit tester\n" +
565
- "hostname : localhost\n" +
566
- "stat time : Mon Jan 12 #{@hr}:46:40 1970\n" +
567
- "last reset : Mon Jan 12 #{@hr}:46:40 1970\n" +
568
- "service up : 1 hr 2 min\n" +
569
- "machine up : 2 days 2 hr 59 min\n" +
570
- "version : 10\n" +
571
- "brokers : b0: rs-broker-localhost-5672 connected, disconnects: none, failures: none\n" +
572
- " b1: rs-broker-localhost-5673 disconnected, disconnects: 2 (16 min 40 sec ago), failures: none\n" +
573
- " b2: rs-broker-localhost-5674 failed, disconnects: none, failures: 3 (16 min 40 sec ago w/ 2 retries)\n" +
574
- " exceptions : none\n" +
575
- " heartbeat : none\n" +
576
- " returns : none\n" +
577
- "stuff : activity % : testing: 100%, total: 1\n" +
578
- " activity last : testing: 10 sec ago\n" +
579
- " empty_hash : none\n" +
580
- " exceptions : testing total: 1, most recent:\n" +
581
- " (1) Mon Jan 12 #{@hr}:46:40 Exception: Test error\n" +
582
- " float_value : 3.2\n" +
583
- " some hash : ants: 100000000, bears: 1, cats: 3, dogs: 2, dragons: none, hippopotami: 99, \n" +
584
- " leopards: 25\n"
585
- end
586
-
587
- it "treats broker status, version, and machine uptime as optional" do
588
- sub_stats = {"exceptions" => @exceptions.stats,
589
- "empty_hash" => {},
590
- "float_value" => 3.15}
591
-
592
- stats = {"stat time" => @now,
593
- "last reset time" => @now,
594
- "service uptime" => 1000,
595
- "hostname" => "localhost",
596
- "identity" => "unit tester",
597
- "stuff stats" => sub_stats}
598
-
599
- result = @helpers.stats_str(stats)
600
- result.should == "identity : unit tester\n" +
601
- "hostname : localhost\n" +
602
- "stat time : Mon Jan 12 #{@hr}:46:40 1970\n" +
603
- "last reset : Mon Jan 12 #{@hr}:46:40 1970\n" +
604
- "service up : 16 min 40 sec\n" +
605
- "stuff : empty_hash : none\n" +
606
- " exceptions : none\n" +
607
- " float_value : 3.2\n"
608
- end
609
-
610
- it "displays name if provided" do
611
- sub_stats = {"exceptions" => @exceptions.stats,
612
- "empty_hash" => {},
613
- "float_value" => 3.15}
614
-
615
- stats = {"stat time" => @now,
616
- "last reset time" => @now,
617
- "service uptime" => 1000,
618
- "hostname" => "localhost",
619
- "identity" => "unit tester",
620
- "name" => "tester_1",
621
- "stuff stats" => sub_stats}
622
-
623
- result = @helpers.stats_str(stats)
624
- result.should == "name : tester_1\n" +
625
- "identity : unit tester\n" +
626
- "hostname : localhost\n" +
627
- "stat time : Mon Jan 12 #{@hr}:46:40 1970\n" +
628
- "last reset : Mon Jan 12 #{@hr}:46:40 1970\n" +
629
- "service up : 16 min 40 sec\n" +
630
- "stuff : empty_hash : none\n" +
631
- " exceptions : none\n" +
632
- " float_value : 3.2\n"
633
- end
634
-
635
- it "sorts stats using optional prefix" do
636
- sub_stats = {"empty_hash" => {},
637
- "float_value" => 3.15}
638
-
639
- stats = {"stat time" => @now,
640
- "last reset time" => @now,
641
- "service uptime" => 1000,
642
- "hostname" => "localhost",
643
- "identity" => "unit tester",
644
- "stuff stats" => sub_stats,
645
- "other stuff stats" => sub_stats,
646
- "/data stats" => sub_stats}
647
-
648
- result = @helpers.stats_str(stats, :sub_name_width => 11)
649
- result.should == "identity : unit tester\n" +
650
- "hostname : localhost\n" +
651
- "stat time : Mon Jan 12 #{@hr}:46:40 1970\n" +
652
- "last reset : Mon Jan 12 #{@hr}:46:40 1970\n" +
653
- "service up : 16 min 40 sec\n" +
654
- "/data : empty_hash : none\n" +
655
- " float_value : 3.2\n" +
656
- "other stuff : empty_hash : none\n" +
657
- " float_value : 3.2\n" +
658
- "stuff : empty_hash : none\n" +
659
- " float_value : 3.2\n"
660
-
661
- stats = {"stat time" => @now,
662
- "last reset time" => @now,
663
- "service uptime" => 1000,
664
- "hostname" => "localhost",
665
- "identity" => "unit tester",
666
- "stuff 0stats" => sub_stats,
667
- "other stuff 1stats" => sub_stats,
668
- "/data stats" => sub_stats}
669
-
670
- result = @helpers.stats_str(stats, :name_width => 15)
671
- result.should == "identity : unit tester\n" +
672
- "hostname : localhost\n" +
673
- "stat time : Mon Jan 12 #{@hr}:46:40 1970\n" +
674
- "last reset : Mon Jan 12 #{@hr}:46:40 1970\n" +
675
- "service up : 16 min 40 sec\n" +
676
- "stuff : empty_hash : none\n" +
677
- " float_value : 3.2\n" +
678
- "other stuff : empty_hash : none\n" +
679
- " float_value : 3.2\n" +
680
- "/data : empty_hash : none\n" +
681
- " float_value : 3.2\n"
682
- end
683
- end
684
-
685
- end # RightSupport::Stats