librato-rails 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.md +3 -1
  2. data/lib/librato/rails/aggregator.rb +11 -2
  3. data/lib/librato/rails/subscribers.rb +4 -4
  4. data/lib/librato/rails/version.rb +1 -1
  5. data/lib/librato/rails.rb +6 -5
  6. data/test/dummy/db/development.sqlite3 +0 -0
  7. data/test/dummy/db/test.sqlite3 +0 -0
  8. data/test/dummy/log/development.log +2189 -0
  9. data/test/dummy/log/test.log +5250 -0
  10. data/test/dummy/test_env.sh +2 -0
  11. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  12. data/test/dummy/tmp/cache/assets/CDF/870/sprockets%2Fb878faf942403e313a5b103e5d80488e +0 -0
  13. data/test/dummy/tmp/cache/assets/CE8/7E0/sprockets%2F178e2a1f9aa891d473009c7f3095df28 +0 -0
  14. data/test/dummy/tmp/cache/assets/CF9/7C0/sprockets%2F40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  15. data/test/dummy/tmp/cache/assets/D04/890/sprockets%2F587335c079eef8d5a63784fc8f99905a +0 -0
  16. data/test/dummy/tmp/cache/assets/D05/D40/sprockets%2F1c9faaf28d05409b88ad3113374d613c +0 -0
  17. data/test/dummy/tmp/cache/assets/D11/D90/sprockets%2Ff688bee5b15ad322749fd06432065df2 +0 -0
  18. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  19. data/test/dummy/tmp/cache/assets/D48/6E0/sprockets%2F3d5dd928c45756c99bb1018cdbba7485 +0 -0
  20. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  21. data/test/dummy/tmp/cache/assets/D4F/000/sprockets%2F25e44896aac12384727e9dab827ebef9 +0 -0
  22. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  23. data/test/dummy/tmp/cache/assets/D66/890/sprockets%2F789354d3ec91e1ba6c8e92878d8f6ff8 +0 -0
  24. data/test/dummy/tmp/cache/assets/D84/000/sprockets%2F2ed60caa8412eb8334fe327cab12cb32 +0 -0
  25. data/test/dummy/tmp/cache/assets/D8B/F90/sprockets%2Ffe6ce696e9141eb755d8eed79128e17c +0 -0
  26. data/test/dummy/tmp/cache/assets/D98/8B0/sprockets%2Fedbef6e0d0a4742346cf479f2c522eb0 +0 -0
  27. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  28. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  29. data/test/fixtures/config/librato.yml +1 -0
  30. data/test/integration/mail_test.rb +1 -3
  31. data/test/integration/request_test.rb +14 -18
  32. data/test/integration/sql_test.rb +8 -10
  33. data/test/metrics-rails_test.rb +5 -0
  34. data/test/unit/aggregator_test.rb +29 -6
  35. data/test/unit/configuration_test.rb +5 -3
  36. metadata +223 -183
@@ -0,0 +1,2 @@
1
+ export LIBRATO_METRICS_USER='matt@librato.com'
2
+ export LIBRATO_METRICS_TOKEN='02673bee476e872a5c40d4529d98c2cfd2d741882c302c1b7f10ccb1ee9eb45e'
@@ -4,6 +4,7 @@ test:
4
4
  prefix: 'rails-test'
5
5
  flush_interval: 30
6
6
  source: 'custom-1'
7
+ source_pids: false
7
8
 
8
9
  production:
9
10
  user: 'live@bar.com'
@@ -5,11 +5,9 @@ class MailTest < ActiveSupport::IntegrationCase
5
5
  # Query tests - the numbers specified assume running against SQLite
6
6
 
7
7
  test 'mail sent' do
8
- prefix = Librato::Rails.prefix
9
-
10
8
  user = User.create!(:email => 'foo@foo.com', :password => 'wow')
11
9
  UserMailer.welcome_email(user).deliver
12
- assert_equal 1, counters["#{prefix}.mail.sent"]
10
+ assert_equal 1, counters["rails.mail.sent"]
13
11
  end
14
12
 
15
13
  end
@@ -5,49 +5,45 @@ class RequestTest < ActiveSupport::IntegrationCase
5
5
  # Each request
6
6
 
7
7
  test 'increment total and status' do
8
- prefix = Librato::Rails.prefix
9
8
  visit root_path
10
9
 
