harness 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/README.md +108 -323
  4. data/harness.gemspec +3 -12
  5. data/lib/harness.rb +69 -68
  6. data/lib/harness/async_queue.rb +29 -0
  7. data/lib/harness/fake_collector.rb +40 -0
  8. data/lib/harness/instrumentation.rb +21 -6
  9. data/lib/harness/null_collector.rb +23 -0
  10. data/lib/harness/subscription.rb +7 -0
  11. data/lib/harness/sync_queue.rb +14 -0
  12. data/lib/harness/version.rb +1 -1
  13. data/test/acceptance_test.rb +20 -0
  14. data/test/active_support_notifications_test.rb +93 -0
  15. data/test/async_queue_test.rb +14 -0
  16. data/test/instrumentation_test.rb +54 -0
  17. data/test/null_collector_test.rb +29 -0
  18. data/test/test_helper.rb +38 -34
  19. metadata +21 -196
  20. data/lib/harness/adapters/librato_adapter.rb +0 -90
  21. data/lib/harness/adapters/memory_adapter.rb +0 -27
  22. data/lib/harness/adapters/null_adapter.rb +0 -11
  23. data/lib/harness/adapters/stathat_adapter.rb +0 -75
  24. data/lib/harness/adapters/statsd_adapter.rb +0 -50
  25. data/lib/harness/consumer.rb +0 -35
  26. data/lib/harness/counter.rb +0 -29
  27. data/lib/harness/gauge.rb +0 -23
  28. data/lib/harness/integration/action_controller.rb +0 -9
  29. data/lib/harness/integration/action_mailer.rb +0 -9
  30. data/lib/harness/integration/action_view.rb +0 -9
  31. data/lib/harness/integration/active_model_serializers.rb +0 -9
  32. data/lib/harness/integration/active_support.rb +0 -9
  33. data/lib/harness/integration/sidekiq.rb +0 -47
  34. data/lib/harness/job.rb +0 -23
  35. data/lib/harness/measurement.rb +0 -43
  36. data/lib/harness/queues/delayed_job_queue.rb +0 -7
  37. data/lib/harness/queues/resque_queue.rb +0 -29
  38. data/lib/harness/queues/sidekiq_queue.rb +0 -31
  39. data/lib/harness/queues/synchronous_queue.rb +0 -18
  40. data/lib/harness/railtie.rb +0 -71
  41. data/lib/harness/tasks.rake +0 -6
  42. data/test/integration/counters_with_redis_test.rb +0 -67
  43. data/test/integration/instrumentation_test.rb +0 -50
  44. data/test/integration/integrations/action_controller_test.rb +0 -51
  45. data/test/integration/integrations/action_mailer_test.rb +0 -22
  46. data/test/integration/integrations/action_view_test.rb +0 -32
  47. data/test/integration/integrations/active_model_serializers_test.rb +0 -22
  48. data/test/integration/integrations/active_support_test.rb +0 -41
  49. data/test/integration/integrations/sidekiq_test.rb +0 -54
  50. data/test/integration/logging_test.rb +0 -17
  51. data/test/integration/queues/delayed_job_test.rb +0 -59
  52. data/test/integration/queues/resque_test.rb +0 -24
  53. data/test/integration/queues/sidekiq_test.rb +0 -34
  54. data/test/integration/railtie_test.rb +0 -26
  55. data/test/unit/adapters/librato_adapter_test.rb +0 -169
  56. data/test/unit/adapters/memory_adapter_test.rb +0 -22
  57. data/test/unit/adapters/stathat_adapter_test.rb +0 -144
  58. data/test/unit/adapters/statsd_adapter_test.rb +0 -74
  59. data/test/unit/counter_test.rb +0 -84
  60. data/test/unit/gauge_test.rb +0 -93
  61. data/test/unit/harness_test.rb +0 -39
  62. data/test/unit/measurement_test.rb +0 -76
