appsignal 0.11.8.beta.3 → 0.11.8.beta.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41eb79c820f9d67a1344387af4fc6397d11dcfaa
4
- data.tar.gz: 26ea28e40d99d4f8a33eb9604620fcbc1caada42
3
+ metadata.gz: cd999ef92367b114d182d7446e8a3333086cb943
4
+ data.tar.gz: e89697a0e0176cc9d567ff575e556c4673258d02
5
5
  SHA512:
6
- metadata.gz: 112b6cf13f7ac013141d1d3e351c373c727d6826d82d339f98904db17183bcb4fa6e5dc6b19f54b08de774a49b1db590bb515b15716fefba75f1916bcd1dc609
7
- data.tar.gz: 480404bb50bbbdc7fbc9ad8cc76bf3487a90f8eef1cfe28e1e425d4986d7744c3262b58f6fdc73fa51ce40b41221e7b76327f379276fa96b6c520db59e3b1bb3
6
+ metadata.gz: 6031199359197cd2e20b089f07af4db8c6f9c94b7bf9d25d9a0654e8c5ab63be9ad32dd22638c974fcbc1ca4170b70f558a6315125108eb30aa03149f0ae56b4
7
+ data.tar.gz: e3f21c86f83751ac0d50e255b7e67308d9e916c5c7e72708f1662ee1f3a4af104e5d355226ccaf55ed555bbb5e880c545cb75a942bf45705dd61c4099edc863c
@@ -201,6 +201,7 @@ require 'appsignal/transaction'
201
201
  require 'appsignal/transaction/formatter'
202
202
  require 'appsignal/transaction/params_sanitizer'
203
203
  require 'appsignal/transmitter'
204
+ require 'appsignal/zipped_payload'
204
205
  require 'appsignal/ipc'
205
206
  require 'appsignal/version'
206
207
  require 'appsignal/integrations/rails'
@@ -1,10 +1,11 @@
1
1
  module Appsignal
2
2
  class Agent
3
3
  ACTION = 'log_entries'.freeze
4
- AGGREGATOR_LIMIT = 5 # Five minutes with a sleep time of 60 seconds
4
+ AGGREGATOR_LIMIT = 3 # Three minutes with a sleep time of 60 seconds
5
5
 
6
6
  attr_accessor :aggregator, :thread, :master_pid, :pid, :active, :sleep_time,
7
- :transmitter, :subscriber, :paused, :aggregator_queue, :revision
7
+ :transmitter, :subscriber, :paused, :aggregator_queue, :revision,
8
+ :transmission_successful
8
9
 
9
10
  def initialize
10
11
  return unless Appsignal.config.active?
@@ -13,11 +14,12 @@ module Appsignal
13
14
  else
14
15
  @sleep_time = 60.0
15
16
  end
16
- @master_pid = Process.pid
17
- @pid = @master_pid
18
- @aggregator = Aggregator.new
19
- @transmitter = Transmitter.new(ACTION)
20
- @aggregator_queue = []
17
+ @master_pid = Process.pid
18
+ @pid = @master_pid
19
+ @aggregator = Aggregator.new
20
+ @transmitter = Transmitter.new(ACTION)
21
+ @aggregator_queue = []
22
+ @transmission_successful = true
21
23
 
22
24
  subscribe
23
25
  start_thread
@@ -110,7 +112,8 @@ module Appsignal
110
112
  end
111
113
 
112
114
  begin
113
- add_to_aggregator_queue(aggregator_to_be_sent.post_processed_queue!)
115
+ payload = Appsignal::ZippedPayload.new(aggregator_to_be_sent.post_processed_queue!)
116
+ add_to_aggregator_queue(payload)
114
117
  send_aggregators
115
118
  rescue Exception => ex
116
119
  Appsignal.logger.error "#{ex.class} while sending queue: #{ex.message}\n#{ex.backtrace.join("\n")}"
@@ -134,6 +137,7 @@ module Appsignal
134
137
  payload
135
138
  end
136
139
  end.compact!
140
+ @transmission_successful = @aggregator_queue.empty?
137
141
  end
138
142
 
139
143
  def truncate_aggregator_queue(limit = AGGREGATOR_LIMIT)
@@ -142,15 +146,6 @@ module Appsignal
142
146
  @aggregator_queue = @aggregator_queue.first(limit)
143
147
  end
144
148
 
145
- def clear_queue
146
- Appsignal.logger.debug('Clearing queue')
147
- # Replace aggregator while making sure no thread
148
- # is adding to it's queue
149
- Thread.exclusive do
150
- @aggregator = Aggregator.new
151
- end
152
- end
153
-
154
149
  def forked!
155
150
  Appsignal.logger.info('Forked worker process')
156
151
  @active = true
@@ -167,7 +162,9 @@ module Appsignal
167
162
  @active = false