11
- assert_equal 1, counters["#{prefix}.request.total"]
12
- assert_equal 1, counters["#{prefix}.request.status.200"]
13
- assert_equal 1, counters["#{prefix}.request.status.2xx"]
10
+ assert_equal 1, counters["rails.request.total"]
11
+ assert_equal 1, counters["rails.request.status.200"]
12
+ assert_equal 1, counters["rails.request.status.2xx"]
14
13
 
15
14
  visit '/status/204'
16
15
 
17
- assert_equal 2, counters["#{prefix}.request.total"]
18
- assert_equal 1, counters["#{prefix}.request.status.200"]
19
- assert_equal 1, counters["#{prefix}.request.status.204"]
20
- assert_equal 2, counters["#{prefix}.request.status.2xx"]
16
+ assert_equal 2, counters["rails.request.total"]
17
+ assert_equal 1, counters["rails.request.status.200"]
18
+ assert_equal 1, counters["rails.request.status.204"]
19
+ assert_equal 2, counters["rails.request.status.2xx"]
21
20
  end
22
21
 
23
22
  test 'request times' do
24
- prefix = Librato::Rails.prefix
25
23
  visit root_path
26
24
 
27
25
  # common for all paths
28
- assert_equal 1, aggregate["#{prefix}.request.time"][:count], 'should record total time'
29
- assert_equal 1, aggregate["#{prefix}.request.time.db"][:count], 'should record db time'
30
- assert_equal 1, aggregate["#{prefix}.request.time.view"][:count], 'should record view time'
26
+ assert_equal 1, aggregate["rails.request.time"][:count], 'should record total time'
27
+ assert_equal 1, aggregate["rails.request.time.db"][:count], 'should record db time'
28
+ assert_equal 1, aggregate["rails.request.time.view"][:count], 'should record view time'
31
29
 
32
30
  # status specific
33
- assert_equal 1, aggregate["#{prefix}.request.status.200.time"][:count]
34
- assert_equal 1, aggregate["#{prefix}.request.status.2xx.time"][:count]
31
+ assert_equal 1, aggregate["rails.request.status.200.time"][:count]
32
+ assert_equal 1, aggregate["rails.request.status.2xx.time"][:count]
35
33
  end
36
34
 
37
35
  test 'track exceptions' do
38
- prefix = Librato::Rails.prefix
39
36
  begin
40
37
  visit exception_path #rescue nil
41
38
  rescue RuntimeError => e
42
39
  raise unless e.message == 'test exception!'
43
40
  end
44
- assert_equal 1, counters["#{prefix}.request.exceptions"]
41
+ assert_equal 1, counters["rails.request.exceptions"]
45
42
  end
46
43
 
47
44
  test 'track slow requests' do
48
- prefix = Librato::Rails.prefix
49
45
  visit slow_path
50
- assert_equal 1, counters["#{prefix}.request.slow"]
46
+ assert_equal 1, counters["rails.request.slow"]
51
47
  end
52
48
 
53
49
  end
@@ -5,26 +5,24 @@ class SQLTest < ActiveSupport::IntegrationCase
5
5
  # Query tests - the numbers specified assume running against SQLite
6
6
 
7
7
  test 'total queries and query types' do
8
- prefix = Librato::Rails.prefix
9
-
10
8
  # note that modifying queries are wrapped in a transaction which
11
9
  # adds 2 to total queries per operation.
12
10
  user = User.create!(:email => 'foo@foo.com', :password => 'wow')
13
- assert_equal 3, counters["#{prefix}.sql.queries"]
14
- assert_equal 1, counters["#{prefix}.sql.inserts"]
11
+ assert_equal 3, counters["rails.sql.queries"]
12
+ assert_equal 1, counters["rails.sql.inserts"]
15
13
 
16
14
  foo = User.find_by_email('foo@foo.com')
17
- assert_equal 4, counters["#{prefix}.sql.queries"]
18
- assert_equal 1, counters["#{prefix}.sql.selects"]
15
+ assert_equal 4, counters["rails.sql.queries"]
16
+ assert_equal 1, counters["rails.sql.selects"]
19
17
 
20
18
  foo.password = 'new password'
21
19
  foo.save
22
- assert_equal 7, counters["#{prefix}.sql.queries"]
23
- assert_equal 1, counters["#{prefix}.sql.updates"]
20
+ assert_equal 7, counters["rails.sql.queries"]
21
+ assert_equal 1, counters["rails.sql.updates"]
24
22
 
25
23
  foo.destroy
26
- assert_equal 10, counters["#{prefix}.sql.queries"]
27
- assert_equal 1, counters["#{prefix}.sql.deletes"]
24
+ assert_equal 10, counters["rails.sql.queries"]
25
+ assert_equal 1, counters["rails.sql.deletes"]
28
26
  end