data/lib/harness/job.rb DELETED
@@ -1,23 +0,0 @@
1
- module Harness
2
- class Job
3
- def log(measurement)
4
- logger.debug "[Harness] Processing Measurement: #{measurement.inspect}"
5
-
6
- case measurement.class.to_s.demodulize.underscore.to_sym
7
- when :gauge
8
- adapter.log_gauge measurement
9
- when :counter
10
- adapter.log_counter measurement
11
- end
12
- end
13
-
14
- private
15
- def logger
16
- Harness.logger
17
- end
18
-
19
- def adapter
20
- Harness.config.adapter
21
- end
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- module Harness
2
- class Measurement
3
- attr_accessor :id, :name, :source, :time, :value, :units, :period
4
-
5
- def initialize(attributes = {})
6
- attributes.each_pair do |name, value|
7
- send "#{name}=", value
8
- end
9
-
10
- self.time ||= Time.now
11
- end
12
-
13
- def time=(value)
14
- if value.is_a? String
15
- @time = DateTime.parse value
16
- elsif value.is_a? Fixnum
17
- @time = Time.at value
18
- else
19
- @time = value
20
- end
21
- end
22
-
23
- def log
24
- Harness.log self
25
- end
26
-
27
- def source
28
- @source || Harness.config.source
29
- end
30
-
31
- def attributes
32
- {
33
- :id => id,
34
- :name => name,
35
- :source => source,
36
- :time => time,
37
- :units => units,
38
- :value => value,
39
- :period => period
40
- }
41
- end
42
- end
43
- end
@@ -1,7 +0,0 @@
1
- module Harness
2
- class DelayedJobQueue
3
- def push(measurement)
4
- Harness::Job.new.delay(:queue => 'harness').log(measurement)
5
- end
6
- end
7
- end
@@ -1,29 +0,0 @@
1
- module Harness
2
- class ResqueQueue
3
- class SendGauge < Job
4
- @queue = :metrics
5
-
6
- def self.perform(attributes)
7
- gauge = Gauge.new attributes
8
- new.log gauge
9
- end
10
- end
11
-
12
- class SendCounter < Job
13
- @queue = :metrics
14
-
15
- def self.perform(attributes)
16
- counter = Counter.new attributes
17
- new.log counter
18
- end
19
- end
20
-
21
- def push(measurement)
22
- if measurement.is_a? Gauge
23
- Resque.enqueue SendGauge, measurement.attributes
24
- elsif measurement.is_a? Counter
25
- Resque.enqueue SendCounter, measurement.attributes
26
- end
27
- end
28
- end
29
- end
@@ -1,31 +0,0 @@
1
- module Harness
2
- class SidekiqQueue
3
- class SendGauge < Job
4
- include Sidekiq::Worker
5
- sidekiq_options :queue => :metrics
6
-
7
- def perform(attributes)
8
- gauge = Gauge.new attributes
9
- log gauge
10
- end
11
- end
12
-
13
- class SendCounter < Job
14
- include Sidekiq::Worker
15
- sidekiq_options :queue => :metrics
16
-
17
- def perform(attributes)
18
- counter = Counter.new attributes
19
- log counter
20
- end
21
- end
22
-
23
- def push(measurement)
24
- if measurement.is_a? Gauge
25
- SendGauge.perform_async measurement.attributes
26
- elsif measurement.is_a? Counter
27
- SendCounter.perform_async measurement.attributes
28
- end
29
- end
30
- end
31
- end
@@ -1,18 +0,0 @@
1
- module Harness
2
- class SynchronousQueue
3
- def push(measurement)
4
- begin
5
- Harness::Job.new.log(measurement)
6
- rescue LoggingError => ex
7
- logger.debug "[Harness] Logging measurement failed! Server Said: #{ex}"
8
- logger.debug ex.backtrace.join("\n")
9
- logger.warn "[Harness] Could not post measurement! Enable debug logging to see full errors"
10
- end
11
- end
12
-
13
- private
14
- def logger
15
- Harness.logger
16
- end
17
- end
18
- end
@@ -1,71 +0,0 @@
1
- module Harness
2
- class Railtie < ::Rails::Railtie
3
- config.harness = Harness.config
4
-
5
- # Set default instrumentation
6
- config.harness.instrument.action_controller = true
7
- config.harness.instrument.action_mailer = true
8
- config.harness.instrument.action_view = true
9
-
10
- config.harness.instrument.active_support = false
11
-
12
- # Custom instrumentation can be turned on as follows
13
- # See files in lib/harness/integration for available integrations
14
- #
15
- # config.harness.instrument.sidekiq = true
16
- # config.harness.instrument.active_model_serializers = true
17
-
18
- rake_tasks do
19
- load "harness/tasks.rake"
20
- end
21
-
22
- initializer "harness.adapter" do |app|
23
- app.config.harness.adapter ||= case Rails.env
24
- when 'development' then :null
25
- when 'test' then :null
26
- else :librato
27
- end
28
- end
29
-
30
- initializer "harness.logger" do |app|
31
- Harness.logger = Rails.logger
32
- end
33
-
34
- initializer "harness.source" do |app|
35
- Harness.config.source = app.class.name.underscore.dasherize
36
- end
37
-
38
- initializer "harness.redis" do
39
- if existing_url = ENV['REDISTOGO_URL'] || ENV['REDIS_URL']
40
- Harness.redis ||= Redis::Namespace.new('harness', :redis => Redis.connect(:url => existing_url))
41
- else
42
- Harness.redis ||= Redis::Namespace.new('harness', :redis => Redis.connect(:host => 'localhost', :port => '6379'))
43
- end
44
- end
45
-
46
- initializer "harness.queue" do
47
- Harness.config.queue = :synchronous
48
- end
49
-
50
- initializer "harness.queue.production" do |app|
51
- use_real_queue = Rails.env != 'development' && Rails.env != 'test'
52
-
53
- if defined?(Resque::Job) && use_real_queue
54
- require 'harness/queues/resque_queue'
55
- Harness.config.queue = :resque
56
- elsif defined?(Sidekiq::Worker) && use_real_queue
57
- require 'harness/queues/sidekiq_queue'
58
- Harness.config.queue = :sidekiq
59
- elsif defined?(Delayed::Worker) && use_real_queue
60
- require 'harness/queues/delayed_job_queue'
61
- Harness.config.queue = :delayed_job
62
- end
63
- end
64
-
65
- initializer "harness.instrumentation" do |app|
66
- app.config.harness.instrument.each_pair do |integration, value|
67
- require "harness/integration/#{integration}" if value
68
- end
69
- end
70
- end
71
- end
@@ -1,6 +0,0 @@
1
- namespace :harness do
2
- desc "Reset all counters back to zero"
3
- task :reset_counters => :environment do
4
- Harness.reset_counters!
5
- end
6
- end
@@ -1,67 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CountersWithRedis < IntegrationTest
4
- def test_stores_name_in_redis
5
- instrument "event-counter", :counter => true
6
-
7
- assert_equal 1, redis.get('counters/event-counter').to_i
8
-
9
- assert_counter_logged "event-counter"
10
- end
11
-
12
- def test_increments_counter_each_instrument
13
- instrument "event-counter", :counter => true
14
- assert_counter_logged "event-counter"
15
-
16
- counters.clear
17
-
18
- instrument "event-counter", :counter => true
19
- assert_counter_logged "event-counter"
20
-
21
- assert_equal 2, counters.first.value
22
- end
23
-
24
- def test_sets_given_value_in_redis_with_shortform
25
- instrument "event-counter", :counter => 10
26
-
27
- counters.clear
28
-
29
- instrument "event-counter", :counter => true
30
- assert_counter_logged 'event-counter'
31
-
32
- assert_equal 11, counters.first.value
33
- end
34
-
35
- def test_sets_given_value_in_redis_with_longform
36
- instrument "event-counter", :counter => { :value => 10 }
37
-
38
- assert_equal 10, redis.get("counters/event-counter").to_i
39
-
40
- counters.clear
41
-
42
- instrument "event-counter", :counter => true
43
- assert_counter_logged 'event-counter'
44
-
45
- assert_equal 11, counters.first.value
46
- end
47
-
48
- def test_resets_counters
49
- instrument "event-counter", :counter => true
50
- instrument "event-counter2", :counter => true
51
-
52
- assert_equal 1, redis.get("counters/event-counter").to_i
53
- assert_equal 1, redis.get("counters/event-counter2").to_i
54
-
55
- Harness.reset_counters!
56
-
57
- assert_equal 0, redis.get("counters/event-counter").to_i
58
- assert_equal 0, redis.get("counters/event-counter2").to_i
59
-
60
- counters.clear
61
- instrument "event-counter", :counter => true
62
- assert_counter_logged 'event-counter'
63
-
64
- assert_equal 1, counters.first.value
65
- assert_equal 1, redis.get("counters/event-counter").to_i
66
- end
67
- end
@@ -1,50 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveSupportTestCase < IntegrationTest
4
- def test_a_gauge_is_logged
5
- ActiveSupport::Notifications.instrument "gauge_test.harness", :gauge => true do |args|
6
- # do nothing
7
- end
8
-
9
- assert_gauge_logged "gauge_test.harness"
10
- end
11
-
12
- def test_a_counter_is_logged
13
- ActiveSupport::Notifications.instrument "counter_test.harness", :counter => { :value => 5 } do |args|
14
- # do nothing
15
- end
16
-
17
- assert_counter_logged "counter_test.harness"
18
- end
19
-
20
- def test_can_log_both
21
- ActiveSupport::Notifications.instrument "test.harness", :gauge => { :id => "test-gauge" }, :counter => {:id => 'test-counter', :value => 5 } do |args|
22
- # do nothing
23
- end
24
-
25
- assert_counter_logged "test-counter"
26
- assert_gauge_logged "test-gauge"
27
- end
28
-
29
- def test_does_not_log_counter_on_exception
30
- begin
31
- ActiveSupport::Notifications.instrument "counter_test.harness", :counter => true do |args|
32
- raise
33
- end
34
- rescue
35
- end
36
-
37
- refute_counter_logged "counter_test.harness"
38
- end
39
-
40
- def test_does_not_log_gauge_on_exception
41
- begin
42
- ActiveSupport::Notifications.instrument "gauge_test.harness", :gauge => true do |args|
43
- raise
44
- end
45
- rescue
46
- end
47
-
48
- refute_gauge_logged "gauge_test.harness"
49
- end
50
- end
@@ -1,51 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActionControllerIntegration < IntegrationTest
4
- def test_logs_write_fragment
5
- instrument "write_fragment"
6
-
7
- assert_gauge_logged "write_fragment.action_controller"
8
- end
9
-
10
- def test_logs_read_fragment
11
- instrument "read_fragment"
12
-
13
- assert_gauge_logged "read_fragment.action_controller"
14
- end
15
-
16
- def test_logs_expire_fragment
17
- instrument "expire_fragment"
18
-
19
- assert_gauge_logged "expire_fragment.action_controller"
20
- end
21
-
22
- def test_logs_write_page
23
- instrument "write_page"
24
-
25
- assert_gauge_logged "write_page.action_controller"
26
- end
27
-
28
- def test_logs_expire_page
29
- instrument "expire_page"
30
-
31
- assert_gauge_logged "expire_page.action_controller"
32
- end
33
-
34
- def test_logs_process_action
35
- instrument "process_action"
36
-
37
- assert_gauge_logged "process_action.action_controller"
38
- end
39
-
40
- def test_logs_send_file
41
- instrument "send_file"
42
-
43
- assert_gauge_logged "send_file.action_controller"
44
- end
45
-
46
- def instrument(event)
47
- ActiveSupport::Notifications.instrument "#{event}.action_controller" do |*args|
48
- # nada
49
- end
50
- end
51
- end
@@ -1,22 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActionMailerIntegration < IntegrationTest
4
- def test_logs_mail_received
5
- instrument "receive"
6
-
7
- assert_gauge_logged "receive.action_mailer"
8
- end
9
-
10
- def test_logs_mail_delivered
11
- instrument "deliver"
12
-
13
- assert_gauge_logged "deliver.action_mailer"
14
- end
15
-
16
- private
17
- def instrument(event)
18
- ActiveSupport::Notifications.instrument "#{event}.action_mailer" do |*args|
19
- # nada
20
- end
21
- end
22
- end
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActionViewIntegration < IntegrationTest
4
- def test_logs_render_template
5
- instrument "render_template"
6
-
7
- assert_gauge_logged "render_template.action_view"
8
- end
9
-
10
- def test_logs_render_partial
11
- instrument "render_partial"
12
-
13
- assert_gauge_logged "render_partial.action_view"
14
- end
15
-
16
- def test_skips_internal_partial_events
17
- instrument "!render_partial"
18
-
19
- refute_gauge_logged "!render_partial.action_view"
20
- end
21
-
22
- def test_skips_internal_template_events
23
- instrument "!render_template"
24
-
25
- refute_gauge_logged "!render_template.action_view"
26
- end
27
-
28
- private
29
- def instrument(event)
30
- ActiveSupport::Notifications.instrument "#{event}.action_view"
31
- end
32
- end