instrumental_agent 3.0.0.beta → 3.0.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1a781a0abec98e8c737a57fac5134fe2ee847879949fc5134ced2c0b0136076
4
- data.tar.gz: 89950c6e0b59713dc6034be99acfc52473ef049b63824685694626d049a85b8b
3
+ metadata.gz: a86fe597ab71c9660d590e42ef37e0d9012a4f5adbe7742d265f3d20ffda1b9e
4
+ data.tar.gz: cd56273db7523852982b58162361359fc3c9fcd3b8cae19bf87387bf63fe26b1
5
5
  SHA512:
6
- metadata.gz: ca82be6040189400c0e01513d517202e8d27d900ad2f10e5558025cad6a499e49985ee58c95efdf90d24e2fd0174b9349c7cd6ac8f906325f2de766c0f14cba3
7
- data.tar.gz: 742200da53f676a9341a795f5f8145416650c033466782348fc4852dc62e656e9fed4e2be02c0829c2ec946092e7dfcd7d836cc50e731a6ceb8cb2493b76a1b6
6
+ metadata.gz: c68427fe4c900db650e45b46423c808263d86df275b9f49b44896973f4db3e25cd61b8fe9a0b67cba54acbe831b4c00a7cbfb8c7b7d6cc30959159e9e149d3dd
7
+ data.tar.gz: 57f5554f876c9311d76305c60b754af1c7d1a8bb63b8682355217b014b927e1d0f500bea37daff954d5149d4015b1be80793f9f2ed8f713928b4af4d428e576f
@@ -265,22 +265,22 @@ module Instrumental
265
265
  logger.info "Cleaning up agent, aggregator_size: #{@aggregator_queue.size}, thread_running: #{@aggregator_thread.alive?}"
266
266
  logger.info "Cleaning up agent, queue size: #{@sender_queue.size}, thread running: #{@sender_thread.alive?}"
267
267
  @allow_reconnect = false
268
- if @sender_queue.size > 0 || @aggregator_queue.size > 0
269
- @sender_queue << ['exit']
270
- @aggregator_queue << ['exit']
271
- begin
272
- with_timeout(EXIT_FLUSH_TIMEOUT) { @aggregator_thread.join }
273
- with_timeout(EXIT_FLUSH_TIMEOUT) { @sender_thread.join }
274
- rescue Timeout::Error
275
- total_size = @sender_queue&.size.to_i +
276
- @aggregator_queue&.size.to_i +
277
- @event_aggregator&.size.to_i
278
-
279
- if total_size > 0
280
- logger.error "Timed out working agent thread on exit, dropping #{total_size} metrics"
281
- else
282
- logger.error "Timed out Instrumental Agent, exiting"
283
- end
268
+ begin
269
+ with_timeout(EXIT_FLUSH_TIMEOUT) do
270
+ @aggregator_queue << ['exit']
271
+ @aggregator_thread.join
272
+ @sender_queue << ['exit']
273
+ @sender_thread.join
274
+ end
275
+ rescue Timeout::Error
276
+ total_size = @sender_queue&.size.to_i +
277
+ @aggregator_queue&.size.to_i +
278
+ @event_aggregator&.size.to_i
279
+
280
+ if total_size > 0
281
+ logger.error "Timed out working agent thread on exit, dropping #{total_size} metrics"
282
+ else
283
+ logger.error "Timed out Instrumental Agent, exiting"
284
284
  end
285
285
  end
286
286
  end
@@ -413,13 +413,23 @@ module Instrumental
413
413
  disconnect
414
414
  address = ipv4_address_for_host(@host, @port)
415
415
  if address
416
- @pid = Process.pid
416
+ new_pid = if @pid != Process.pid
417
+ @pid = Process.pid
418
+ true
419
+ else
420
+ false
421
+ end
422
+
417
423
  @sync_mutex = Mutex.new
418
424
  @failures = 0
419
425
  @sockaddr_in = Socket.pack_sockaddr_in(@port, address)
420
426
 
421
427
  logger.info "Starting aggregator thread"
422
428
  if !@aggregator_thread&.alive?
429
+ if new_pid
430
+ @event_aggregator = nil
431
+ @aggregator_queue = Queue.new
432
+ end
423
433
  @aggregator_thread = Thread.new do
424
434
  run_aggregator_loop
425
435
  end
@@ -427,6 +437,7 @@ module Instrumental
427
437
 
428
438
  if !@sender_thread&.alive?
429
439
  logger.info "Starting sender thread"
440
+ @sender_queue = Queue.new if new_pid
430
441
  @sender_thread = Thread.new do
431
442
  run_sender_loop
432
443
  end
@@ -492,9 +503,12 @@ module Instrumental
492
503
  end