168
163
  unsubscribe
169
164
  stop_thread
170
- send_queue if send_current_queue
165
+
166
+ # Only attempt to send the queue on shutdown when there are no API issues
167
+ send_queue if @transmission_successful
171
168
  end
172
169
 
173
170
  protected
@@ -41,7 +41,12 @@ module Appsignal
41
41
  end
42
42
  end
43
43
 
44
+ # Accepts a string or `Appsignal::ZippedPayload`
45
+ # If no `Appsignal::ZippedPayload` is given, it will convert it to one.
44
46
  def transmit(payload)
47
+ unless payload.is_a?(Appsignal::ZippedPayload)
48
+ payload = Appsignal::ZippedPayload.new(payload)
49
+ end
45
50
  Appsignal.logger.debug "Transmitting payload to #{uri}"
46
51
  http_client.request(http_post(payload)).code
47
52
  end
@@ -52,10 +57,7 @@ module Appsignal
52
57
  Net::HTTP::Post.new(uri.request_uri).tap do |request|
53
58
  request['Content-Type'] = CONTENT_TYPE
54
59
  request['Content-Encoding'] = CONTENT_ENCODING
55
- request.body = Zlib::Deflate.deflate(
56
- JSON.generate(payload, :quirks_mode => true),
57
- Zlib::BEST_SPEED
58
- )
60
+ request.body = payload.body
59
61
  end
60
62
  end
61
63
 
@@ -1,3 +1,3 @@
1
1
  module Appsignal
2
- VERSION = '0.11.8.beta.3'
2
+ VERSION = '0.11.8.beta.4'
3
3
  end
@@ -0,0 +1,13 @@
1
+ module Appsignal
2
+ class ZippedPayload
3
+ attr_reader :body
4
+
5
+ def initialize(given_body)
6
+ @body = Zlib::Deflate.deflate(
7
+ JSON.generate(given_body, :quirks_mode => true),
8
+ Zlib::BEST_SPEED
9
+ )
10
+ end
11
+
12
+ end
13
+ end
@@ -269,9 +269,17 @@ describe Appsignal::Agent do
269
269
  end
270
270
 
271
271
  describe "#send_queue" do
272
- it "adds aggregator to queue" do
272
+ let(:zipped_payload) { double(:body => :zip) }
273
+
274
+ it "adds Zipped Payload to queue" do
273
275
  subject.aggregator.stub(:post_processed_queue! => :foo)
274
- subject.should_receive(:add_to_aggregator_queue).with(:foo)
276
+
277
+ Appsignal::ZippedPayload
278
+ .should_receive(:new)
279
+ .with(:foo)
280
+ .and_return(zipped_payload)
281
+
282
+ subject.should_receive(:add_to_aggregator_queue).with(zipped_payload)
275
283
  end
276
284
 
277
285
  it "sends aggregators" do
@@ -329,6 +337,11 @@ describe Appsignal::Agent do
329
337
  subject.send_aggregators
330
338
  }.to change(subject, :aggregator_queue).from([aggregator_hash]).to([])
331
339
  end
340
+
341
+ it "should set the transmission state to successful" do
342
+ subject.send_aggregators
343
+ expect( subject.transmission_successful ).to be_true
344
+ end
332
345
  end
333
346
 
334
347
  context "when failed to sent" do
@@ -339,6 +352,11 @@ describe Appsignal::Agent do
339
352
  subject.send_aggregators
340
353
  }.to_not change(subject, :aggregator_queue)
341
354
  end
355
+
356
+ it "should set the transmission state to unsuccessful" do
357
+ subject.send_aggregators
358
+ expect( subject.transmission_successful ).to be_false
359
+ end
342
360
  end
343
361
 
344
362
  context "when an exception related to connection problems occurred during sending" do
@@ -354,6 +372,10 @@ describe Appsignal::Agent do
354
372
  }.to_not change(subject, :aggregator_queue)
355
373
  end
356
374
 
375
+ it "should set the transmission state to unsuccessful" do
376
+ subject.send_aggregators
377
+ expect( subject.transmission_successful ).to be_false
378
+ end
357
379
  end
358
380
  end
359
381
  end
@@ -378,14 +400,6 @@ describe Appsignal::Agent do
378
400
  end
379
401
  end
380
402
 
381
- describe "#clear_queue" do
382
- it "starts a new aggregator" do
383
- Appsignal::Aggregator.should_receive(:new).twice # once on start, once on clear
384
- end
385
-
386
- after { subject.clear_queue }
387
- end
388
-
389
403
  describe "#forked!" do
390
404
  subject { Appsignal.agent }
391
405
 
@@ -428,12 +442,15 @@ describe Appsignal::Agent do
428
442
  end
429
443
 
