librato-rails 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,6 +31,7 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
31
31
  Librato::Rails.increment :foo
32
32
  Librato::Rails.increment :bar, 2
33
33
  Librato::Rails.increment :foo
34
+ Librato::Rails.increment :foo, :source => 'baz', :by => 3
34
35
  Librato::Rails.flush
35
36
 
36
37
  client = Librato::Rails.client
@@ -41,6 +42,10 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
41
42
  foo = client.fetch 'foo', :count => 10
42
43
  assert_equal 1, foo[source].length
43
44
  assert_equal 2, foo[source][0]['value']
45
+
46
+ # custom source
47
+ assert_equal 1, foo['baz'].length
48
+ assert_equal 3, foo['baz'][0]['value']
44
49
 
45
50
  bar = client.fetch 'bar', :count => 10
46
51
  assert_equal 1, bar[source].length
@@ -49,9 +54,13 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
49
54
 
50
55
  test 'counters should persist through flush' do
51
56
  Librato::Rails.increment 'knightrider'
57
+ Librato::Rails.increment 'badguys', :sporadic => true
52
58
  assert_equal 1, Librato::Rails.counters['knightrider']
59
+ assert_equal 1, Librato::Rails.counters['badguys']
60
+
53
61
  Librato::Rails.flush
54
62
  assert_equal 0, Librato::Rails.counters['knightrider']
63
+ assert_equal nil, Librato::Rails.counters['badguys']
55
64
  end
56
65
 
57
66
  test 'flush sends measures/timings' do
@@ -61,6 +70,7 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
61
70
  Librato::Rails.timing 'request.time.total', 122.1
62
71
  Librato::Rails.measure 'items_bought', 20
63
72
  Librato::Rails.timing 'request.time.total', 81.3
73
+ Librato::Rails.timing 'jobs.queued', 5, :source => 'worker.3'
64
74
  Librato::Rails.flush
65
75
 
66
76
  client = Librato::Rails.client
@@ -75,6 +85,10 @@ class LibratoRailsRemoteTest < ActiveSupport::TestCase
75
85
  items = client.fetch 'items_bought', :count => 10
76
86
  assert_equal 1, items[source][0]['count']
77
87
  assert_in_delta 20, items[source][0]['sum'], 0.1
88
+
89
+ jobs = client.fetch 'jobs.queued', :count => 10
90
+ assert_equal 1, jobs['worker.3'][0]['count']
91
+ assert_in_delta 5, jobs['worker.3'][0]['sum'], 0.1
78
92
  end
79
93
 
80
94
  test 'flush should purge measures/timings' do
@@ -36,4 +36,18 @@ class LibratoRailsAggregatorTest < MiniTest::Unit::TestCase
36
36
  assert_equal 'bar', timing
37
37
  end
38
38
 
39
+ def test_custom_source
40
+ # sources are kept separate
41
+ @agg.measure 'meaning.of.life', 1
42
+ @agg.measure 'meaning.of.life', 42, :source => 'douglas_adams'
43
+ assert_equal 1.0, @agg.fetch('meaning.of.life')[:sum]
44
+ assert_equal 42.0, @agg.fetch('meaning.of.life', :source => 'douglas_adams')[:sum]
45
+
46
+ # sources work with time blocks
47
+ @agg.timing 'mytiming', :source => 'mine' do
48
+ sleep 0.02
49
+ end
50
+ assert_in_delta @agg.fetch('mytiming', :source => 'mine')[:sum], 20, 10
51
+ end
52
+
39
53
  end
@@ -8,12 +8,83 @@ class LibratoRailsCounterCacheTest < MiniTest::Unit::TestCase
8
8
  assert_equal 1, cc[:foo]
9
9
 
10
10
  # accepts optional argument
11
- cc.increment :foo, 5
11
+ cc.increment :foo, :by => 5
12
12
  assert_equal 6, cc[:foo]
13
13
 
14
+ # legacy style
15
+ cc.increment :foo, 2
16
+ assert_equal 8, cc[:foo]
17
+
14
18
  # strings or symbols work
15
19
  cc.increment 'foo'
