librato-rails 0.7.2 → 0.7.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.
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
 
3
4
  class LibratoRailsRemoteTest < ActiveSupport::TestCase
4
-
5
+
5
6
  # These tests connect to the Metrics server with an account and verify remote
6
7
  # functions. They will only run if the below environment variables are set.
7
8
  #
@@ -9,7 +10,7 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
9
10
  # test account.
10
11
  #
11
12
  if ENV['LIBRATO_RAILS_TEST_EMAIL'] && ENV['LIBRATO_RAILS_TEST_API_KEY']
12
-
13
+
13
14
  setup do
14
15
  # delete any generated Librato::Rails
15
16
  Librato::Rails.user = ENV['LIBRATO_RAILS_TEST_EMAIL']
@@ -18,22 +19,22 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
18
19
  Librato::Rails.api_endpoint = ENV['LIBRATO_RAILS_TEST_API_ENDPOINT']
19
20
  end
20
21
  Librato::Rails.delete_all
22
+ delete_all_metrics
21
23
  end
22
-
24
+
23
25
  teardown do
24
26
  Librato::Rails.prefix = nil
25
27
  end
26
28
 
27
29
  test 'flush sends counters' do
28
- delete_all_metrics
29
30
  source = Librato::Rails.qualified_source
30
-
31
+
31
32
  Librato::Rails.increment :foo
32
33
  Librato::Rails.increment :bar, 2
33
34
  Librato::Rails.increment :foo
34
35
  Librato::Rails.increment :foo, :source => 'baz', :by => 3
35
36
  Librato::Rails.flush
36
-
37
+
37
38
  client = Librato::Rails.client
38
39
  metric_names = client.list.map { |m| m['name'] }
39
40
  assert metric_names.include?('foo'), 'foo should be present'
@@ -42,104 +43,151 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
42
43
  foo = client.fetch 'foo', :count => 10
43
44
  assert_equal 1, foo[source].length
44
45
  assert_equal 2, foo[source][0]['value']
45
-
46
+
46
47
  # custom source
47
48
  assert_equal 1, foo['baz'].length
48
- assert_equal 3, foo['baz'][0]['value']
49
-
49
+ assert_equal 3, foo['baz'][0]['value']
50
+
50
51
  bar = client.fetch 'bar', :count => 10
51
52
  assert_equal 1, bar[source].length
52
53
  assert_equal 2, bar[source][0]['value']
53
54
  end
54
-
55
+
55
56
  test 'counters should persist through flush' do
56
57
  Librato::Rails.increment 'knightrider'
57
58
  Librato::Rails.increment 'badguys', :sporadic => true
58
59
  assert_equal 1, Librato::Rails.counters['knightrider']
59
60
  assert_equal 1, Librato::Rails.counters['badguys']
60
-
61
+
61
62
  Librato::Rails.flush
62
63
  assert_equal 0, Librato::Rails.counters['knightrider']
63
64
  assert_equal nil, Librato::Rails.counters['badguys']
64
65
  end
65
-
66
+
66
67
  test 'flush sends measures/timings' do
67
- delete_all_metrics
68
68
  source = Librato::Rails.qualified_source
69
-
69
+
70
70
  Librato::Rails.timing 'request.time.total', 122.1
71
71
  Librato::Rails.measure 'items_bought', 20
72
72
  Librato::Rails.timing 'request.time.total', 81.3
73
73
  Librato::Rails.timing 'jobs.queued', 5, :source => 'worker.3'
74
74
  Librato::Rails.flush
75
-
75
+
76
76
  client = Librato::Rails.client
77
77
  metric_names = client.list.map { |m| m['name'] }
78
78
  assert metric_names.include?('request.time.total'), 'request.time.total should be present'
79
79
  assert metric_names.include?('items_bought'), 'request.time.db should be present'
80
-
80
+
81
81
  total = client.fetch 'request.time.total', :count => 10
82
82
  assert_equal 2, total[source][0]['count']
83
83
  assert_in_delta 203.4, total[source][0]['sum'], 0.1
84
-
84
+
85
85
  items = client.fetch 'items_bought', :count => 10
86
86
  assert_equal 1, items[source][0]['count']
87
87
  assert_in_delta 20, items[source][0]['sum'], 0.1
88
-
88
+
89
89
  jobs = client.fetch 'jobs.queued', :count => 10
90
90
  assert_equal 1, jobs['worker.3'][0]['count']
91
91
  assert_in_delta 5, jobs['worker.3'][0]['sum'], 0.1
92
92
  end
93
-
93
+
94
94
  test 'flush should purge measures/timings' do
95
- delete_all_metrics
96
-
97
95
  Librato::Rails.timing 'request.time.total', 122.1
98
96
  Librato::Rails.measure 'items_bought', 20
99
97
  Librato::Rails.flush
100
-
98
+
101
99
  assert Librato::Rails.aggregate.empty?, 'measures and timings should be cleared with flush'
102
100
  end