29
27
 
30
28
  end
@@ -36,4 +36,9 @@ class LibratoRailsTest < ActiveSupport::TestCase
36
36
  assert_match /\.\d{2,6}$/, Librato::Rails.qualified_source
37
37
  end
38
38
 
39
+ test 'qualified source does not include pid when disabled' do
40
+ Librato::Rails.source_pids = false
41
+ assert_match Librato::Rails.source, Librato::Rails.qualified_source
42
+ Librato::Rails.source_pids = true
43
+ end
39
44
  end
@@ -2,15 +2,38 @@ require 'test_helper'
2
2
 
3
3
  class LibratoRailsAggregatorTest < MiniTest::Unit::TestCase
4
4
 
5
+ def setup
6
+ @agg = Librato::Rails::Aggregator.new
7
+ end
8
+
5
9
  def test_adding_timings
6
- agg = Librato::Rails::Aggregator.new
10
+ @agg.timing 'request.time.total', 23.7
11
+ @agg.timing 'request.time.db', 5.3
12
+ @agg.timing 'request.time.total', 64.3
7
13
 
8
- agg.timing 'request.time.total', 23.7
9
- agg.timing 'request.time.db', 5.3
10
- agg.timing 'request.time.total', 64.3
14
+ assert_equal 2, @agg['request.time.total'][:count]
15
+ assert_equal 88.0, @agg['request.time.total'][:sum]
16
+ end
17
+
18
+ def test_block_timing
19
+ @agg.timing 'my.task' do
20
+ sleep 0.2
21
+ end
22
+ assert_in_delta @agg['my.task'][:sum], 200, 50
23
+
24
+ @agg.timing('another.task') { sleep 0.1 }
25
+ assert_in_delta @agg['another.task'][:sum], 100, 50
26
+ end
27
+
28
+ def test_return_values
29
+ simple = @agg.timing 'simple', 20
30
+ assert_equal nil, simple
11
31
 
12
- assert_equal 2, agg['request.time.total'][:count]
13
- assert_equal 88.0, agg['request.time.total'][:sum]
32
+ timing = @agg.timing 'foo' do
33
+ sleep 0.1
34
+ 'bar'
35
+ end
36
+ assert_equal 'bar', timing
14
37
  end
15
38
 
16
39
  end
@@ -7,16 +7,17 @@ class LibratoRailsAggregatorTest < MiniTest::Unit::TestCase
7
7
  ENV.delete('LIBRATO_METRICS_TOKEN')
8
8
  ENV.delete('LIBRATO_METRICS_SOURCE')
9
9
  Librato::Rails.check_config
10
+ Librato::Rails.prefix = nil
10
11
  end
11
12
 
12
13
  def test_environmental_variable_config
13
14
  ENV['LIBRATO_METRICS_USER'] = 'foo@bar.com'
14
15
  ENV['LIBRATO_METRICS_TOKEN'] = 'api_key'
15
- ENV['LIBRATO_METRICS_SOURCE'] = 'appname'
16
+ ENV['LIBRATO_METRICS_SOURCE'] = 'source'
16
17
  Librato::Rails.check_config
17
18
  assert_equal 'foo@bar.com', Librato::Rails.user
18
19
  assert_equal 'api_key', Librato::Rails.token
19
- assert_equal 'appname', Librato::Rails.prefix
20
+ assert_equal 'source', Librato::Rails.source
20
21
  end
21
22
 
22
23
  def test_config_file_config
@@ -26,13 +27,14 @@ class LibratoRailsAggregatorTest < MiniTest::Unit::TestCase
26
27
  assert_equal 'rails-test', Librato::Rails.prefix
27
28
  assert_equal 30, Librato::Rails.flush_interval
28
29
  assert_equal 'custom-1', Librato::Rails.source
30
+ assert_equal false, Librato::Rails.source_pids
29
31
  end
30
32
  end
31
33
 
32
34
  def test_environmental_and_config_file_config
33
35
  ENV['LIBRATO_METRICS_USER'] = 'foo@bar.com'
34
36
  ENV['LIBRATO_METRICS_TOKEN'] = 'api_key'
35
- ENV['LIBRATO_METRICS_SOURCE'] = 'appname'
37
+ ENV['LIBRATO_METRICS_SOURCE'] = 'source'
36
38
  with_fixture_config do
37
39
  assert_equal 'test@bar.com', Librato::Rails.user # from config file
38
40
  assert_equal 'test api key', Librato::Rails.token # from config file