instrumental_agent 3.0.0.beta2 → 3.0.0.beta3
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/lib/instrumental/event_aggregator.rb +22 -20
- data/lib/instrumental/version.rb +1 -1
- data/spec/agent_spec.rb +3 -20
- data/spec/event_aggregator_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20bc1dfd989a1d555912b21cd1a43b0a2ebb235e411fed6b27746cd3c01ce2ad
|
4
|
+
data.tar.gz: 7e725c0d514db6cccba3827a76a7b73995b06084a54bf0637cf7c2423d2beb3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356538412bb4aeeb4af6dbb912de961ca587b08410a48cc60b8246e7d138909dab5f75261dd441bf4fd9287868565c2a4554a313c0b9d43316ca7ac615f38b20
|
7
|
+
data.tar.gz: f819635e2b8ea0efaa7a25ed62cdf52d54b602e8b8703a7eea3b7975f83ed557ffe0cdd1a39b5dd97942492e3a872d4e343c6c179de18feb3dbb257c08faf1a8
|
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(frequency:)
|
5
|
-
@values = Hash.new
|
6
|
-
@frequency = frequency
|
7
|
-
end
|
1
|
+
module Instrumental
|
2
|
+
class EventAggregator
|
3
|
+
attr_accessor :counts, :values, :received_at, :frequency
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
command.time = (command_at - (command_at % frequency))
|
5
|
+
def initialize(frequency:)
|
6
|
+
@values = Hash.new
|
7
|
+
@frequency = frequency
|
13
8
|
end
|
14
|
-
metadata = command.metadata
|
15
|
-
@values[metadata] = (command + @values[metadata])
|
16
|
-
end
|
17
9
|
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
def put(command)
|
11
|
+
command_at = command.time
|
12
|
+
unless(command_at % frequency == 0)
|
13
|
+
command.time = (command_at - (command_at % frequency))
|
14
|
+
end
|
15
|
+
metadata = command.metadata
|
16
|
+
@values[metadata] = (command + @values[metadata])
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
def size
|
20
|
+
@values.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def coerce_time(time)
|
24
|
+
itime = time.to_i
|
25
|
+
(itime - (itime % frequency)).to_i
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/instrumental/version.rb
CHANGED
data/spec/agent_spec.rb
CHANGED
@@ -832,7 +832,7 @@ shared_examples "Instrumental Agent" do
|
|
832
832
|
|
833
833
|
it "bypasses aggregator queue entirely for most commands when frequency == 0" do
|
834
834
|
agent.frequency = 0 # this is red - 0 for green
|
835
|
-
expect(EventAggregator).not_to receive(:new)
|
835
|
+
expect(Instrumental::EventAggregator).not_to receive(:new)
|
836
836
|
agent.increment('a_metric')
|
837
837
|
end
|
838
838
|
|
@@ -909,7 +909,7 @@ shared_examples "Instrumental Agent" do
|
|
909
909
|
|
910
910
|
it "can be disabled by setting frequency to nil" do
|
911
911
|
agent.frequency = nil
|
912
|
-
expect(EventAggregator).not_to receive(:new)
|
912
|
+
expect(Instrumental::EventAggregator).not_to receive(:new)
|
913
913
|
agent.increment('metric')
|
914
914
|
wait do
|
915
915
|
expect(server.commands.grep(/metric/).size).to eq(1)
|
@@ -918,7 +918,7 @@ shared_examples "Instrumental Agent" do
|
|
918
918
|
|
919
919
|
it "can be disabled by setting frequency to 0" do
|
920
920
|
agent.frequency = 0
|
921
|
-
expect(EventAggregator).not_to receive(:new)
|
921
|
+
expect(Instrumental::EventAggregator).not_to receive(:new)
|
922
922
|
agent.increment('metric')
|
923
923
|
wait do
|
924
924
|
expect(server.commands.grep(/metric/).size).to eq(1)
|
@@ -979,23 +979,6 @@ shared_examples "Instrumental Agent" do
|
|
979
979
|
expect(server.commands.grep(/other 3/).size).to eq(1)
|
980
980
|
end
|
981
981
|
|
982
|
-
# this test really relies on the worker threads not working unexpectedly
|
983
|
-
it "will overflow if the aggregator queue is full" do
|
984
|
-
Timecop.travel(start_of_minute)
|
985
|
-
with_constants('Instrumental::Agent::MAX_BUFFER' => 3) do
|
986
|
-
allow(agent.logger).to receive(:debug)
|
987
|
-
expect(agent.logger).to receive(:debug).with("Dropping command, queue full(3): increment overflow_test 4 300 1")
|
988
|
-
agent.increment('overflow_test', 4, 300, 1)
|
989
|
-
agent.increment('overflow_test', 4, 300, 1)
|
990
|
-
agent.increment('overflow_test', 4, 300, 1)
|
991
|
-
agent.increment('overflow_test', 4, 300, 1)
|
992
|
-
|
993
|
-
expect(agent.instance_variable_get(:@aggregator_queue).size).to eq(3)
|
994
|
-
agent.flush
|
995
|
-
expect(agent.instance_variable_get(:@aggregator_queue).size).to eq(0)
|
996
|
-
end
|
997
|
-
end
|
998
|
-
|
999
982
|
it "if aggregator is at max size, next command will force a forward to the sender thread" do
|
1000
983
|
Timecop.travel(start_of_minute)
|
1001
984
|
with_constants('Instrumental::Agent::MAX_AGGREGATOR_SIZE' => 3) do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe EventAggregator, "time and frequency operations" do
|
3
|
+
describe Instrumental::EventAggregator, "time and frequency operations" do
|
4
4
|
it "should massage time values to match the start of a window" do
|
5
|
-
agg = EventAggregator.new(frequency: 10)
|
5
|
+
agg = Instrumental::EventAggregator.new(frequency: 10)
|
6
6
|
Timecop.freeze do
|
7
7
|
start_of_minute = Time.now.to_i - (Time.now.to_i % 60)
|
8
8
|
times_to_report = [start_of_minute + 5, start_of_minute + 15]
|
@@ -20,11 +20,11 @@ describe EventAggregator, "time and frequency operations" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe EventAggregator do
|
23
|
+
describe Instrumental::EventAggregator do
|
24
24
|
it "should aggregate put operations to a given frequency" do
|
25
25
|
start_of_minute = Time.now.to_i - (Time.now.to_i % 60)
|
26
26
|
Timecop.freeze(Time.at(start_of_minute)) do
|
27
|
-
agg = EventAggregator.new(frequency: 30)
|
27
|
+
agg = Instrumental::EventAggregator.new(frequency: 30)
|
28
28
|
(Time.now.to_i..(Time.now.to_i + 119)).each do |time|
|
29
29
|
agg.put(Instrumental::Command.new("increment", "abc", 1, time, 1))
|
30
30
|
end
|
@@ -37,7 +37,7 @@ describe EventAggregator do
|
|
37
37
|
|
38
38
|
it "should aggregate put operations to the same metric and last type wins" do
|
39
39
|
Timecop.freeze do
|
40
|
-
agg = EventAggregator.new(frequency: 6)
|
40
|
+
agg = Instrumental::EventAggregator.new(frequency: 6)
|
41
41
|
|
42
42
|
agg.put(Instrumental::Command.new("gauge", "hello", 3.0, Time.now, 1))
|
43
43
|
agg.put(Instrumental::Command.new("increment", "hello", 4.0, Time.now, 1))
|