instrumental_agent 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/instrumental/agent.rb +13 -3
- data/lib/instrumental/version.rb +1 -1
- data/spec/agent_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32d9f3dab94080e4c8194ab8c71e0ddf4d83bb8a
|
4
|
+
data.tar.gz: fa78452258ca2f450d5a6da975a5c1d0a114902a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5174c7be573fab85d465dc2a6db07d35a62b7bcae160668fc4182da5fefc795930911392c556fa71af0a210723a5534c8548305f2de74c1ccbaae40d535ae448
|
7
|
+
data.tar.gz: 69d4ad769e79161afa6d0c915c9a2b21835a010fc5452a975cfa438484f61906e4474e366c845ce1f46443b3effeba6b737c2f738dfaadfad9a7441604fc05f6
|
data/CHANGELOG.md
CHANGED
data/lib/instrumental/agent.rb
CHANGED
@@ -77,6 +77,8 @@ module Instrumental
|
|
77
77
|
@certs = certificates
|
78
78
|
@dns_resolutions = 0
|
79
79
|
@last_connect_at = 0
|
80
|
+
@start_worker_mutex = Mutex.new
|
81
|
+
@queue = Queue.new
|
80
82
|
|
81
83
|
setup_cleanup_at_exit if @enabled
|
82
84
|
end
|
@@ -287,7 +289,7 @@ module Instrumental
|
|
287
289
|
cmd = "%s %s\n" % [cmd, args.collect { |a| a.to_s }.join(" ")]
|
288
290
|
if enabled?
|
289
291
|
|
290
|
-
start_connection_worker
|
292
|
+
start_connection_worker
|
291
293
|
if @queue && @queue.size < MAX_BUFFER
|
292
294
|
@queue_full_warning = false
|
293
295
|
logger.debug "Queueing: #{cmd.chomp}"
|
@@ -365,9 +367,15 @@ module Instrumental
|
|
365
367
|
end
|
366
368
|
|
367
369
|
def start_connection_worker
|
368
|
-
|
370
|
+
# NOTE: We need a mutex around both `running?` and thread creation,
|
371
|
+
# otherwise we could create two threads.
|
372
|
+
# Return early and queue the message if another thread is
|
373
|
+
# starting the worker.
|
374
|
+
return if !@start_worker_mutex.try_lock
|
375
|
+
begin
|
376
|
+
return if running?
|
377
|
+
return unless enabled?
|
369
378
|
disconnect
|
370
|
-
@queue ||= Queue.new
|
371
379
|
address = ipv4_address_for_host(@host, @port)
|
372
380
|
if address
|
373
381
|
@pid = Process.pid
|
@@ -379,6 +387,8 @@ module Instrumental
|
|
379
387
|
run_worker_loop
|
380
388
|
end
|
381
389
|
end
|
390
|
+
ensure
|
391
|
+
@start_worker_mutex.unlock
|
382
392
|
end
|
383
393
|
end
|
384
394
|
|
data/lib/instrumental/version.rb
CHANGED
data/spec/agent_spec.rb
CHANGED
@@ -235,6 +235,25 @@ shared_examples "Instrumental Agent" do
|
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
|
+
it "shouldn't start multiple background threads" do
|
239
|
+
# Force a wait that would cause a race condition
|
240
|
+
allow(agent).to receive(:disconnect) {
|
241
|
+
sleep 1
|
242
|
+
}
|
243
|
+
|
244
|
+
run_worker_loop_calls = 0
|
245
|
+
allow(agent).to receive(:run_worker_loop) {
|
246
|
+
run_worker_loop_calls += 1
|
247
|
+
sleep 3 # keep the worker thread alive
|
248
|
+
}
|
249
|
+
|
250
|
+
t = Thread.new { agent.increment("race") }
|
251
|
+
agent.increment("race")
|
252
|
+
wait(2)
|
253
|
+
expect(run_worker_loop_calls).to eq(1)
|
254
|
+
expect(agent.queue.size).to eq(2)
|
255
|
+
end
|
256
|
+
|
238
257
|
it "should never let an exception reach the user" do
|
239
258
|
expect(agent).to receive(:send_command).twice { raise(Exception.new("Test Exception")) }
|
240
259
|
expect(agent.increment('throws_exception', 2)).to eq(nil)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instrumental_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elijah Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pry
|