fluq 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/benchmark/logging.rb +10 -10
- data/lib/fluq/feed/base.rb +20 -1
- data/lib/fluq/feed/json.rb +18 -18
- data/lib/fluq/feed/msgpack.rb +17 -17
- data/lib/fluq/feed/tsv.rb +20 -20
- data/lib/fluq/version.rb +1 -1
- data/spec/spec_helper.rb +27 -2
- metadata +1 -2
- data/spec/support/configuration.rb +0 -25
data/Gemfile.lock
CHANGED
data/benchmark/logging.rb
CHANGED
@@ -6,25 +6,25 @@ require 'bundler/setup'
|
|
6
6
|
require 'fluq'
|
7
7
|
require 'benchmark'
|
8
8
|
|
9
|
-
ITER
|
9
|
+
ITER = 1_000
|
10
|
+
SLICE = 1_000
|
10
11
|
|
11
|
-
MultiJson.use :oj
|
12
12
|
FileUtils.rm_rf FluQ.root.join("log/benchmark")
|
13
13
|
|
14
|
-
events = (1..
|
15
|
-
FluQ::Event.new "a.b#{rand(4)}.c#{rand(
|
14
|
+
events = (1..SLICE).map do
|
15
|
+
FluQ::Event.new "a.b#{rand(4)}.c#{rand(10)}.d#{rand(100)}", Time.now.to_i, "k1" => "value", "k2" => "value", "k3" => "value"
|
16
16
|
end
|
17
17
|
|
18
|
-
handler = FluQ::Handler::Log.new
|
18
|
+
handler = FluQ::Handler::Log.new FluQ::Reactor.new,
|
19
19
|
path: "log/benchmark/%Y%m/%d/%H/%t.log",
|
20
|
-
rewrite: lambda {|t| t.split(".")[1] }
|
20
|
+
rewrite: lambda {|t| t.split(".")[1, 2].join("-") }
|
21
21
|
|
22
22
|
puts "--> Started benchmark"
|
23
23
|
processed = Benchmark.realtime do
|
24
24
|
num = 0
|
25
|
-
|
26
|
-
handler.on_events(
|
27
|
-
num +=
|
25
|
+
ITER.times do
|
26
|
+
handler.on_events(events)
|
27
|
+
num += SLICE
|
28
28
|
if (num % 10_000).zero?
|
29
29
|
puts "--> Processed : #{num}"
|
30
30
|
end
|
@@ -34,4 +34,4 @@ end
|
|
34
34
|
puts "--> Processed : #{events.size} in #{processed.round(1)}s"
|
35
35
|
files = Dir[FluQ.root.join("log/benchmark/**/*.log").to_s]
|
36
36
|
lines = `cat #{files.join(' ')} | wc -l`.strip
|
37
|
-
puts "-->
|
37
|
+
puts "--> Fsynched : #{lines} lines"
|
data/lib/fluq/feed/base.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
class FluQ::Feed::Base
|
2
2
|
include Enumerable
|
3
3
|
include FluQ::Mixins::Loggable
|
4
|
+
extend FluQ::Mixins::Loggable
|
5
|
+
|
6
|
+
# @abstract enumerator
|
7
|
+
# @param [String] raw event string
|
8
|
+
# @return [FluQ::Event] event
|
9
|
+
def self.to_event(raw)
|
10
|
+
end
|
4
11
|
|
5
12
|
# @attr_reader [FluQ::Buffer::Base] buffer
|
6
13
|
attr_reader :buffer
|
@@ -10,9 +17,21 @@ class FluQ::Feed::Base
|
|
10
17
|
@buffer = buffer
|
11
18
|
end
|
12
19
|
|
13
|
-
# @abstract enumerator
|
14
20
|
# @yield ober a feed of events
|
15
21
|
# @yieldparam [FluQ::Event] event
|
16
22
|
def each
|
23
|
+
each_raw do |raw|
|
24
|
+
event = self.class.to_event(raw)
|
25
|
+
yield event if event
|
26
|
+
end
|
17
27
|
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# @abstract enumerator
|
32
|
+
# @yield ober a feed of raw events
|
33
|
+
# @yieldparam [String] raw event
|
34
|
+
def each_raw
|
35
|
+
end
|
36
|
+
|
18
37
|
end
|
data/lib/fluq/feed/json.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
class FluQ::Feed::Json < FluQ::Feed::Base
|
2
2
|
|
3
|
-
# @see
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
# @see FluQ::Feed::Base.to_event
|
4
|
+
def self.to_event(raw)
|
5
|
+
case hash = Oj.load(raw)
|
6
|
+
when Hash
|
7
|
+
FluQ::Event.new hash.delete("="), hash.delete("@"), hash
|
8
|
+
else
|
9
|
+
logger.warn "buffer contained invalid event #{hash.inspect}"
|
10
|
+
nil
|
10
11
|
end
|
12
|
+
rescue Oj::ParseError
|
13
|
+
logger.warn "buffer contained invalid line #{raw.inspect}"
|
14
|
+
nil
|
11
15
|
end
|
12
16
|
|
13
|
-
|
17
|
+
protected
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
nil
|
19
|
+
# @see [FluQ::Feed::Base] each_raw
|
20
|
+
def each_raw
|
21
|
+
buffer.drain do |io|
|
22
|
+
while line = io.gets
|
23
|
+
yield line
|
24
|
+
end
|
22
25
|
end
|
23
|
-
rescue Oj::ParseError
|
24
|
-
logger.warn "buffer contained invalid line #{line.inspect}"
|
25
|
-
nil
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/lib/fluq/feed/msgpack.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
class FluQ::Feed::Msgpack < FluQ::Feed::Base
|
2
2
|
|
3
|
-
# @see
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
# @see FluQ::Feed::Base.to_event
|
4
|
+
def self.to_event(raw)
|
5
|
+
raw = MessagePack.unpack(raw) if raw.is_a?(String)
|
6
|
+
|
7
|
+
case raw
|
8
|
+
when Hash
|
9
|
+
FluQ::Event.new raw.delete("="), raw.delete("@"), raw
|
10
|
+
else
|
11
|
+
logger.warn "buffer contained invalid event #{raw.inspect}"
|
12
|
+
nil
|
11
13
|
end
|
12
|
-
rescue EOFError
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
protected
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
logger.warn "buffer contained invalid event #{hash.inspect}"
|
23
|
-
nil
|
18
|
+
# @see [FluQ::Feed::Base] each
|
19
|
+
def each_raw(&block)
|
20
|
+
buffer.drain do |io|
|
21
|
+
pac = MessagePack::Unpacker.new(io)
|
22
|
+
pac.each(&block)
|
24
23
|
end
|
24
|
+
rescue EOFError
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
data/lib/fluq/feed/tsv.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
class FluQ::Feed::Tsv < FluQ::Feed::Base
|
2
2
|
|
3
|
-
# @see
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
# @see FluQ::Feed::Base.to_event
|
4
|
+
def self.to_event(raw)
|
5
|
+
tag, timestamp, json = raw.split("\t")
|
6
|
+
|
7
|
+
case hash = Oj.load(json)
|
8
|
+
when Hash
|
9
|
+
FluQ::Event.new tag, timestamp, hash
|
10
|
+
else
|
11
|
+
logger.warn "buffer contained invalid event #{hash.inspect}"
|
12
|
+
nil
|
10
13
|
end
|
14
|
+
rescue Oj::ParseError, ArgumentError
|
15
|
+
logger.warn "buffer contained invalid line #{raw.inspect}"
|
16
|
+
nil
|
11
17
|
end
|
12
18
|
|
13
|
-
|
19
|
+
protected
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
logger.warn "buffer contained invalid event #{[tag, timestamp, hash].inspect}"
|
23
|
-
nil
|
21
|
+
# @see [FluQ::Feed::Base] each_raw
|
22
|
+
def each_raw
|
23
|
+
buffer.drain do |io|
|
24
|
+
while line = io.gets
|
25
|
+
yield line
|
26
|
+
end
|
24
27
|
end
|
25
|
-
rescue Oj::ParseError, ArgumentError
|
26
|
-
logger.warn "buffer contained invalid line #{line.inspect}"
|
27
|
-
nil
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
data/lib/fluq/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,33 @@ require 'bundler/setup'
|
|
5
5
|
require 'rspec'
|
6
6
|
require 'fluq/testing'
|
7
7
|
|
8
|
-
Dir[FluQ.root.join("../support/**/*.rb")].each {|f| require f }
|
9
8
|
FluQ.logger = Logger.new(FluQ.root.join("log", "fluq.log").to_s)
|
10
9
|
|
11
10
|
$LOAD_PATH.unshift FluQ.root.join('lib')
|
12
|
-
Random.srand(1234)
|
11
|
+
Random.srand(1234)
|
12
|
+
|
13
|
+
module FluQ::SpecHelpers
|
14
|
+
|
15
|
+
def self.included(base)
|
16
|
+
super
|
17
|
+
base.instance_eval do
|
18
|
+
let(:reactor) { @_reactor ||= FluQ::Reactor.new }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_reactor(&block)
|
23
|
+
FluQ::Reactor.run do |reactor|
|
24
|
+
@_reactor = reactor
|
25
|
+
block.call(reactor)
|
26
|
+
EM.stop
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |c|
|
33
|
+
c.include FluQ::SpecHelpers
|
34
|
+
c.after do
|
35
|
+
FileUtils.rm_rf FluQ.root.join("tmp").to_s
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -213,7 +213,6 @@ files:
|
|
213
213
|
- spec/scenario/lib/fluq/handler/custom/test_handler.rb
|
214
214
|
- spec/scenario/log/.gitkeep
|
215
215
|
- spec/spec_helper.rb
|
216
|
-
- spec/support/configuration.rb
|
217
216
|
homepage: https://github.com/bsm/fluq
|
218
217
|
licenses: []
|
219
218
|
post_install_message:
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module FluQ::SpecHelpers
|
2
|
-
|
3
|
-
def self.included(base)
|
4
|
-
super
|
5
|
-
base.instance_eval do
|
6
|
-
let(:reactor) { @_reactor ||= FluQ::Reactor.new }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_reactor(&block)
|
11
|
-
FluQ::Reactor.run do |reactor|
|
12
|
-
@_reactor = reactor
|
13
|
-
block.call(reactor)
|
14
|
-
EM.stop
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
RSpec.configure do |c|
|
21
|
-
c.include FluQ::SpecHelpers
|
22
|
-
c.after do
|
23
|
-
FileUtils.rm_rf FluQ.root.join("tmp").to_s
|
24
|
-
end
|
25
|
-
end
|