harness 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +108 -323
- data/harness.gemspec +3 -12
- data/lib/harness.rb +69 -68
- data/lib/harness/async_queue.rb +29 -0
- data/lib/harness/fake_collector.rb +40 -0
- data/lib/harness/instrumentation.rb +21 -6
- data/lib/harness/null_collector.rb +23 -0
- data/lib/harness/subscription.rb +7 -0
- data/lib/harness/sync_queue.rb +14 -0
- data/lib/harness/version.rb +1 -1
- data/test/acceptance_test.rb +20 -0
- data/test/active_support_notifications_test.rb +93 -0
- data/test/async_queue_test.rb +14 -0
- data/test/instrumentation_test.rb +54 -0
- data/test/null_collector_test.rb +29 -0
- data/test/test_helper.rb +38 -34
- metadata +21 -196
- data/lib/harness/adapters/librato_adapter.rb +0 -90
- data/lib/harness/adapters/memory_adapter.rb +0 -27
- data/lib/harness/adapters/null_adapter.rb +0 -11
- data/lib/harness/adapters/stathat_adapter.rb +0 -75
- data/lib/harness/adapters/statsd_adapter.rb +0 -50
- data/lib/harness/consumer.rb +0 -35
- data/lib/harness/counter.rb +0 -29
- data/lib/harness/gauge.rb +0 -23
- data/lib/harness/integration/action_controller.rb +0 -9
- data/lib/harness/integration/action_mailer.rb +0 -9
- data/lib/harness/integration/action_view.rb +0 -9
- data/lib/harness/integration/active_model_serializers.rb +0 -9
- data/lib/harness/integration/active_support.rb +0 -9
- data/lib/harness/integration/sidekiq.rb +0 -47
- data/lib/harness/job.rb +0 -23
- data/lib/harness/measurement.rb +0 -43
- data/lib/harness/queues/delayed_job_queue.rb +0 -7
- data/lib/harness/queues/resque_queue.rb +0 -29
- data/lib/harness/queues/sidekiq_queue.rb +0 -31
- data/lib/harness/queues/synchronous_queue.rb +0 -18
- data/lib/harness/railtie.rb +0 -71
- data/lib/harness/tasks.rake +0 -6
- data/test/integration/counters_with_redis_test.rb +0 -67
- data/test/integration/instrumentation_test.rb +0 -50
- data/test/integration/integrations/action_controller_test.rb +0 -51
- data/test/integration/integrations/action_mailer_test.rb +0 -22
- data/test/integration/integrations/action_view_test.rb +0 -32
- data/test/integration/integrations/active_model_serializers_test.rb +0 -22
- data/test/integration/integrations/active_support_test.rb +0 -41
- data/test/integration/integrations/sidekiq_test.rb +0 -54
- data/test/integration/logging_test.rb +0 -17
- data/test/integration/queues/delayed_job_test.rb +0 -59
- data/test/integration/queues/resque_test.rb +0 -24
- data/test/integration/queues/sidekiq_test.rb +0 -34
- data/test/integration/railtie_test.rb +0 -26
- data/test/unit/adapters/librato_adapter_test.rb +0 -169
- data/test/unit/adapters/memory_adapter_test.rb +0 -22
- data/test/unit/adapters/stathat_adapter_test.rb +0 -144
- data/test/unit/adapters/statsd_adapter_test.rb +0 -74
- data/test/unit/counter_test.rb +0 -84
- data/test/unit/gauge_test.rb +0 -93
- data/test/unit/harness_test.rb +0 -39
- data/test/unit/measurement_test.rb +0 -76
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MemoryAdapterTest < MiniTest::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
Harness::MemoryAdapter.counters.clear
|
6
|
-
Harness::MemoryAdapter.gauges.clear
|
7
|
-
|
8
|
-
@adapter = Harness::MemoryAdapter.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_log_gauge_adds_to_gauges
|
12
|
-
@adapter.log_gauge :foo
|
13
|
-
|
14
|
-
assert_includes @adapter.gauges, :foo
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_log_counter_adds_to_counters
|
18
|
-
@adapter.log_counter :bar
|
19
|
-
|
20
|
-
assert_includes @adapter.counters, :bar
|
21
|
-
end
|
22
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'harness/adapters/stathat_adapter'
|
3
|
-
|
4
|
-
class StathatAdapterTest < MiniTest::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@adapter = Harness::StathatAdapter.new
|
7
|
-
|
8
|
-
@gauge = Harness::Gauge.new
|
9
|
-
@gauge.id = "fake-gauge"
|
10
|
-
@gauge.name = "Fake Gauge"
|
11
|
-
@gauge.source = "minitest"
|
12
|
-
@gauge.time = Time.now
|
13
|
-
@gauge.value = "55"
|
14
|
-
|
15
|
-
@counter = Harness::Counter.new
|
16
|
-
@counter.id = "fake-counter"
|
17
|
-
@counter.name = "Fake Counter"
|
18
|
-
@counter.source = "minitest"
|
19
|
-
@counter.time = Time.now
|
20
|
-
@counter.value = "55"
|
21
|
-
@counter.units = :bytes
|
22
|
-
|
23
|
-
Harness::StathatAdapter.config.ezkey = token
|
24
|
-
Harness.config.namespace = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_gauge_is_logged
|
28
|
-
args = {
|
29
|
-
:stat => @gauge.id,
|
30
|
-
:ezkey => token,
|
31
|
-
:value => @gauge.value,
|
32
|
-
}
|
33
|
-
|
34
|
-
expected_request = stub_request(:post, "https://api.stathat.com/ez").
|
35
|
-
with(:body => args, :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
|
36
|
-
to_return(:status => 200)
|
37
|
-
|
38
|
-
assert @adapter.log_gauge(@gauge)
|
39
|
-
assert_requested expected_request
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_gauge_is_logged_with_namespace
|
43
|
-
Harness.config.namespace = :foo
|
44
|
-
|
45
|
-
args = {
|
46
|
-
:stat => "#{@gauge.id}.foo",
|
47
|
-
:ezkey => token,
|
48
|
-
:value => @gauge.value,
|
49
|
-
}
|
50
|
-
|
51
|
-
expected_request = stub_request(:post, "https://api.stathat.com/ez").
|
52
|
-
with(:body => args, :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
|
53
|
-
to_return(:status => 200)
|
54
|
-
|
55
|
-
assert @adapter.log_gauge(@gauge)
|
56
|
-
assert_requested expected_request
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_logging_gauge_raises_an_exception
|
60
|
-
stub_request(:post, %r{stathat}).to_return(:status => 500, :body => "message")
|
61
|
-
|
62
|
-
assert_raises Harness::LoggingError do
|
63
|
-
@adapter.log_gauge @gauge
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_logging_gauge_raises_an_exception_when_id_is_too_long
|
68
|
-
@gauge.id = "f" * 256
|
69
|
-
|
70
|
-
assert_raises Harness::LoggingError do
|
71
|
-
@adapter.log_gauge @gauge
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_logging_gauge_raises_an_exception_when_not_configured
|
76
|
-
Harness::StathatAdapter.config.ezkey = nil
|
77
|
-
|
78
|
-
assert_raises RuntimeError do
|
79
|
-
@adapter.log_gauge @gauge
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_counter_is_logged
|
84
|
-
args = {
|
85
|
-
:stat => @counter.id,
|
86
|
-
:ezkey => token,
|
87
|
-
:count => @counter.value,
|
88
|
-
}
|
89
|
-
|
90
|
-
expected_request = stub_request(:post, "https://api.stathat.com/ez").
|
91
|
-
with(:body => args, :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
|
92
|
-
to_return(:status => 200)
|
93
|
-
|
94
|
-
assert @adapter.log_counter(@counter)
|
95
|
-
assert_requested expected_request
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_counter_is_logged_with_namespace
|
99
|
-
Harness.config.namespace = :foo
|
100
|
-
|
101
|
-
args = {
|
102
|
-
:stat => "#{@counter.id}.foo",
|
103
|
-
:ezkey => token,
|
104
|
-
:count => @counter.value,
|
105
|
-
}
|
106
|
-
|
107
|
-
expected_request = stub_request(:post, "https://api.stathat.com/ez").
|
108
|
-
with(:body => args, :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
|
109
|
-
to_return(:status => 200)
|
110
|
-
|
111
|
-
assert @adapter.log_counter(@counter)
|
112
|
-
assert_requested expected_request
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_logging_counter_raises_an_exception
|
116
|
-
stub_request(:post, %r{stathat}).to_return(:status => 500, :body => "message")
|
117
|
-
|
118
|
-
assert_raises Harness::LoggingError do
|
119
|
-
@adapter.log_counter @counter
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_logging_counter_raises_an_exception_when_not_configured
|
124
|
-
Harness::StathatAdapter.config.ezkey = nil
|
125
|
-
|
126
|
-
assert_raises RuntimeError do
|
127
|
-
@adapter.log_counter @counter
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_logging_counter_raises_an_exception_when_id_is_too_long
|
132
|
-
@counter.id = "f" * 256
|
133
|
-
|
134
|
-
assert_raises Harness::LoggingError do
|
135
|
-
@adapter.log_counter @counter
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
private
|
140
|
-
|
141
|
-
def token
|
142
|
-
'example@example.com'
|
143
|
-
end
|
144
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
require 'harness/adapters/statsd_adapter'
|
4
|
-
|
5
|
-
class StatsdAdapterTest < MiniTest::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@adapter = Harness::StatsdAdapter.new
|
8
|
-
|
9
|
-
@gauge = Harness::Gauge.new
|
10
|
-
@gauge.id = "fake-gauge"
|
11
|
-
@gauge.name = "Fake Gauge"
|
12
|
-
@gauge.source = "minitest"
|
13
|
-
@gauge.time = Time.now
|
14
|
-
@gauge.value = 55
|
15
|
-
|
16
|
-
@counter = Harness::Counter.new
|
17
|
-
@counter.id = "fake-counter"
|
18
|
-
@counter.name = "Fake Counter"
|
19
|
-
@counter.source = "minitest"
|
20
|
-
@counter.time = Time.now
|
21
|
-
@counter.value = 1337
|
22
|
-
@counter.units = :bytes
|
23
|
-
Harness.config.namespace = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_gauge_is_logged
|
27
|
-
mock_backend = MiniTest::Mock.new
|
28
|
-
mock_backend.expect :host, 'foo'
|
29
|
-
mock_backend.expect :port, 'bar'
|
30
|
-
|
31
|
-
Harness::StatsdAdapter.config.backend = mock_backend
|
32
|
-
mock_backend.expect :gauge, true, [String, 55]
|
33
|
-
|
34
|
-
assert @adapter.log_gauge(@gauge)
|
35
|
-
assert mock_backend.verify
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_logging_gauge_raises_an_exception_when_not_configured
|
39
|
-
mock_backend = MiniTest::Mock.new
|
40
|
-
mock_backend.expect :host, nil
|
41
|
-
mock_backend.expect :port, nil
|
42
|
-
|
43
|
-
Harness::StatsdAdapter.config.backend = mock_backend
|
44
|
-
mock_backend.expect :gauge, true, [String, 55]
|
45
|
-
|
46
|
-
assert_raises RuntimeError do
|
47
|
-
@adapter.log_gauge @gauge
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_counter_is_logged
|
52
|
-
mock_backend = MiniTest::Mock.new
|
53
|
-
mock_backend.expect :host, 'foo'
|
54
|
-
mock_backend.expect :port, 'bar'
|
55
|
-
|
56
|
-
Harness::StatsdAdapter.config.backend = mock_backend
|
57
|
-
mock_backend.expect :increment, true, [String, 1337]
|
58
|
-
|
59
|
-
assert @adapter.log_counter(@counter)
|
60
|
-
assert mock_backend.verify
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_logging_counter_raises_an_exception_when_not_configured
|
64
|
-
mock_backend = MiniTest::Mock.new
|
65
|
-
mock_backend.expect :host, nil
|
66
|
-
mock_backend.expect :port, nil
|
67
|
-
|
68
|
-
Harness::StatsdAdapter.config.backend = mock_backend
|
69
|
-
|
70
|
-
assert_raises RuntimeError do
|
71
|
-
@adapter.log_counter @counter
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/test/unit/counter_test.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CounterTest < MiniTest::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@counter = Harness::Counter.new
|
6
|
-
Harness.redis.flushall
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_sets_id_from_event
|
10
|
-
event = ActiveSupport::Notifications::Event.new "name", Time.now, Time.now, nil, {}
|
11
|
-
|
12
|
-
counter = Harness::Counter.from_event event
|
13
|
-
|
14
|
-
assert_equal "name", counter.id
|
15
|
-
end
|
16
|
-
|
17
|
-
def tests_sets_source_from_event_payload
|
18
|
-
event = ActiveSupport::Notifications::Event.new "name", Time.now, Time.now, nil, :counter => { :source => 'box1' }
|
19
|
-
|
20
|
-
counter = Harness::Counter.from_event event
|
21
|
-
|
22
|
-
assert_equal "box1", counter.source
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_sets_value_from_event_payload
|
26
|
-
base = Time.now
|
27
|
-
|
28
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => {:value => 5 }
|
29
|
-
|
30
|
-
counter = Harness::Counter.from_event event
|
31
|
-
|
32
|
-
assert_equal 5, counter.value
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_sets_value_from_event_payload_with_number
|
36
|
-
base = Time.now
|
37
|
-
|
38
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => 5
|
39
|
-
|
40
|
-
counter = Harness::Counter.from_event event
|
41
|
-
|
42
|
-
assert_equal 5, counter.value
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_sets_name_from_event
|
46
|
-
base = Time.now
|
47
|
-
|
48
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => { :name => 'foo' }
|
49
|
-
|
50
|
-
counter = Harness::Counter.from_event event
|
51
|
-
|
52
|
-
assert_equal 'foo', counter.name
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_sets_id_from_payload_if_symbol
|
56
|
-
base = Time.now
|
57
|
-
|
58
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => :foo
|
59
|
-
|
60
|
-
counter = Harness::Counter.from_event event
|
61
|
-
|
62
|
-
assert_equal 'foo', counter.id
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_sets_id_from_payload_if_string
|
66
|
-
base = Time.now
|
67
|
-
|
68
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => 'foo'
|
69
|
-
|
70
|
-
counter = Harness::Counter.from_event event
|
71
|
-
|
72
|
-
assert_equal 'foo', counter.id
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_sets_the_period_from_the_event
|
76
|
-
base = Time.now
|
77
|
-
|
78
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :counter => {period: 30}
|
79
|
-
|
80
|
-
counter = Harness::Counter.from_event event
|
81
|
-
|
82
|
-
assert_equal 30, counter.period
|
83
|
-
end
|
84
|
-
end
|
data/test/unit/gauge_test.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class GaugeTest < MiniTest::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@gauge = Harness::Gauge.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_initializes_units
|
9
|
-
assert_equal :ms, @gauge.units
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_sets_name_id_event
|
13
|
-
event = ActiveSupport::Notifications::Event.new "name", Time.now, Time.now, nil, {}
|
14
|
-
|
15
|
-
gauge = Harness::Gauge.from_event event
|
16
|
-
|
17
|
-
assert_equal "name", gauge.id
|
18
|
-
end
|
19
|
-
|
20
|
-
def tests_sets_source_from_event_payload
|
21
|
-
event = ActiveSupport::Notifications::Event.new "name", Time.now, Time.now, nil, :gauge => { :source => 'box1' }
|
22
|
-
|
23
|
-
gauge = Harness::Gauge.from_event event
|
24
|
-
|
25
|
-
assert_equal "box1", gauge.source
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_sets_duration_from_event
|
29
|
-
base = Time.now
|
30
|
-
|
31
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, {}
|
32
|
-
|
33
|
-
gauge = Harness::Gauge.from_event event
|
34
|
-
|
35
|
-
assert_in_delta 1000, 0.01, gauge.value
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_sets_name_from_event
|
39
|
-
base = Time.now
|
40
|
-
|
41
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :gauge => { :name => 'foo' }
|
42
|
-
|
43
|
-
gauge = Harness::Gauge.from_event event
|
44
|
-
|
45
|
-
assert_equal 'foo', gauge.name
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_sets_id_from_payload_if_symbol
|
49
|
-
base = Time.now
|
50
|
-
|
51
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :gauge => :foo
|
52
|
-
|
53
|
-
gauge = Harness::Gauge.from_event event
|
54
|
-
|
55
|
-
assert_equal 'foo', gauge.id
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_sets_id_from_payload_if_string
|
59
|
-
base = Time.now
|
60
|
-
|
61
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :gauge => 'foo'
|
62
|
-
|
63
|
-
gauge = Harness::Gauge.from_event event
|
64
|
-
|
65
|
-
assert_equal 'foo', gauge.id
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_sets_value_from_payload_if_number
|
69
|
-
base = Time.now
|
70
|
-
|
71
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :gauge => {value: 42}
|
72
|
-
|
73
|
-
gauge = Harness::Gauge.from_event event
|
74
|
-
|
75
|
-
assert_equal 42, gauge.value
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_sets_the_period_from_the_event
|
79
|
-
base = Time.now
|
80
|
-
|
81
|
-
event = ActiveSupport::Notifications::Event.new "name", base - 1, Time.now, nil, :gauge => {period: 30}
|
82
|
-
|
83
|
-
gauge = Harness::Gauge.from_event event
|
84
|
-
|
85
|
-
assert_equal 30, gauge.period
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_initializes_time_if_not_set
|
89
|
-
gauge = Harness::Gauge.new
|
90
|
-
|
91
|
-
assert gauge.time
|
92
|
-
end
|
93
|
-
end
|
data/test/unit/harness_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class HarnessModuleTest < MiniTest::Unit::TestCase
|
4
|
-
def test_can_set_the_adapter_with_a_symbol
|
5
|
-
Harness.config.adapter = :memory
|
6
|
-
|
7
|
-
assert_kind_of Harness::MemoryAdapter, Harness.config.adapter
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_can_set_the_adapter_with_an_adapter_instance
|
11
|
-
Harness.config.adapter = Harness::MemoryAdapter.new
|
12
|
-
|
13
|
-
assert_kind_of Harness::MemoryAdapter, Harness.config.adapter
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_can_set_the_queue_with_a_symbol
|
17
|
-
Harness.config.queue = :synchronous
|
18
|
-
|
19
|
-
assert_kind_of Harness::SynchronousQueue, Harness.config.queue
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_can_set_the_queue_with_a_queue_instance
|
23
|
-
Harness.config.queue = Harness::SynchronousQueue.new
|
24
|
-
|
25
|
-
assert_kind_of Harness::SynchronousQueue, Harness.config.queue
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_uses_method_missing_to_configure_adapters
|
29
|
-
Harness.config.librato.email = 'foo'
|
30
|
-
|
31
|
-
assert_equal 'foo', Harness.config.librato.email
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_blows_up_when_calling_an_unknown_adapter
|
35
|
-
assert_raises NoMethodError do
|
36
|
-
Harness.config.foo_bar
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|