librato-rails 0.9.0 → 0.10.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG.md +14 -0
  2. data/FAQ.md +25 -0
  3. data/README.md +11 -2
  4. data/lib/librato/rails/configuration.rb +26 -29
  5. data/lib/librato/rails/railtie.rb +30 -5
  6. data/lib/librato/rails/subscribers/cache.rb +22 -0
  7. data/lib/librato/rails/subscribers/controller.rb +56 -0
  8. data/lib/librato/rails/subscribers/mail.rb +18 -0
  9. data/lib/librato/rails/subscribers/render.rb +28 -0
  10. data/lib/librato/rails/subscribers/sql.rb +24 -0
  11. data/lib/librato/rails/subscribers.rb +14 -69
  12. data/lib/librato/rails/tracker.rb +13 -0
  13. data/lib/librato/rails/version.rb +1 -1
  14. data/lib/librato/rails.rb +9 -214
  15. data/test/dummy/app/assets/javascripts/application.js +0 -3
  16. data/test/dummy/app/controllers/cache_controller.rb +44 -0
  17. data/test/dummy/app/controllers/render_controller.rb +4 -0
  18. data/test/dummy/app/models/user.rb +7 -5
  19. data/test/dummy/app/views/render/_first.html.erb +1 -0
  20. data/test/dummy/app/views/render/_second.html.erb +1 -0
  21. data/test/dummy/app/views/render/partial.html.erb +2 -0
  22. data/test/dummy/app/views/render/template.html.erb +1 -0
  23. data/test/dummy/config/application.rb +8 -6
  24. data/test/dummy/config/environments/test.rb +1 -1
  25. data/test/dummy/config/routes.rb +12 -3
  26. data/test/integration/cache_test.rb +40 -0
  27. data/test/integration/mail_test.rb +2 -4
  28. data/test/integration/render_test.rb +27 -0
  29. data/test/integration/request_test.rb +15 -11
  30. data/test/integration/sql_test.rb +6 -6
  31. data/test/support/integration_case.rb +11 -7
  32. data/test/unit/configuration_test.rb +63 -73
  33. data/test/unit/tracker_test.rb +15 -0
  34. metadata +36 -53
  35. data/lib/librato/rack/middleware.rb +0 -47
  36. data/lib/librato/rack.rb +0 -4
  37. data/lib/librato/rails/aggregator.rb +0 -95
  38. data/lib/librato/rails/collector.rb +0 -45
  39. data/lib/librato/rails/counter_cache.rb +0 -122
  40. data/lib/librato/rails/group.rb +0 -27
  41. data/lib/librato/rails/logging.rb +0 -77
  42. data/lib/librato/rails/validating_queue.rb +0 -31
  43. data/lib/librato/rails/worker.rb +0 -54
  44. data/lib/tasks/metrics-rails_tasks.rake +0 -4
  45. data/test/librato-rails_test.rb +0 -44
  46. data/test/remote/rails_remote_test.rb +0 -193
  47. data/test/unit/aggregator_test.rb +0 -53
  48. data/test/unit/counter_cache_test.rb +0 -90
  49. data/test/unit/group_test.rb +0 -54
  50. data/test/unit/middleware_test.rb +0 -82
  51. data/test/unit/worker_test.rb +0 -31
@@ -1,82 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MetricRackMiddlewareTest < MiniTest::Unit::TestCase
4
-
5
- def setup
6
- Librato::Rails.stubs(:forking_server?).returns(false)
7
- Librato::Rails.stubs(:measure).returns(true)
8
- Librato::Rails.stubs(:increment).returns(true)
9
-
10
- Time.stubs(:now).returns(Time.at(0.1305), Time.at(0.20075))
11
-
12
- @middleware = Librato::Rack::Middleware.new(
13
- stub(:call => [200, {}, []])
14
- )
15
- end
16
-
17
- def teardown
18
- Librato::Rails.unstub :forking_server?, :measure, :increment
19
- Time.unstub :now
20
- end
21
-
22
- def test_logs_header_metrics
23
- Librato::Rails.expects(:measure).with('rack.heroku.queue.depth', 1.0)
24
- Librato::Rails.expects(:measure).with('rack.heroku.queue.wait_time', 20.5)
25
- Librato::Rails.expects(:measure).with('rack.heroku.queue.dynos', 2.0)
26
-
27
- @middleware.call(
28
- 'HTTP_X_HEROKU_QUEUE_DEPTH' => '1',
29
- 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => '20.5',
30
- 'HTTP_X_HEROKU_DYNOS_IN_USE' => '2'
31
- )
32
- end
33
-
34
- def test_logs_request_time
35
- Librato::Rails.expects(:measure).with('rack.request.time', 70.25)
36
-
37
- @middleware.call({})
38
- end
39
-
40
- def test_increments_request_count
41
- Librato::Rails.expects(:increment).with('rack.request.total', 1)
42
-
43
- @middleware.call({})
44
- end
45
-
46
- def test_log_200_status
47
- Librato::Rails.expects(:increment).with('rack.request.status.200', 1)
48
- Librato::Rails.expects(:increment).with('rack.request.status.2xx', 1)
49
-
50
- Librato::Rails.expects(:measure).with('rack.request.status.200.time', 70.25)
51
- Librato::Rails.expects(:measure).with('rack.request.status.2xx.time', 70.25)
52
-
53
- @middleware.call({})
54
- end
55
-
56
- def test_log_403_status
57
- Librato::Rails.expects(:increment).with('rack.request.status.403', 1)
58
- Librato::Rails.expects(:increment).with('rack.request.status.4xx', 1)
59
-
60
- Librato::Rails.expects(:measure).with('rack.request.status.403.time', 70.25)
61
- Librato::Rails.expects(:measure).with('rack.request.status.4xx.time', 70.25)
62
-
63
- @middleware = Librato::Rack::Middleware.new stub(:call => [403, {}, []])
64
- @middleware.call({})
65
- end
66
-
67
- def test_fast_queries_are_not_slow
68
- Time.stubs(:now).returns(0.1305, 0.3305)
69
-
70
- Librato::Rails.expects(:increment).with('rack.request.slow', 1).never
71
-
72
- @middleware.call({})
73
- end
74
-
75
- def test_log_slow_queries
76
- Time.stubs(:now).returns(0.1305, 0.40075)
77
-
78
- Librato::Rails.expects(:increment).with('rack.request.slow', 1)
79
-
80
- @middleware.call({})
81
- end
82
- end
@@ -1,31 +0,0 @@
1
- require 'test_helper'
2
-
3
- class LibratoRailsWorkerTest < MiniTest::Unit::TestCase
4
-
5
- def test_basic_use
6
- worker = Librato::Rails::Worker.new
7
- counter = 0
8
- Thread.new do
9
- worker.run_periodically(0.1) do
10
- counter += 1
11
- end
12
- end
13
- sleep 0.45
14
- assert_equal counter, 4
15
- end
16
-
17
- def test_start_time
18
- worker = Librato::Rails::Worker.new
19
-
20
- time = Time.now
21
- start = worker.start_time(60)
22
- assert start >= time + 60, 'should be more than 60 seconds from when run'
23
- assert_equal 0, start.sec, 'should start on a whole minute'
24
-
25
- time = Time.now
26
- start = worker.start_time(10)
27
- assert start >= time + 10, 'should be more than 10 seconds from when run'
28
- assert_equal 0, start.sec%10, 'should be evenly divisible with whole minutes'
29
- end
30
-
31
- end