493
504
  end
494
505
  if command_and_args
495
- sync_resource = command_options && command_options[:sync_resource]
496
506
  case command_and_args
497
507
  when 'exit'
508
+ if !@event_aggregator.nil?
509
+ @sender_queue << @event_aggregator
510
+ @event_aggregator = nil
511
+ end
498
512
  logger.info "Exiting, #{@aggregator_queue.size} commands remain"
499
513
  return true
500
514
  when 'flush'
@@ -1,3 +1,3 @@
1
1
  module Instrumental
2
- VERSION = "3.0.0.beta"
2
+ VERSION = "3.0.0.beta2"
3
3
  end
@@ -636,20 +636,21 @@ shared_examples "Instrumental Agent" do
636
636
  end
637
637
  end
638
638
 
639
- it "should not wait to exit a process if there are no commands queued" do
639
+ it "should follow normal exit procedures whether or not there are commands queued" do
640
640
  allow(agent).to receive(:open_socket) { |*args, &block| sleep(5) && block.call }
641
- with_constants('Instrumental::Agent::EXIT_FLUSH_TIMEOUT' => 3) do
641
+ with_constants('Instrumental::Agent::EXIT_FLUSH_TIMEOUT' => 1) do
642
642
  if (pid = fork { agent.increment('foo', 1); agent.sender_queue.clear })
643
643
  tm = Time.now.to_f
644
644
  Process.wait(pid)
645
645
  diff = Time.now.to_f - tm
646
- expect(diff).to be < 1
646
+ expect(diff).to be < 2
647
+ expect(diff).to be > 1
647
648
  end
648
649
  end
649
650
  end
650
651
  end
651
652
 
652
- it "should not wait longer than EXIT_FLUSH_TIMEOUT to attempt flushing the socket when disconnecting" do
653
+ it "should not wait much longer than EXIT_FLUSH_TIMEOUT to attempt flushing the socket when disconnecting" do
653
654
  agent.increment('foo', 1)
654
655
  wait do
655
656
  expect(server.commands.grep(/foo/).size).to eq(1)
@@ -665,12 +666,13 @@ shared_examples "Instrumental Agent" do
665
666
  raise
666
667
  end
667
668
  end.join
668
- end
669
+ end.at_least(1).times
670
+
669
671
  with_constants('Instrumental::Agent::EXIT_FLUSH_TIMEOUT' => 3) do
670
672
  tm = Time.now.to_f
671
673
  agent.cleanup
672
674
  diff = Time.now.to_f - tm
673
- expect(diff).to be <= 3
675
+ expect(diff).to be <= 3.1
674
676
  end
675
677
  end
676
678
 
@@ -1097,6 +1099,33 @@ shared_examples "Instrumental Agent" do
1097
1099
  end
1098
1100
  end
1099
1101
  end
1102
+
1103
+ if FORK_SUPPORTED
1104
+ it "should automatically reconnect when forked when aggregation is enabled" do
1105
+ Timecop.travel start_of_minute
1106
+ agent.frequency = 10
1107
+
1108
+ agent.increment('fork_reconnect_test1', 1, 0, 1)
1109
+ fork do
1110
+ agent.increment('fork_reconnect_test2', 1, 0, 1) # triggers reconnect
1111
+ exit
1112
+ end
1113
+
1114
+
1115
+ sleep 1
1116
+ agent.increment('fork_reconnect_test3', 1, 0, 1) # triggers reconnect
1117
+
1118
+ agent.flush
1119
+ expect(server.connect_count).to eq(2)
1120
+
1121
+ wait do
1122
+ expect(server.commands).to include("increment fork_reconnect_test1 1 0 1")
1123
+ expect(server.commands).to include("increment fork_reconnect_test2 1 0 1")
1124
+ expect(server.commands).to include("increment fork_reconnect_test3 1 0 1")
1125
+ expect(server.commands.grep(/fork_reconnect/).size).to eq(3)
1126
+ end
1127
+ end
1128
+ end
1100
1129
  end
1101
1130
  end
1102
1131
  end
@@ -9,6 +9,15 @@ require 'test_server'
9
9
  RSpec.configure do |config|
10
10
 
11
11
  config.before(:all) do
12
+ # this is heavily threaded code with lots of really interesting
13
+ # comparison and matching. forcing rspec to load all its differs
14
+ # and matchers up front can save considerable time.
15
+ # Lazy loading these things can be so slow that it causes false
16
+ # failures in some tests.
17
+ begin
18
+ expect(1).to eq(2)
19
+ rescue Exception
20
+ end
12
21
  end
13
22
 
14
23
  config.before(:each) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrumental_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta
4
+ version: 3.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Expected Behavior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metrician