newrelic_plugin 1.0.3 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +44 -1
- data/README.md +11 -5
- data/lib/newrelic_platform_binding.rb +11 -0
- data/lib/newrelic_platform_binding/component.rb +27 -0
- data/lib/newrelic_platform_binding/config.rb +39 -0
- data/lib/newrelic_platform_binding/connection.rb +86 -0
- data/lib/newrelic_platform_binding/context.rb +49 -0
- data/lib/newrelic_platform_binding/logger.rb +40 -0
- data/lib/newrelic_platform_binding/metric.rb +49 -0
- data/lib/newrelic_platform_binding/request.rb +111 -0
- data/lib/newrelic_plugin.rb +1 -4
- data/lib/newrelic_plugin/agent.rb +14 -21
- data/lib/newrelic_plugin/config.rb +2 -1
- data/lib/newrelic_plugin/processors/rate_processor.rb +3 -3
- data/lib/newrelic_plugin/run.rb +97 -54
- data/lib/newrelic_plugin/setup.rb +10 -19
- data/lib/newrelic_plugin/version.rb +1 -1
- data/newrelic_plugin.gemspec +4 -4
- data/test/newrelic_platform_binding/component_test.rb +16 -0
- data/test/newrelic_platform_binding/config_test.rb +89 -0
- data/test/newrelic_platform_binding/connection_test.rb +67 -0
- data/test/newrelic_platform_binding/context_test.rb +35 -0
- data/test/newrelic_platform_binding/logger_test.rb +33 -0
- data/test/newrelic_platform_binding/metric_test.rb +97 -0
- data/test/newrelic_platform_binding/request_test.rb +127 -0
- data/test/newrelic_plugin/agent_test.rb +127 -0
- data/test/newrelic_plugin/run_test.rb +77 -0
- data/test/newrelic_plugin/setup_test.rb +17 -0
- data/test/test_helper.rb +11 -4
- metadata +59 -17
- data/lib/newrelic_plugin/data_collector.rb +0 -67
- data/lib/newrelic_plugin/logger.rb +0 -19
- data/lib/newrelic_plugin/new_relic_connection.rb +0 -67
- data/lib/newrelic_plugin/new_relic_message.rb +0 -173
- data/test/agent_test.rb +0 -153
- data/test/logger_test.rb +0 -21
- data/test/manual_test.rb +0 -20
- data/test/new_relic_message_test.rb +0 -76
data/test/agent_test.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AgentTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@agent_info = {:ident => 1}
|
7
|
-
@agent_class = TestingAgent::Agent.dup
|
8
|
-
end
|
9
|
-
|
10
|
-
context :agent_guid do
|
11
|
-
should 'set guid' do
|
12
|
-
@agent_class.class_eval do
|
13
|
-
agent_guid '12234'
|
14
|
-
end
|
15
|
-
agent = @agent_class.new('test agent', @agent_info)
|
16
|
-
assert_equal '12234', agent.class.guid
|
17
|
-
end
|
18
|
-
|
19
|
-
should 'raise RuntimeError if guid is set to nil' do
|
20
|
-
assert_raise RuntimeError do
|
21
|
-
@agent_class.class_eval do
|
22
|
-
agent_guid nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'raise RuntimeError if guid is set to empty string' do
|
28
|
-
assert_raise RuntimeError do
|
29
|
-
@agent_class.class_eval do
|
30
|
-
agent_guid ""
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context :guid do
|
37
|
-
should "return instance @guid" do
|
38
|
-
agent = @agent_class.new('test agent', @agent_info)
|
39
|
-
agent.instance_variable_set(:@guid, 'test')
|
40
|
-
assert_equal 'test', agent.guid
|
41
|
-
end
|
42
|
-
|
43
|
-
should "return class guid" do
|
44
|
-
@agent_class.class_eval do
|
45
|
-
@guid = '123'
|
46
|
-
end
|
47
|
-
agent = @agent_class.new('test agent', @agent_info)
|
48
|
-
assert_equal '123', agent.guid
|
49
|
-
end
|
50
|
-
|
51
|
-
should "raise error if guid is not set properly" do
|
52
|
-
@agent_class.class_eval do
|
53
|
-
@guid = 'guid'
|
54
|
-
end
|
55
|
-
#agent = TestingAgent::Agent.new('test agent', @agent_info)
|
56
|
-
# refactor the code this is hitting before finishing this test
|
57
|
-
# this does not test well
|
58
|
-
#assert_raise RuntimeError, 'Did not set GUID' do
|
59
|
-
# agent.guid
|
60
|
-
#end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context :agent_version do
|
65
|
-
should 'set version' do
|
66
|
-
@agent_class.class_eval do
|
67
|
-
agent_version '0.0.1'
|
68
|
-
end
|
69
|
-
agent = @agent_class.new('test agent', @agent_info)
|
70
|
-
assert_equal '0.0.1', agent.class.version
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context :version do
|
75
|
-
should 'return class @version' do
|
76
|
-
@agent_class.class_eval do
|
77
|
-
@version = '1.2.3'
|
78
|
-
end
|
79
|
-
agent = @agent_class.new('test agent', @agent_info)
|
80
|
-
assert_equal '1.2.3', agent.version
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context :agent_human_labels do
|
85
|
-
setup do
|
86
|
-
@agent_class.class_eval do
|
87
|
-
agent_human_labels('Testing Agent') { 'Testing Agent block' }
|
88
|
-
end
|
89
|
-
@agent = @agent_class.new('test agent', @agent_info)
|
90
|
-
end
|
91
|
-
should 'set class @label' do
|
92
|
-
assert_equal 'Testing Agent', @agent.class.label
|
93
|
-
end
|
94
|
-
should 'set instance label proc' do
|
95
|
-
assert_equal "Testing Agent block", @agent.class.instance_label_proc.call
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context :no_config_required do
|
100
|
-
should 'set class @no_config_required' do
|
101
|
-
@agent_class.class_eval do
|
102
|
-
agent_human_labels('Testing Agent') { 'Testing Agent block' }
|
103
|
-
end
|
104
|
-
agent = @agent_class.new('test agent', @agent_info)
|
105
|
-
assert_equal true, agent.class.no_config_required
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context :config_required? do
|
110
|
-
should 'return false when class @no_config_required true' do
|
111
|
-
@agent_class.class_eval do
|
112
|
-
@no_config_required = true
|
113
|
-
end
|
114
|
-
agent = @agent_class.new('test agent', @agent_info)
|
115
|
-
assert_equal false, agent.class.config_required?
|
116
|
-
end
|
117
|
-
should 'return true when class @no_config_required false' do
|
118
|
-
@agent_class.class_eval do
|
119
|
-
@no_config_required = false
|
120
|
-
end
|
121
|
-
agent = @agent_class.new('test agent', @agent_info)
|
122
|
-
assert_equal true, agent.class.config_required?
|
123
|
-
end
|
124
|
-
should 'return true when class @no_config_required is not set' do
|
125
|
-
@agent_class.class_eval do
|
126
|
-
end
|
127
|
-
agent = @agent_class.new('test agent', @agent_info)
|
128
|
-
assert_equal true, agent.class.config_required?
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context :agent_config_options do
|
133
|
-
should 'set class @config_options_list if empty' do
|
134
|
-
@agent_class.class_eval do
|
135
|
-
agent_config_options(:test, 'foo', 'bar')
|
136
|
-
end
|
137
|
-
@agent = @agent_class.new('test agent', @agent_info)
|
138
|
-
assert_equal [:test, 'foo', 'bar'], @agent.class.config_options_list
|
139
|
-
end
|
140
|
-
|
141
|
-
should 'add to existing @config_options_list' do
|
142
|
-
@agent_class.class_eval do
|
143
|
-
attr_accessor 'foobar'
|
144
|
-
@config_options_list = ['foobar']
|
145
|
-
agent_config_options(:test, 'foo', 'bar')
|
146
|
-
end
|
147
|
-
|
148
|
-
@agent = @agent_class.new('test agent', @agent_info)
|
149
|
-
assert_equal ['foobar', :test, 'foo', 'bar'], @agent.class.config_options_list
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
data/test/logger_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class LoggerTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context 'self.write' do
|
6
|
-
should 'build expected log string and output it' do
|
7
|
-
NewRelic::Plugin::Logger.expects(:timestamp).returns('foobar')
|
8
|
-
NewRelic::Plugin::Logger.expects(:output).with('[foobar] test')
|
9
|
-
NewRelic::Plugin::Logger.write('test')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'self.timestamp' do
|
14
|
-
should 'format timestamp in iso8601' do
|
15
|
-
test_time = Time.new(2013, 6, 24, 0, 0, 0, "+00:00")
|
16
|
-
Time.expects(:now).twice.returns(test_time)
|
17
|
-
assert_equal '2013-06-24 00:00:00 UTC', NewRelic::Plugin::Logger.timestamp
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
data/test/manual_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
new_relic_message = NewRelic::Plugin::NewRelicMessage.new('fake connection', 'manual curl test', 'manual-test-guid', 'version', 60)
|
5
|
-
new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
6
|
-
new_relic_message.add_stat_fullname('other metric', 2, 2, :min => 2, :max => 2, :sum_of_squares => 8)
|
7
|
-
|
8
|
-
puts <<-EOF
|
9
|
-
########################################################
|
10
|
-
Manual testing -- output curl command with payload
|
11
|
-
########################################################
|
12
|
-
|
13
|
-
curl -vi http://collector.newrelic.com/platform/v1/metrics \
|
14
|
-
-H "X-License-Key: ADD_LICENSE_KEY" \
|
15
|
-
-H "Content-Type: application/json" \
|
16
|
-
-H "Accept: application/json" \
|
17
|
-
-X POST -d \'#{new_relic_message.send(:build_request_payload)}\'
|
18
|
-
|
19
|
-
########################################################
|
20
|
-
EOF
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class NewRelicMessageTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@new_relic_message = NewRelic::Plugin::NewRelicMessage.new('foo', 'test component name', 'fake guid', 'version', 60)
|
6
|
-
end
|
7
|
-
|
8
|
-
context 'initialization' do
|
9
|
-
should 'start with an empty metrics array' do
|
10
|
-
assert_equal [], @new_relic_message.instance_variable_get(:@metrics)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context :add_stat_fullname do
|
15
|
-
setup do
|
16
|
-
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
17
|
-
end
|
18
|
-
should '@metric array should have 1 metric' do
|
19
|
-
assert_equal 1, @new_relic_message.metrics.size
|
20
|
-
end
|
21
|
-
|
22
|
-
should '@metric array should include expected data' do
|
23
|
-
stored_metric = {
|
24
|
-
:metric_name => 'test metric',
|
25
|
-
:count => 2,
|
26
|
-
:total => 2,
|
27
|
-
:min => 1,
|
28
|
-
:max => 3,
|
29
|
-
:sum_of_squares => 10
|
30
|
-
}
|
31
|
-
assert_equal stored_metric, @new_relic_message.metrics.first
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context :build_metrics_hash do
|
36
|
-
setup do
|
37
|
-
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
38
|
-
@new_relic_message.add_stat_fullname('other metric', 2, 2, :min => 2, :max => 2, :sum_of_squares => 8)
|
39
|
-
end
|
40
|
-
|
41
|
-
should 'build expected metric hash' do
|
42
|
-
metric_hash = {
|
43
|
-
'test metric' => [2,2,3,1,10],
|
44
|
-
'other metric' => [2,2,2,2,8]
|
45
|
-
}
|
46
|
-
assert_equal metric_hash, @new_relic_message.send(:build_metrics_hash)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context :build_request_payload do
|
51
|
-
setup do
|
52
|
-
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
53
|
-
end
|
54
|
-
|
55
|
-
should 'build expected request payload' do
|
56
|
-
payload = {
|
57
|
-
'agent' => {
|
58
|
-
'name' => 'test component name',
|
59
|
-
'version' => 'version',
|
60
|
-
'host' => ''
|
61
|
-
},
|
62
|
-
'components' => [
|
63
|
-
{
|
64
|
-
'name' => 'test component name',
|
65
|
-
'guid' => 'fake guid',
|
66
|
-
'duration' => 60,
|
67
|
-
'metrics' => @new_relic_message.send(:build_metrics_hash)
|
68
|
-
}
|
69
|
-
]
|
70
|
-
}
|
71
|
-
|
72
|
-
assert_equal payload.to_json, @new_relic_message.send(:build_request_payload)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|