16
- assert_equal 7, cc['foo']
20
+ assert_equal 9, cc['foo']
21
+ end
22
+
23
+ def test_custom_sources
24
+ cc = Librato::Rails::CounterCache.new
25
+
26
+ cc.increment :foo, :source => 'bar'
27
+ assert_equal 1, cc.fetch(:foo, :source => 'bar')
28
+
29
+ # symbols also work
30
+ cc.increment :foo, :source => :baz
31
+ assert_equal 1, cc.fetch(:foo, :source => :baz)
32
+
33
+ # strings and symbols are interchangable
34
+ cc.increment :foo, :source => :bar
35
+ assert_equal 2, cc.fetch(:foo, :source => 'bar')
36
+
37
+ # custom source and custom increment
38
+ cc.increment :foo, :source => 'boombah', :by => 10
39
+ assert_equal 10, cc.fetch(:foo, :source => 'boombah')
40
+ end
41
+
42
+ def test_continuous
43
+ cc = Librato::Rails::CounterCache.new
44
+
45
+ cc.increment :foo
46
+ cc.increment :foo, :source => 'bar'
47
+
48
+ cc.increment :baz, :sporadic => true
49
+ cc.increment :baz, :source => 118, :sporadic => true
50
+ assert_equal 1, cc[:baz]
51
+ assert_equal 1, cc.fetch(:baz, :source => 118)
52
+
53
+ cc.flush_to(Librato::Metrics::Queue.new) # persist values once
54
+
55
+ # continous values persist
56
+ assert_equal 0, cc[:foo]
57
+ assert_equal 0, cc.fetch(:foo, :source => 'bar')
58
+
59
+ # non-continous do not
60
+ assert_equal nil, cc[:baz]
61
+ assert_equal nil, cc.fetch(:baz, :source => 118)
62
+
63
+ # add a different sporadic metric
64
+ cc.increment :bazoom, :sporadic => true
65
+ assert_equal 1, cc[:bazoom]
66
+
67
+ cc.flush_to(Librato::Metrics::Queue.new) # persist values again
68
+ assert_equal nil, cc[:bazoom]
69
+ end
70
+
71
+ def test_flushing
72
+ cc = Librato::Rails::CounterCache.new
73
+
74
+ cc.increment :foo
75
+ cc.increment :bar, :by => 2
76
+ cc.increment :foo, :source => 'foobar'
77
+ cc.increment :foo, :source => 'foobar', :by => 3
78
+
79
+ q = Librato::Metrics::Queue.new
80
+ cc.flush_to(q)
81
+
82
+ expected = Set.new [{:name=>"foo", :value=>1},
83
+ {:name=>"foo", :value=>4, :source=>"foobar"},
84
+ {:name=>"bar", :value=>2}]
85
+ queued = Set.new q.gauges
86
+ queued.each { |hash| hash.delete(:measure_time) }
87
+ assert_equal queued, expected
17
88
  end
18
89
 
19
90
  end
@@ -5,8 +5,12 @@ class LibratoRailsGroupTest < MiniTest::Unit::TestCase
5
5
  def test_basic_grouping
6
6
  Librato::Rails.group 'fruit' do |g|
7
7
  g.increment 'bites'
8
+ g.increment 'nibbles', :by => 2
8
9
  g.increment 'nibbles', 5
9
10
 
11
+ g.increment 'chomps', :source => 'pacman'
12
+ g.increment 'chomps', :source => 'pacman', :by => 5
13
+
10
14
  g.measure 'banana', 12
11
15
  g.measure 'banana', 10
12
16
 
@@ -15,7 +19,8 @@ class LibratoRailsGroupTest < MiniTest::Unit::TestCase
15
19
  end
16
20
 
17
21
  assert_equal 1, counters['fruit.bites']
18
- assert_equal 5, counters['fruit.nibbles']
22
+ assert_equal 7, counters['fruit.nibbles']
23
+ assert_equal 6, counters.fetch('fruit.chomps', :source => 'pacman')
19
24
 
20
25
  assert_equal 2, aggregate['fruit.banana'][:count]
21
26
  assert_equal 22, aggregate['fruit.banana'][:sum]
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.5.2
4
+ version: 0.6.0
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-10-08 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.7.2
37
+ version: 0.7.3
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.7.2
45
+ version: 0.7.3
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: sqlite3
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,7 @@ files:
86
86
  - lib/librato/rack/middleware.rb
87
87
  - lib/librato/rack.rb
88
88
  - lib/librato/rails/aggregator.rb
89
+ - lib/librato/rails/collector.rb
89
90
  - lib/librato/rails/counter_cache.rb
90
91
  - lib/librato/rails/group.rb
91
92
  - lib/librato/rails/railtie.rb
@@ -196,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
197
  version: '0'
197
198
  segments:
198
199
  - 0
199
- hash: 1496276957323870941
200
+ hash: 2251758174729954387
200
201
  required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  none: false
202
203
  requirements:
@@ -205,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  version: '0'
206
207
  segments:
207
208
  - 0
208
- hash: 1496276957323870941
209
+ hash: 2251758174729954387
209
210
  requirements: []
210
211
  rubyforge_project:
211
212
  rubygems_version: 1.8.24