appsignal 0.11.18 → 0.12.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG.md +4 -38
- data/Rakefile +14 -6
- data/appsignal.gemspec +3 -1
- data/benchmark.rake +12 -16
- data/ext/appsignal_extension.c +183 -0
- data/ext/extconf.rb +39 -0
- data/gemfiles/capistrano2.gemfile +0 -1
- data/gemfiles/capistrano3.gemfile +0 -1
- data/gemfiles/rails-4.2.gemfile +1 -1
- data/lib/appsignal.rb +23 -61
- data/lib/appsignal/capistrano.rb +1 -2
- data/lib/appsignal/config.rb +13 -1
- data/lib/appsignal/event_formatter.rb +67 -0
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +23 -0
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +74 -0
- data/lib/appsignal/event_formatter/moped/query_formatter.rb +80 -0
- data/lib/appsignal/event_formatter/net_http/request_formatter.rb +13 -0
- data/lib/appsignal/instrumentations/net_http.rb +6 -4
- data/lib/appsignal/integrations/resque.rb +2 -10
- data/lib/appsignal/integrations/sidekiq.rb +2 -2
- data/lib/appsignal/integrations/sinatra.rb +1 -0
- data/lib/appsignal/js_exception_transaction.rb +44 -28
- data/lib/appsignal/marker.rb +11 -13
- data/lib/appsignal/params_sanitizer.rb +5 -8
- data/lib/appsignal/rack/instrumentation.rb +2 -0
- data/lib/appsignal/rack/js_exception_catcher.rb +1 -0
- data/lib/appsignal/rack/listener.rb +1 -1
- data/lib/appsignal/rack/sinatra_instrumentation.rb +2 -12
- data/lib/appsignal/subscriber.rb +59 -0
- data/lib/appsignal/transaction.rb +117 -174
- data/lib/appsignal/transmitter.rb +8 -37
- data/lib/appsignal/version.rb +2 -1
- data/spec/lib/appsignal/config_spec.rb +25 -4
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +42 -0
- data/spec/lib/appsignal/{aggregator/middleware/active_record_sanitizer_spec.rb → event_formatter/active_record/sql_formatter_spec.rb} +61 -61
- data/spec/lib/appsignal/{event/moped_event_spec.rb → event_formatter/moped/query_formatter_spec.rb} +32 -78
- data/spec/lib/appsignal/event_formatter/net_http/request_formatter_spec.rb +26 -0
- data/spec/lib/appsignal/event_formatter_spec.rb +102 -0
- data/spec/lib/appsignal/extension_spec.rb +75 -0
- data/spec/lib/appsignal/instrumentations/net_http_spec.rb +20 -4
- data/spec/lib/appsignal/integrations/delayed_job_spec.rb +3 -2
- data/spec/lib/appsignal/integrations/rails_spec.rb +0 -7
- data/spec/lib/appsignal/integrations/resque_spec.rb +51 -55
- data/spec/lib/appsignal/integrations/sequel_spec.rb +8 -3
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +4 -21
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -6
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +57 -60
- data/spec/lib/appsignal/params_sanitizer_spec.rb +11 -27
- data/spec/lib/appsignal/rack/listener_spec.rb +6 -6
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +2 -43
- data/spec/lib/appsignal/subscriber_spec.rb +162 -0
- data/spec/lib/appsignal/transaction_spec.rb +283 -615
- data/spec/lib/appsignal/transmitter_spec.rb +3 -32
- data/spec/lib/appsignal_spec.rb +41 -90
- data/spec/lib/generators/appsignal/appsignal_generator_spec.rb +0 -17
- data/spec/spec_helper.rb +18 -22
- data/spec/support/helpers/notification_helpers.rb +1 -1
- data/spec/support/helpers/time_helpers.rb +11 -0
- data/spec/support/helpers/transaction_helpers.rb +6 -18
- data/spec/support/project_fixture/config/appsignal.yml +1 -2
- metadata +68 -78
- checksums.yaml +0 -7
- data/gemfiles/padrino-0.13.gemfile +0 -7
- data/gemfiles/resque.gemfile +0 -5
- data/lib/appsignal/agent.rb +0 -217
- data/lib/appsignal/aggregator.rb +0 -67
- data/lib/appsignal/aggregator/middleware.rb +0 -4
- data/lib/appsignal/aggregator/middleware/action_view_sanitizer.rb +0 -23
- data/lib/appsignal/aggregator/middleware/active_record_sanitizer.rb +0 -65
- data/lib/appsignal/aggregator/middleware/chain.rb +0 -101
- data/lib/appsignal/aggregator/middleware/delete_blanks.rb +0 -16
- data/lib/appsignal/aggregator/post_processor.rb +0 -32
- data/lib/appsignal/event.rb +0 -20
- data/lib/appsignal/event/moped_event.rb +0 -90
- data/lib/appsignal/integrations/padrino.rb +0 -64
- data/lib/appsignal/integrations/passenger.rb +0 -13
- data/lib/appsignal/integrations/rake.rb +0 -29
- data/lib/appsignal/integrations/unicorn.rb +0 -25
- data/lib/appsignal/ipc.rb +0 -68
- data/lib/appsignal/transaction/formatter.rb +0 -85
- data/lib/appsignal/transaction/params_sanitizer.rb +0 -4
- data/lib/appsignal/zipped_payload.rb +0 -37
- data/spec/lib/appsignal/agent_spec.rb +0 -592
- data/spec/lib/appsignal/aggregator/middleware/action_view_sanitizer_spec.rb +0 -44
- data/spec/lib/appsignal/aggregator/middleware/chain_spec.rb +0 -168
- data/spec/lib/appsignal/aggregator/middleware/delete_blanks_spec.rb +0 -37
- data/spec/lib/appsignal/aggregator/post_processor_spec.rb +0 -99
- data/spec/lib/appsignal/aggregator_spec.rb +0 -186
- data/spec/lib/appsignal/event_spec.rb +0 -48
- data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -171
- data/spec/lib/appsignal/integrations/passenger_spec.rb +0 -22
- data/spec/lib/appsignal/integrations/rake_spec.rb +0 -92
- data/spec/lib/appsignal/integrations/unicorn_spec.rb +0 -48
- data/spec/lib/appsignal/ipc_spec.rb +0 -128
- data/spec/lib/appsignal/transaction/formatter_spec.rb +0 -247
- data/spec/lib/appsignal/zipped_payload_spec.rb +0 -42
@@ -1,37 +0,0 @@
|
|
1
|
-
module Appsignal
|
2
|
-
class ZippedPayload
|
3
|
-
attr_reader :body
|
4
|
-
|
5
|
-
def initialize(given_body)
|
6
|
-
@body = Zlib::Deflate.deflate(
|
7
|
-
Appsignal::ZippedPayload.json_generate(given_body),
|
8
|
-
Zlib::BEST_SPEED
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def self.json_generate(given_body)
|
15
|
-
JSON.generate(jsonify(given_body))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.jsonify(value)
|
19
|
-
case value
|
20
|
-
when String
|
21
|
-
value.encode(
|
22
|
-
'utf-8',
|
23
|
-
:invalid => :replace,
|
24
|
-
:undef => :replace
|
25
|
-
)
|
26
|
-
when Numeric, NilClass, TrueClass, FalseClass
|
27
|
-
value
|
28
|
-
when Hash
|
29
|
-
Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
|
30
|
-
when Array
|
31
|
-
value.map { |v| jsonify(v) }
|
32
|
-
else
|
33
|
-
jsonify(value.to_s)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,592 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class PostProcessingException < Exception
|
4
|
-
end
|
5
|
-
|
6
|
-
describe Appsignal::Agent do
|
7
|
-
before :all do
|
8
|
-
start_agent
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:transaction) { regular_transaction }
|
12
|
-
|
13
|
-
its(:active?) { should be_true }
|
14
|
-
|
15
|
-
context "pid" do
|
16
|
-
its(:master_pid) { should == Process.pid }
|
17
|
-
its(:pid) { should == Process.pid }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#sleep_time" do
|
21
|
-
subject { Appsignal::Agent.new.sleep_time }
|
22
|
-
|
23
|
-
it { should == 60 }
|
24
|
-
|
25
|
-
context "for development" do
|
26
|
-
before do
|
27
|
-
Appsignal.config.stub(:env => 'development')
|
28
|
-
end
|
29
|
-
|
30
|
-
it { should == 10 }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#start_thread" do
|
35
|
-
before do
|
36
|
-
subject.thread = nil
|
37
|
-
subject.stub(:sleep_time => 0.1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should truncate the aggregator queue" do
|
41
|
-
subject.should_receive(:truncate_aggregator_queue).at_least(1).times
|
42
|
-
subject.start_thread
|
43
|
-
sleep 1
|
44
|
-
end
|
45
|
-
|
46
|
-
context "without transactions" do
|
47
|
-
it "should start and run a background thread" do
|
48
|
-
subject.should_not_receive(:send_queue)
|
49
|
-
|
50
|
-
subject.start_thread
|
51
|
-
|
52
|
-
subject.thread.should be_a(Thread)
|
53
|
-
subject.thread.should be_alive
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "with transactions" do
|
58
|
-
before do
|
59
|
-
subject.stub(:aggregator => double(:has_transactions? => true))
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should send the queue and sleep" do
|
63
|
-
subject.should_receive(:send_queue).at_least(:twice)
|
64
|
-
|
65
|
-
subject.start_thread
|
66
|
-
sleep 2
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with items in the aggregator queue" do
|
71
|
-
before do
|
72
|
-
subject.aggregator_queue.stub(:any? => true)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should send the queue and sleep" do
|
76
|
-
subject.should_receive(:send_queue).at_least(:twice)
|
77
|
-
|
78
|
-
subject.start_thread
|
79
|
-
sleep 2
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "when an exception occurs in the thread" do
|
84
|
-
before do
|
85
|
-
aggregator = double
|
86
|
-
aggregator.stub(:has_transactions?).and_raise(
|
87
|
-
RuntimeError.new('error')
|
88
|
-
)
|
89
|
-
subject.stub(:aggregator => aggregator)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should log the error" do
|
93
|
-
Appsignal.logger.should_receive(:error).
|
94
|
-
with(kind_of(String)).
|
95
|
-
once
|
96
|
-
|
97
|
-
subject.start_thread
|
98
|
-
sleep 1
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "with revision" do
|
103
|
-
around do |sample|
|
104
|
-
ENV['APP_REVISION'] = 'abc'
|
105
|
-
sample.run
|
106
|
-
ENV['APP_REVISION'] = nil
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should set the revision" do
|
110
|
-
subject.start_thread
|
111
|
-
expect( subject.revision ).to eql 'abc'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "#restart_thread" do
|
117
|
-
it "should stop and start the thread" do
|
118
|
-
subject.should_receive(:stop_thread)
|
119
|
-
subject.should_receive(:start_thread)
|
120
|
-
end
|
121
|
-
|
122
|
-
after { subject.restart_thread }
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "#stop_thread" do
|
126
|
-
context "if there is no thread" do
|
127
|
-
before { subject.thread = nil }
|
128
|
-
|
129
|
-
it "should not do anything" do
|
130
|
-
Thread.should_not_receive(:kill)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context "if there is an inactive thread" do
|
135
|
-
before do
|
136
|
-
Thread.kill(subject.thread)
|
137
|
-
sleep 0.1 # We need to wait for the thread to exit
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should start a thread" do
|
141
|
-
Thread.should_not_receive(:kill)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "if there is an active thread" do
|
146
|
-
it "should kill the current thread " do
|
147
|
-
Thread.should_receive(:kill)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
after { subject.stop_thread }
|
152
|
-
end
|
153
|
-
|
154
|
-
describe "#subscribe" do
|
155
|
-
it "should have set the appsignal subscriber" do
|
156
|
-
if defined? ActiveSupport::Notifications::Fanout::Subscribers::Timed
|
157
|
-
# ActiveSupport 4
|
158
|
-
subject.subscriber.should be_a ActiveSupport::Notifications::Fanout::Subscribers::Timed
|
159
|
-
else
|
160
|
-
# ActiveSupport 3
|
161
|
-
subject.subscriber.should be_a ActiveSupport::Notifications::Fanout::Subscriber
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "handling events" do
|
166
|
-
before :each do
|
167
|
-
# Unsubscribe previous notification subscribers
|
168
|
-
ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers).
|
169
|
-
reject { |sub| sub.instance_variable_get(:@pattern).is_a? String }.
|
170
|
-
each { |sub| ActiveSupport::Notifications.unsubscribe(sub) }
|
171
|
-
# And re-subscribe with just one subscriber
|
172
|
-
Appsignal.agent.subscribe
|
173
|
-
|
174
|
-
Appsignal::Transaction.create('123', {})
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should should not listen to events that start with a bang" do
|
178
|
-
Appsignal::Transaction.current.should_not_receive(:add_event)
|
179
|
-
|
180
|
-
ActiveSupport::Notifications.instrument '!render_template'
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should ignore events that do not confirm to the event spec" do
|
184
|
-
Appsignal::Transaction.current.should_not_receive(:add_event)
|
185
|
-
|
186
|
-
ActiveSupport::Notifications.publish 'borked', 'foo'
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should add a normal event" do
|
190
|
-
Appsignal::Transaction.current.should_not_receive(:set_process_action_event)
|
191
|
-
Appsignal::Transaction.current.should_receive(:add_event).with(
|
192
|
-
kind_of(ActiveSupport::Notifications::Event)
|
193
|
-
).at_least(:once)
|
194
|
-
|
195
|
-
ActiveSupport::Notifications.instrument 'render_template'
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should add and set a process action event" do
|
199
|
-
Appsignal::Transaction.current.should_receive(:set_process_action_event).with(
|
200
|
-
kind_of(ActiveSupport::Notifications::Event)
|
201
|
-
).at_least(:once)
|
202
|
-
Appsignal::Transaction.current.should_receive(:add_event).with(
|
203
|
-
kind_of(ActiveSupport::Notifications::Event)
|
204
|
-
).at_least(:once)
|
205
|
-
|
206
|
-
ActiveSupport::Notifications.instrument 'process_action.rack'
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should add and set a perform job event" do
|
210
|
-
Appsignal::Transaction.current.should_receive(:set_perform_job_event).with(
|
211
|
-
kind_of(ActiveSupport::Notifications::Event)
|
212
|
-
).at_least(:once)
|
213
|
-
Appsignal::Transaction.current.should_receive(:add_event).with(
|
214
|
-
kind_of(ActiveSupport::Notifications::Event)
|
215
|
-
).at_least(:once)
|
216
|
-
|
217
|
-
ActiveSupport::Notifications.instrument 'perform_job.processor'
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe "#unsubscribe" do
|
222
|
-
before :each do
|
223
|
-
Appsignal.agent.unsubscribe
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should not have a subscriber" do
|
227
|
-
Appsignal.agent.subscriber.should be_nil
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should add a normal event" do
|
231
|
-
Appsignal::Transaction.current.should_not_receive(:add_event)
|
232
|
-
|
233
|
-
ActiveSupport::Notifications.instrument 'moo'
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe "#resubscribe" do
|
239
|
-
it "should stop and start the thread" do
|
240
|
-
subject.should_receive(:unsubscribe)
|
241
|
-
subject.should_receive(:subscribe)
|
242
|
-
end
|
243
|
-
|
244
|
-
after { subject.resubscribe }
|
245
|
-
end
|
246
|
-
|
247
|
-
describe "#enqueue" do
|
248
|
-
let(:transaction) { double(:action => 'test#test', :request_id => 'id') }
|
249
|
-
subject { Appsignal.agent }
|
250
|
-
|
251
|
-
it "forwards to the aggregator" do
|
252
|
-
subject.aggregator.should respond_to(:add)
|
253
|
-
subject.aggregator.should_receive(:add).with(transaction)
|
254
|
-
subject.should_not_receive(:forked!)
|
255
|
-
end
|
256
|
-
|
257
|
-
context "if we have been forked" do
|
258
|
-
before { Process.stub(:pid => 9000000002) }
|
259
|
-
|
260
|
-
it "should call forked!" do
|
261
|
-
subject.aggregator.should_receive(:add).with(transaction)
|
262
|
-
subject.should_receive(:forked!)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
context "with ignored action" do
|
267
|
-
before { Appsignal.stub(:is_ignored_action? => true) }
|
268
|
-
|
269
|
-
it "should not add item to queue" do
|
270
|
-
subject.aggregator.should_not_receive(:add)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
after { subject.enqueue(transaction) }
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "#send_queue" do
|
278
|
-
let(:zipped_payload) { double(:body => :zip) }
|
279
|
-
|
280
|
-
context "with something in the aggregator" do
|
281
|
-
before do
|
282
|
-
subject.aggregator.stub(:has_transactions? => true)
|
283
|
-
end
|
284
|
-
|
285
|
-
it "adds Zipped Payload to queue" do
|
286
|
-
subject.aggregator.stub(:post_processed_queue! => :foo)
|
287
|
-
|
288
|
-
Appsignal::ZippedPayload
|
289
|
-
.should_receive(:new)
|
290
|
-
.with(:foo)
|
291
|
-
.and_return(zipped_payload)
|
292
|
-
|
293
|
-
subject.should_receive(:add_to_aggregator_queue).with(zipped_payload)
|
294
|
-
end
|
295
|
-
|
296
|
-
it "sends aggregators" do
|
297
|
-
subject.should_receive(:send_aggregators)
|
298
|
-
end
|
299
|
-
|
300
|
-
it "handle exceptions in post processing" do
|
301
|
-
subject.aggregator.stub(:post_processed_queue!).and_raise(
|
302
|
-
PostProcessingException.new('Message')
|
303
|
-
)
|
304
|
-
|
305
|
-
Appsignal.logger.should_receive(:error).
|
306
|
-
with(kind_of(String)).
|
307
|
-
once
|
308
|
-
end
|
309
|
-
|
310
|
-
it "handles exceptions in transmit" do
|
311
|
-
subject.stub(:send_aggregators).and_raise(
|
312
|
-
Exception.new('Message')
|
313
|
-
)
|
314
|
-
|
315
|
-
Appsignal.logger.should_receive(:error).
|
316
|
-
with(kind_of(String)).
|
317
|
-
once
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
context "with something in the aggregator queue" do
|
322
|
-
before do
|
323
|
-
subject.aggregator_queue.stub(:any? => true)
|
324
|
-
end
|
325
|
-
|
326
|
-
it "sends aggregators" do
|
327
|
-
subject.should_receive(:send_aggregators)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
context "with empty aggregator and aggregator queue" do
|
332
|
-
it "does not send aggregators" do
|
333
|
-
subject.should_not_receive(:send_aggregators)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
after { subject.send_queue }
|
338
|
-
end
|
339
|
-
|
340
|
-
describe "#send_aggregators" do
|
341
|
-
let(:aggregator_hash) { double }
|
342
|
-
before { subject.add_to_aggregator_queue(aggregator_hash) }
|
343
|
-
|
344
|
-
context "sending aggreagotor hashes" do
|
345
|
-
it "sends each item in the aggregators_to_be_sent array" do
|
346
|
-
subject.transmitter.should_receive(:transmit).with(aggregator_hash)
|
347
|
-
end
|
348
|
-
|
349
|
-
it "handles the return code" do
|
350
|
-
subject.transmitter.stub(:transmit => '200')
|
351
|
-
subject.should_receive(:handle_result).with('200')
|
352
|
-
end
|
353
|
-
|
354
|
-
after { subject.send_aggregators }
|
355
|
-
end
|
356
|
-
|
357
|
-
context "managing the queue" do
|
358
|
-
before { subject.transmitter.stub(:transmit => '200') }
|
359
|
-
|
360
|
-
context "when successfully sent" do
|
361
|
-
before { subject.stub(:handle_result => true) }
|
362
|
-
|
363
|
-
it "should remove only successfully sent item from the queue" do
|
364
|
-
expect {
|
365
|
-
subject.send_aggregators
|
366
|
-
}.to change(subject, :aggregator_queue).from([aggregator_hash]).to([])
|
367
|
-
end
|
368
|
-
|
369
|
-
it "should set the transmission state to successful" do
|
370
|
-
subject.send_aggregators
|
371
|
-
expect( subject.transmission_successful ).to be_true
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
context "when failed to sent" do
|
376
|
-
before { subject.stub(:handle_result => false) }
|
377
|
-
|
378
|
-
it "should remove only successfully sent item from the queue" do
|
379
|
-
expect {
|
380
|
-
subject.send_aggregators
|
381
|
-
}.to_not change(subject, :aggregator_queue)
|
382
|
-
end
|
383
|
-
|
384
|
-
it "should set the transmission state to unsuccessful" do
|
385
|
-
subject.send_aggregators
|
386
|
-
expect( subject.transmission_successful ).to be_false
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
context "when an exception related to connection problems occurred during sending" do
|
391
|
-
before { subject.stub(:transmitter).and_raise(OpenSSL::SSL::SSLError.new) }
|
392
|
-
|
393
|
-
it "should remove only successfully sent item from the queue" do
|
394
|
-
Appsignal.logger.should_receive(:error).
|
395
|
-
with(kind_of(String)).
|
396
|
-
once
|
397
|
-
|
398
|
-
expect {
|
399
|
-
subject.send_aggregators
|
400
|
-
}.to_not change(subject, :aggregator_queue)
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should set the transmission state to unsuccessful" do
|
404
|
-
subject.send_aggregators
|
405
|
-
expect( subject.transmission_successful ).to be_false
|
406
|
-
end
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
describe "#truncate_aggregator_queue" do
|
412
|
-
before do
|
413
|
-
5.times { |i| subject.add_to_aggregator_queue(i) }
|
414
|
-
end
|
415
|
-
|
416
|
-
it "should truncate the queue to the given limit" do
|
417
|
-
expect {
|
418
|
-
subject.truncate_aggregator_queue(2)
|
419
|
-
}.to change(subject, :aggregator_queue).from([4, 3, 2, 1, 0]).to([4,3])
|
420
|
-
end
|
421
|
-
|
422
|
-
it "should log this event as an error" do
|
423
|
-
Appsignal.logger.should_receive(:error).
|
424
|
-
with('Aggregator queue to large, removing items').
|
425
|
-
once
|
426
|
-
|
427
|
-
subject.truncate_aggregator_queue(2)
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
describe "#forked!" do
|
432
|
-
subject { Appsignal.agent }
|
433
|
-
|
434
|
-
it "should set active to true, create a new aggregator, set the new pid and restart the thread" do
|
435
|
-
master_pid = subject.master_pid
|
436
|
-
subject.pid.should == master_pid
|
437
|
-
|
438
|
-
Process.stub(:pid => 9000000001)
|
439
|
-
subject.active = false
|
440
|
-
subject.should_receive(:resubscribe)
|
441
|
-
subject.should_receive(:restart_thread)
|
442
|
-
previous_aggregator = subject.aggregator
|
443
|
-
|
444
|
-
subject.forked!
|
445
|
-
|
446
|
-
subject.active?.should be_true
|
447
|
-
|
448
|
-
subject.aggregator.should_not == previous_aggregator
|
449
|
-
subject.aggregator.should be_a Appsignal::Aggregator
|
450
|
-
|
451
|
-
subject.master_pid.should == master_pid
|
452
|
-
subject.pid.should == 9000000001
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
describe "#shutdown" do
|
457
|
-
before do
|
458
|
-
ActiveSupport::Notifications.should_receive(:unsubscribe).with(subject.subscriber)
|
459
|
-
Thread.should_receive(:kill).with(subject.thread)
|
460
|
-
end
|
461
|
-
|
462
|
-
it "should not be active anymore after shutting down" do
|
463
|
-
subject.shutdown
|
464
|
-
subject.active?.should be_false
|
465
|
-
end
|
466
|
-
|
467
|
-
it "should log the reason for shutting down" do
|
468
|
-
Appsignal.logger.should_receive(:info).with('Shutting down agent (shutting down)')
|
469
|
-
subject.shutdown(false, 'shutting down')
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should send the queue and shut down if the queue is to be sent" do
|
473
|
-
subject.instance_variable_set(:@transmission_successful, true)
|
474
|
-
|
475
|
-
subject.should_receive(:send_queue)
|
476
|
-
|
477
|
-
subject.shutdown(true, nil)
|
478
|
-
end
|
479
|
-
|
480
|
-
it "should only shutdown if the queue is not be sent" do
|
481
|
-
subject.should_not_receive(:send_queue)
|
482
|
-
|
483
|
-
subject.shutdown(false, nil)
|
484
|
-
end
|
485
|
-
|
486
|
-
it "should only shutdown if the last tranmission was not successfull" do
|
487
|
-
subject.instance_variable_set(:@transmission_successful, false)
|
488
|
-
subject.should_not_receive(:send_queue)
|
489
|
-
|
490
|
-
subject.shutdown(true, nil)
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
describe '#handle_result' do
|
495
|
-
before { subject.aggregator.add(transaction) }
|
496
|
-
before { subject.instance_variable_set(:@sleep_time, 3.0) }
|
497
|
-
|
498
|
-
context "good responses" do
|
499
|
-
before { subject.send(:handle_result, code) }
|
500
|
-
|
501
|
-
context "with 200" do
|
502
|
-
let(:code) { '200' }
|
503
|
-
|
504
|
-
its(:sleep_time) { should == 3.0 }
|
505
|
-
|
506
|
-
it "does not log the event" do
|
507
|
-
Appsignal.logger.should_not_receive(:error)
|
508
|
-
end
|
509
|
-
end
|
510
|
-
|
511
|
-
context "with 420" do
|
512
|
-
let(:code) { '420' }
|
513
|
-
|
514
|
-
its(:sleep_time) { should == 4.5 }
|
515
|
-
end
|
516
|
-
|
517
|
-
context "with 413" do
|
518
|
-
let(:code) { '413' }
|
519
|
-
|
520
|
-
its(:sleep_time) { should == 2.0 }
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
context "bad responses" do
|
525
|
-
context "with 429" do
|
526
|
-
let(:code) { '429' }
|
527
|
-
|
528
|
-
it "calls a stop to logging" do
|
529
|
-
subject.should_receive(:shutdown)
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context "with 406" do
|
534
|
-
let(:code) { '406' }
|
535
|
-
|
536
|
-
it "calls a stop to logging" do
|
537
|
-
subject.should_receive(:shutdown)
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
context "with 402" do
|
542
|
-
let(:code) { '402' }
|
543
|
-
|
544
|
-
it "calls a stop to logging" do
|
545
|
-
subject.should_receive(:shutdown)
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
context "with 401" do
|
550
|
-
let(:code) { '401' }
|
551
|
-
|
552
|
-
it "calls a stop to logging" do
|
553
|
-
subject.should_receive(:shutdown)
|
554
|
-
end
|
555
|
-
end
|
556
|
-
|
557
|
-
context "any other response" do
|
558
|
-
let(:code) { 'any other response' }
|
559
|
-
|
560
|
-
it "logs the event" do
|
561
|
-
Appsignal.logger.should_receive(:error)
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
after { subject.send(:handle_result, code) }
|
566
|
-
end
|
567
|
-
|
568
|
-
context "return values" do
|
569
|
-
%w( 200 420 413 429 406 402 401 400 ).each do |code|
|
570
|
-
it "should return true for '#{code}'" do
|
571
|
-
subject.send(:handle_result, code).should be_true
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
%w( 500 502 ).each do |code|
|
576
|
-
it "should return false for '#{code}'" do
|
577
|
-
subject.send(:handle_result, code).should be_false
|
578
|
-
end
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|
582
|
-
|
583
|
-
context "when inactive" do
|
584
|
-
before { Appsignal.config.stub(:active? => false) }
|
585
|
-
|
586
|
-
it "should not start a thread" do
|
587
|
-
Thread.should_not_receive(:new)
|
588
|
-
end
|
589
|
-
|
590
|
-
after { Appsignal::Agent.new }
|
591
|
-
end
|
592
|
-
end
|