103
-
101
+
104
102
  test 'empty flush should not be sent' do
105
- delete_all_metrics
106
103
  Librato::Rails.flush
107
-
108
104
  assert_equal [], Librato::Rails.client.list
109
105
  end
110
-
106
+
111
107
  test 'flush respects prefix' do
112
- delete_all_metrics
113
108
  source = Librato::Rails.qualified_source
114
109
  Librato::Rails.prefix = 'testyprefix'
115
-
110
+
116
111
  Librato::Rails.timing 'mytime', 221.1
117
112
  Librato::Rails.increment 'mycount', 4
118
113
  Librato::Rails.flush
119
-
114
+
120
115
  client = Librato::Rails.client
121
116
  metric_names = client.list.map { |m| m['name'] }
122
117
  assert metric_names.include?('testyprefix.mytime'), 'testyprefix.mytime should be present'
123
118
  assert metric_names.include?('testyprefix.mycount'), 'testyprefix.mycount should be present'
124
-
119
+
125
120
  mytime = client.fetch 'testyprefix.mytime', :count => 10
126
121
  assert_equal 1, mytime[source][0]['count']
127
-
122
+
128
123
  mycount = client.fetch 'testyprefix.mycount', :count => 10
129
124
  assert_equal 4, mycount[source][0]['value']
130
125
  end
131
-
126
+
127
+ test 'flush recovers from failed flush' do
128
+ client = Librato::Rails.client
129
+ source = Librato::Rails.qualified_source
130
+
131
+ # create a metric foo of counter type
132
+ client.submit :foo => {:type => :counter, :value => 12}
133
+
134
+ # failing flush - submit a foo measurement as a gauge (type mismatch)
135
+ Librato::Rails.measure :foo, 2.12
136
+ Librato::Rails.flush
137
+
138
+ foo = client.fetch :foo, :count => 10
139
+ assert_equal 1, foo['unassigned'].length
140
+ assert_nil foo[source] # shouldn't have been accepted
141
+
142
+ Librato::Rails.measure :boo, 2.12
143
+ Librato::Rails.flush
144
+
145
+ boo = client.fetch :boo, :count => 10
146
+ assert_equal 2.12, boo[source][0]["value"]
147
+ end
148
+
149
+ test 'flush tolerates invalid metric names' do
150
+ client = Librato::Rails.client
151
+ source = Librato::Rails.qualified_source
152
+
153
+ Librato::Rails.increment :foo
154
+ Librato::Rails.increment 'fübar'
155
+ Librato::Rails.measure 'fu/bar/baz', 12.1
156
+ Librato::Rails.flush
157
+
158
+ metric_names = client.list.map { |m| m['name'] }
159
+ assert metric_names.include?('foo')
160
+
161
+ # should have saved values for foo even though
162
+ # other metrics had invalid names
163
+ foo = client.fetch :foo, :count => 5
164
+ assert_equal 1.0, foo[source][0]["value"]
165
+ end
166
+
167
+ test 'flush tolerates invalid source names' do
168
+ client = Librato::Rails.client
169
+
170
+ Librato::Rails.increment :foo, :source => 'atreides'
171
+ Librato::Rails.increment :bar, :source => 'glébnöst'
172
+ Librato::Rails.measure 'baz', 2.25, :source => 'b/l/ak/nok'
173
+ Librato::Rails.flush
174
+
175
+ # should have saved values for foo even though
176
+ # other metrics had invalid sources
177
+ foo = client.fetch :foo, :count => 5
178
+ assert_equal 1.0, foo['atreides'][0]["value"]
179
+ end
180
+
132
181
  private
133
-
182
+
134
183
  def delete_all_metrics
135
184
  client = Librato::Rails.client
136
- client.list.each do |metric|
137
- client.connection.delete("metrics/#{metric['name']}")
138
- end
185
+ metric_names = client.list.map { |metric| metric['name'] }
186
+ client.delete(*metric_names) if !metric_names.empty?
139
187
  end
140
-
188
+
141
189
  else
142
190
  puts "Skipping remote tests..."
143
191
  end
144
-
192
+
145
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librato-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.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: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -91,6 +91,7 @@ files:
91
91
  - lib/librato/rails/group.rb
92
92
  - lib/librato/rails/railtie.rb
93
93
  - lib/librato/rails/subscribers.rb
94
+ - lib/librato/rails/validating_queue.rb
94
95
  - lib/librato/rails/version.rb
95
96
  - lib/librato/rails/worker.rb
96
97
  - lib/librato/rails.rb
@@ -197,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
198
  version: '0'
198
199
  segments:
199
200
  - 0
200
- hash: 3855473348708511701
201
+ hash: 1346909575512186282
201
202
  required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  none: false
203
204
  requirements:
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  version: '0'
207
208
  segments:
208
209
  - 0
209
- hash: 3855473348708511701
210
+ hash: 1346909575512186282
210
211
  requirements: []
211
212
  rubyforge_project:
212
213
  rubygems_version: 1.8.24