430
444
  it "should send the queue and shut down if the queue is to be sent" do
445
+ subject.instance_variable_set(:@transmission_successful, true)
446
+
431
447
  subject.should_receive(:send_queue)
432
448
 
433
449
  subject.shutdown(true, nil)
434
450
  end
435
451
 
436
452
  it "should only shutdown if the queue is not be sent" do
453
+ subject.instance_variable_set(:@transmission_successful, false)
437
454
  subject.should_not_receive(:send_queue)
438
455
 
439
456
  subject.shutdown(false, nil)
@@ -4,6 +4,7 @@ describe Appsignal::Transmitter do
4
4
  let(:config) { project_fixture_config }
5
5
  let(:action) { 'action' }
6
6
  let(:instance) { Appsignal::Transmitter.new(action, config) }
7
+ let!(:payload) { Appsignal::ZippedPayload.new({'the' => 'payload'}) }
7
8
 
8
9
  describe "#uri" do
9
10
  before { Socket.stub(:gethostname => 'app1.local') }
@@ -34,9 +35,25 @@ describe Appsignal::Transmitter do
34
35
  )
35
36
  end
36
37
 
37
- subject { instance.transmit(:the => :payload) }
38
+ it "should post the ZippedPayload" do
39
+ instance.transmit(payload).should == '200'
40
+ end
41
+
42
+ it "should not instantiate a new ZippedPayload" do
43
+ expect( Appsignal::ZippedPayload ).to_not receive(:new)
44
+ instance.transmit(payload)
45
+ end
38
46
 
39
- it { should == '200' }
47
+ context "when not given a ZippedPayload, but a hash" do
48
+ it "should post the ZippedPayload" do
49
+ instance.transmit({'the' => 'payload'}).should == '200'
50
+ end
51
+
52
+ it "should instantiate a new ZippedPayload" do
53
+ expect( Appsignal::ZippedPayload ).to receive(:new).and_return(payload)
54
+ instance.transmit({'the' => 'payload'})
55
+ end
56
+ end
40
57
  end
41
58
 
42
59
  describe "#http_post" do
@@ -44,7 +61,7 @@ describe Appsignal::Transmitter do
44
61
  Socket.stub(:gethostname => 'app1.local')
45
62
  end
46
63
 
47
- subject { instance.send(:http_post, 'the' => 'payload') }
64
+ subject { instance.send(:http_post, payload) }
48
65
 
49
66
  its(:body) { should == Zlib::Deflate.deflate("{\"the\":\"payload\"}", Zlib::BEST_SPEED) }
50
67
  its(:path) { should == instance.uri.request_uri }
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Appsignal::ZippedPayload do
4
+
5
+ describe "#initialize" do
6
+ it "should initialize a new `Appsignal::ZippedPayload` and zip the body" do
7
+ payload = Appsignal::ZippedPayload.new({'the' => 'payload'})
8
+
9
+ expect( payload.body ).to eql(Zlib::Deflate.deflate(
10
+ "{\"the\":\"payload\"}",
11
+ Zlib::BEST_SPEED
12
+ ))
13
+ end
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.8.beta.3
4
+ version: 0.11.8.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-03-20 00:00:00.000000000 Z
15
+ date: 2015-04-01 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -182,6 +182,7 @@ files:
182
182
  - lib/appsignal/transaction/params_sanitizer.rb
183
183
  - lib/appsignal/transmitter.rb
184
184
  - lib/appsignal/version.rb
185
+ - lib/appsignal/zipped_payload.rb
185
186
  - lib/generators/appsignal/USAGE
186
187
  - lib/generators/appsignal/appsignal_generator.rb
187
188
  - lib/generators/appsignal/templates/appsignal.yml
@@ -225,6 +226,7 @@ files:
225
226
  - spec/lib/appsignal/transaction/formatter_spec.rb
226
227
  - spec/lib/appsignal/transaction_spec.rb
227
228
  - spec/lib/appsignal/transmitter_spec.rb
229
+ - spec/lib/appsignal/zipped_payload_spec.rb
228
230
  - spec/lib/appsignal_spec.rb
229
231
  - spec/lib/generators/appsignal/appsignal_generator_spec.rb
230
232
  - spec/lib/tmp/config/appsignal.yml
@@ -298,6 +300,7 @@ test_files:
298
300
  - spec/lib/appsignal/transaction/formatter_spec.rb
299
301
  - spec/lib/appsignal/transaction_spec.rb
300
302
  - spec/lib/appsignal/transmitter_spec.rb
303
+ - spec/lib/appsignal/zipped_payload_spec.rb
301
304
  - spec/lib/appsignal_spec.rb
302
305
  - spec/lib/generators/appsignal/appsignal_generator_spec.rb
303
306
  - spec/lib/tmp/config/appsignal.yml