fluentd 0.12.43 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +1239 -0
- data/README.md +0 -25
- data/Rakefile +2 -1
- data/Vagrantfile +17 -0
- data/appveyor.yml +35 -0
- data/example/filter_stdout.conf +5 -5
- data/example/in_forward.conf +2 -2
- data/example/in_http.conf +2 -2
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +2 -2
- data/example/in_tail.conf +2 -2
- data/example/in_tcp.conf +2 -2
- data/example/in_udp.conf +2 -2
- data/example/out_copy.conf +4 -4
- data/example/out_file.conf +2 -2
- data/example/out_forward.conf +2 -2
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +8 -8
- data/fluent.conf +29 -0
- data/fluentd.gemspec +18 -11
- data/lib/fluent/agent.rb +60 -58
- data/lib/fluent/command/cat.rb +1 -1
- data/lib/fluent/command/debug.rb +7 -5
- data/lib/fluent/command/fluentd.rb +97 -2
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/filter.rb +50 -0
- data/lib/fluent/compat/formatter.rb +109 -0
- data/lib/fluent/compat/input.rb +50 -0
- data/lib/fluent/compat/output.rb +617 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +163 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/config.rb +23 -20
- data/lib/fluent/config/configure_proxy.rb +119 -70
- data/lib/fluent/config/dsl.rb +5 -18
- data/lib/fluent/config/element.rb +72 -8
- data/lib/fluent/config/error.rb +0 -3
- data/lib/fluent/config/literal_parser.rb +0 -2
- data/lib/fluent/config/parser.rb +4 -4
- data/lib/fluent/config/section.rb +39 -28
- data/lib/fluent/config/types.rb +2 -13
- data/lib/fluent/config/v1_parser.rb +1 -3
- data/lib/fluent/configurable.rb +48 -16
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +26 -52
- data/lib/fluent/env.rb +6 -4
- data/lib/fluent/event.rb +58 -11
- data/lib/fluent/event_router.rb +5 -5
- data/lib/fluent/filter.rb +2 -50
- data/lib/fluent/formatter.rb +4 -293
- data/lib/fluent/input.rb +2 -32
- data/lib/fluent/label.rb +2 -2
- data/lib/fluent/load.rb +3 -2
- data/lib/fluent/log.rb +107 -38
- data/lib/fluent/match.rb +0 -36
- data/lib/fluent/mixin.rb +117 -7
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +7 -612
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +4 -800
- data/lib/fluent/plugin.rb +100 -121
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +121 -0
- data/lib/fluent/plugin/buf_file.rb +101 -182
- data/lib/fluent/plugin/buf_memory.rb +9 -92
- data/lib/fluent/plugin/buffer.rb +473 -0
- data/lib/fluent/plugin/buffer/chunk.rb +135 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
- data/lib/fluent/plugin/exec_util.rb +80 -75
- data/lib/fluent/plugin/file_util.rb +33 -28
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +51 -0
- data/lib/fluent/plugin/filter_grep.rb +13 -40
- data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
- data/lib/fluent/plugin/formatter.rb +93 -0
- data/lib/fluent/plugin/formatter_csv.rb +48 -0
- data/lib/fluent/plugin/formatter_hash.rb +32 -0
- data/lib/fluent/plugin/formatter_json.rb +47 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
- data/lib/fluent/plugin/formatter_out_file.rb +45 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +39 -0
- data/lib/fluent/plugin/in_debug_agent.rb +4 -0
- data/lib/fluent/plugin/in_dummy.rb +22 -18
- data/lib/fluent/plugin/in_exec.rb +18 -8
- data/lib/fluent/plugin/in_forward.rb +36 -79
- data/lib/fluent/plugin/in_gc_stat.rb +4 -0
- data/lib/fluent/plugin/in_http.rb +21 -18
- data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
- data/lib/fluent/plugin/in_object_space.rb +6 -1
- data/lib/fluent/plugin/in_stream.rb +7 -3
- data/lib/fluent/plugin/in_syslog.rb +46 -95
- data/lib/fluent/plugin/in_tail.rb +58 -640
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -18
- data/lib/fluent/plugin/input.rb +33 -0
- data/lib/fluent/plugin/multi_output.rb +95 -0
- data/lib/fluent/plugin/out_buffered_null.rb +59 -0
- data/lib/fluent/plugin/out_copy.rb +11 -7
- data/lib/fluent/plugin/out_exec.rb +15 -11
- data/lib/fluent/plugin/out_exec_filter.rb +18 -10
- data/lib/fluent/plugin/out_file.rb +34 -5
- data/lib/fluent/plugin/out_forward.rb +25 -19
- data/lib/fluent/plugin/out_null.rb +0 -14
- data/lib/fluent/plugin/out_roundrobin.rb +11 -7
- data/lib/fluent/plugin/out_stdout.rb +5 -7
- data/lib/fluent/plugin/out_stream.rb +3 -1
- data/lib/fluent/plugin/output.rb +979 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +244 -0
- data/lib/fluent/plugin/parser_apache.rb +24 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +21 -0
- data/lib/fluent/plugin/parser_csv.rb +31 -0
- data/lib/fluent/plugin/parser_json.rb +79 -0
- data/lib/fluent/plugin/parser_ltsv.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +102 -0
- data/lib/fluent/plugin/parser_nginx.rb +24 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_syslog.rb +82 -0
- data/lib/fluent/plugin/parser_tsv.rb +37 -0
- data/lib/fluent/plugin/socket_util.rb +119 -117
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +116 -0
- data/lib/fluent/plugin/string_util.rb +16 -13
- data/lib/fluent/plugin_helper.rb +39 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
- data/lib/fluent/plugin_helper/event_loop.rb +118 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +308 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +85 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +21 -30
- data/lib/fluent/registry.rb +21 -9
- data/lib/fluent/root_agent.rb +115 -40
- data/lib/fluent/supervisor.rb +330 -320
- data/lib/fluent/system_config.rb +42 -18
- data/lib/fluent/test.rb +6 -1
- data/lib/fluent/test/base.rb +23 -3
- data/lib/fluent/test/driver/base.rb +247 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +35 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/output.rb +78 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +0 -1
- data/lib/fluent/test/formatter_test.rb +2 -1
- data/lib/fluent/test/input_test.rb +23 -17
- data/lib/fluent/test/output_test.rb +28 -39
- data/lib/fluent/test/parser_test.rb +1 -1
- data/lib/fluent/time.rb +104 -1
- data/lib/fluent/{status.rb → unique_id.rb} +15 -24
- data/lib/fluent/version.rb +1 -1
- data/lib/fluent/winsvc.rb +72 -0
- data/test/compat/test_calls_super.rb +164 -0
- data/test/config/test_config_parser.rb +83 -0
- data/test/config/test_configurable.rb +547 -274
- data/test/config/test_configure_proxy.rb +146 -29
- data/test/config/test_dsl.rb +3 -181
- data/test/config/test_element.rb +274 -0
- data/test/config/test_literal_parser.rb +1 -1
- data/test/config/test_section.rb +79 -7
- data/test/config/test_system_config.rb +21 -0
- data/test/config/test_types.rb +3 -26
- data/test/helper.rb +78 -8
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +420 -521
- data/test/plugin/test_buf_memory.rb +32 -194
- data/test/plugin/test_buffer.rb +981 -0
- data/test/plugin/test_buffer_chunk.rb +110 -0
- data/test/plugin/test_buffer_file_chunk.rb +770 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_filter.rb +255 -0
- data/test/plugin/test_filter_grep.rb +2 -73
- data/test/plugin/test_filter_record_transformer.rb +24 -68
- data/test/plugin/test_filter_stdout.rb +6 -6
- data/test/plugin/test_in_debug_agent.rb +2 -0
- data/test/plugin/test_in_dummy.rb +11 -17
- data/test/plugin/test_in_exec.rb +6 -25
- data/test/plugin/test_in_forward.rb +112 -151
- data/test/plugin/test_in_gc_stat.rb +2 -0
- data/test/plugin/test_in_http.rb +106 -157
- data/test/plugin/test_in_object_space.rb +21 -5
- data/test/plugin/test_in_stream.rb +14 -13
- data/test/plugin/test_in_syslog.rb +30 -275
- data/test/plugin/test_in_tail.rb +95 -282
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -67
- data/test/plugin/test_input.rb +122 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_buffered_null.rb +79 -0
- data/test/plugin/test_out_copy.rb +15 -2
- data/test/plugin/test_out_exec.rb +75 -25
- data/test/plugin/test_out_exec_filter.rb +74 -8
- data/test/plugin/test_out_file.rb +61 -7
- data/test/plugin/test_out_forward.rb +92 -15
- data/test/plugin/test_out_roundrobin.rb +1 -0
- data/test/plugin/test_out_stdout.rb +22 -13
- data/test/plugin/test_out_stream.rb +18 -0
- data/test/plugin/test_output.rb +515 -0
- data/test/plugin/test_output_as_buffered.rb +1540 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
- data/test/plugin/test_output_as_buffered_retries.rb +808 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
- data/test/plugin/test_output_as_standard.rb +362 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin_helper/test_child_process.rb +599 -0
- data/test/plugin_helper/test_compat_parameters.rb +175 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +411 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +100 -0
- data/test/scripts/exec_script.rb +0 -6
- data/test/scripts/fluent/plugin/out_test.rb +3 -0
- data/test/test_config.rb +13 -4
- data/test/test_event.rb +24 -13
- data/test/test_event_router.rb +8 -7
- data/test/test_event_time.rb +187 -0
- data/test/test_formatter.rb +13 -51
- data/test/test_input.rb +1 -1
- data/test/test_log.rb +239 -16
- data/test/test_mixin.rb +1 -1
- data/test/test_output.rb +53 -66
- data/test/test_parser.rb +105 -323
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_root_agent.rb +4 -52
- data/test/test_supervisor.rb +272 -0
- data/test/test_unique_id.rb +47 -0
- metadata +181 -55
- data/CHANGELOG.md +0 -710
- data/lib/fluent/buffer.rb +0 -365
- data/lib/fluent/plugin/filter_parser.rb +0 -107
- data/lib/fluent/plugin/in_status.rb +0 -76
- data/lib/fluent/test/helpers.rb +0 -86
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/test_filter_parser.rb +0 -744
- data/test/plugin/test_in_status.rb +0 -38
- data/test/test_buffer.rb +0 -624
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin_helper/timer'
|
3
|
+
require 'fluent/plugin/base'
|
4
|
+
|
5
|
+
class TimerTest < Test::Unit::TestCase
|
6
|
+
class Dummy < Fluent::Plugin::TestBase
|
7
|
+
helpers :timer
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'can be instantiated under state that timer is not running' do
|
11
|
+
d1 = Dummy.new
|
12
|
+
assert d1.respond_to?(:timer_running?)
|
13
|
+
assert !d1.timer_running?
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'can be configured' do
|
17
|
+
d1 = Dummy.new
|
18
|
+
assert_nothing_raised do
|
19
|
+
d1.configure(config_element())
|
20
|
+
end
|
21
|
+
assert d1.plugin_id
|
22
|
+
assert d1.log
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'can start timers by start' do
|
26
|
+
d1 = Dummy.new
|
27
|
+
d1.configure(config_element())
|
28
|
+
assert !d1.timer_running?
|
29
|
+
d1.start
|
30
|
+
assert d1.timer_running?
|
31
|
+
|
32
|
+
counter = 0
|
33
|
+
d1.timer_execute(:test, 1) do
|
34
|
+
counter += 1
|
35
|
+
end
|
36
|
+
|
37
|
+
sleep 5
|
38
|
+
|
39
|
+
d1.stop
|
40
|
+
assert !d1.timer_running?
|
41
|
+
|
42
|
+
assert{ counter >= 3 && counter <= 6 }
|
43
|
+
|
44
|
+
d1.shutdown; d1.close; d1.terminate
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'can run many timers' do
|
48
|
+
d1 = Dummy.new
|
49
|
+
d1.configure(config_element())
|
50
|
+
d1.start
|
51
|
+
|
52
|
+
counter1 = 0
|
53
|
+
counter2 = 0
|
54
|
+
|
55
|
+
d1.timer_execute(:t1, 1) do
|
56
|
+
counter1 += 1
|
57
|
+
end
|
58
|
+
d1.timer_execute(:t2, 2) do
|
59
|
+
counter2 += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
sleep 6
|
63
|
+
|
64
|
+
d1.stop
|
65
|
+
|
66
|
+
assert{ counter1 >= 4 && counter1 <= 7 }
|
67
|
+
assert{ counter2 >= 2 && counter2 <= 4 }
|
68
|
+
|
69
|
+
d1.shutdown; d1.close; d1.terminate
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'aborts timer which raises exceptions' do
|
73
|
+
d1 = Dummy.new
|
74
|
+
d1.configure(config_element())
|
75
|
+
d1.start
|
76
|
+
|
77
|
+
counter1 = 0
|
78
|
+
counter2 = 0
|
79
|
+
|
80
|
+
d1.timer_execute(:t1, 1) do
|
81
|
+
counter1 += 1
|
82
|
+
end
|
83
|
+
d1.timer_execute(:t2, 1) do
|
84
|
+
raise "abort!!!!!!" if counter2 > 1
|
85
|
+
counter2 += 1
|
86
|
+
end
|
87
|
+
|
88
|
+
sleep 5
|
89
|
+
|
90
|
+
d1.stop
|
91
|
+
|
92
|
+
assert{ counter1 >= 3 && counter1 <= 6 }
|
93
|
+
assert{ counter2 == 2 }
|
94
|
+
msg = "Unexpected error raised. Stopping the timer. title=:t2"
|
95
|
+
assert{ d1.log.out.logs.any?{|line| line.include?("[error]:") && line.include?(msg) && line.include?("abort!!!!!!") } }
|
96
|
+
assert{ d1.log.out.logs.any?{|line| line.include?("[error]:") && line.include?("Timer detached. title=:t2") } }
|
97
|
+
|
98
|
+
d1.shutdown; d1.close; d1.terminate
|
99
|
+
end
|
100
|
+
end
|
data/test/scripts/exec_script.rb
CHANGED
@@ -17,10 +17,6 @@ def gen_raw_string(time)
|
|
17
17
|
"#{time} hello"
|
18
18
|
end
|
19
19
|
|
20
|
-
def gen_invalid_json(time)
|
21
|
-
%({"tag": "tag1", "time": #{time}, "k1": "ok", })
|
22
|
-
end
|
23
|
-
|
24
20
|
time = ARGV.first
|
25
21
|
time = Integer(time) rescue time
|
26
22
|
|
@@ -33,6 +29,4 @@ when 2
|
|
33
29
|
print gen_msgpack(time)
|
34
30
|
when 3
|
35
31
|
print gen_raw_string(time)
|
36
|
-
when 4
|
37
|
-
print gen_invalid_json(time)
|
38
32
|
end
|
@@ -19,6 +19,7 @@ module Fluent
|
|
19
19
|
Plugin.register_output('test', self)
|
20
20
|
|
21
21
|
def initialize
|
22
|
+
super
|
22
23
|
@emit_streams = []
|
23
24
|
@name = nil
|
24
25
|
end
|
@@ -60,9 +61,11 @@ module Fluent
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def start
|
64
|
+
super
|
63
65
|
end
|
64
66
|
|
65
67
|
def shutdown
|
68
|
+
super
|
66
69
|
end
|
67
70
|
|
68
71
|
def emit(tag, es, chain)
|
data/test/test_config.rb
CHANGED
@@ -157,14 +157,23 @@ class ConfigTest < Test::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def test_inline
|
160
|
-
prepare_config
|
160
|
+
prepare_config
|
161
161
|
opts = {
|
162
|
-
|
163
|
-
|
162
|
+
:config_path => "#{TMP_DIR}/config_test_1.conf",
|
163
|
+
:inline_config => "<source>\n type http\n port 2222\n </source>"
|
164
164
|
}
|
165
165
|
assert_nothing_raised do
|
166
166
|
Fluent::Supervisor.new(opts)
|
167
|
-
end
|
167
|
+
end
|
168
|
+
create_warn_dummy_logger
|
169
|
+
end
|
170
|
+
|
171
|
+
def create_warn_dummy_logger
|
172
|
+
dl_opts = {}
|
173
|
+
dl_opts[:log_level] = ServerEngine::DaemonLogger::WARN
|
174
|
+
logdev = Fluent::Test::DummyLogDevice.new
|
175
|
+
logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
|
176
|
+
$log = Fluent::Log.new(logger)
|
168
177
|
end
|
169
178
|
end
|
170
179
|
|
data/test/test_event.rb
CHANGED
@@ -7,7 +7,7 @@ module EventTest
|
|
7
7
|
include Fluent
|
8
8
|
|
9
9
|
def setup
|
10
|
-
@time =
|
10
|
+
@time = event_time()
|
11
11
|
@record = {'k' => 'v', 'n' => 1}
|
12
12
|
@es = OneEventStream.new(@time, @record)
|
13
13
|
end
|
@@ -31,18 +31,27 @@ module EventTest
|
|
31
31
|
|
32
32
|
test 'to_msgpack_stream' do
|
33
33
|
stream = @es.to_msgpack_stream
|
34
|
-
|
34
|
+
Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
|
35
35
|
assert_equal @time, time
|
36
36
|
assert_equal @record, record
|
37
37
|
}
|
38
38
|
end
|
39
|
+
|
40
|
+
test 'to_msgpack_stream with time_int argument' do
|
41
|
+
stream = @es.to_msgpack_stream(time_int: true)
|
42
|
+
Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
|
43
|
+
assert_equal @time.to_i, time
|
44
|
+
assert_equal @record, record
|
45
|
+
}
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
class ArrayEventStreamTest < ::Test::Unit::TestCase
|
42
50
|
include Fluent
|
43
51
|
|
44
52
|
def setup
|
45
|
-
|
53
|
+
time = Engine.now
|
54
|
+
@times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
|
46
55
|
@records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
|
47
56
|
@es = ArrayEventStream.new(@times.zip(@records))
|
48
57
|
end
|
@@ -74,7 +83,7 @@ module EventTest
|
|
74
83
|
test 'to_msgpack_stream' do
|
75
84
|
i = 0
|
76
85
|
stream = @es.to_msgpack_stream
|
77
|
-
|
86
|
+
Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
|
78
87
|
assert_equal @times[i], time
|
79
88
|
assert_equal @records[i], record
|
80
89
|
i += 1
|
@@ -86,11 +95,12 @@ module EventTest
|
|
86
95
|
include Fluent
|
87
96
|
|
88
97
|
def setup
|
89
|
-
|
98
|
+
time = Engine.now
|
99
|
+
@times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
|
90
100
|
@records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
|
91
101
|
@es = MultiEventStream.new
|
92
|
-
@times.zip(@records).each { |
|
93
|
-
@es.add(
|
102
|
+
@times.zip(@records).each { |_time, record|
|
103
|
+
@es.add(_time, record)
|
94
104
|
}
|
95
105
|
end
|
96
106
|
|
@@ -121,7 +131,7 @@ module EventTest
|
|
121
131
|
test 'to_msgpack_stream' do
|
122
132
|
i = 0
|
123
133
|
stream = @es.to_msgpack_stream
|
124
|
-
|
134
|
+
Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
|
125
135
|
assert_equal @times[i], time
|
126
136
|
assert_equal @records[i], record
|
127
137
|
i += 1
|
@@ -133,11 +143,12 @@ module EventTest
|
|
133
143
|
include Fluent
|
134
144
|
|
135
145
|
def setup
|
136
|
-
pk =
|
137
|
-
|
146
|
+
pk = Fluent::Engine.msgpack_factory.packer
|
147
|
+
time = Engine.now
|
148
|
+
@times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)]
|
138
149
|
@records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}]
|
139
|
-
@times.zip(@records).each { |
|
140
|
-
pk.write([
|
150
|
+
@times.zip(@records).each { |_time, record|
|
151
|
+
pk.write([_time, record])
|
141
152
|
}
|
142
153
|
@es = MessagePackEventStream.new(pk.to_s)
|
143
154
|
end
|
@@ -158,7 +169,7 @@ module EventTest
|
|
158
169
|
test 'to_msgpack_stream' do
|
159
170
|
i = 0
|
160
171
|
stream = @es.to_msgpack_stream
|
161
|
-
|
172
|
+
Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record|
|
162
173
|
assert_equal @times[i], time
|
163
174
|
assert_equal @records[i], record
|
164
175
|
i += 1
|
data/test/test_event_router.rb
CHANGED
@@ -97,7 +97,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
97
97
|
|
98
98
|
test 'set one output' do
|
99
99
|
@pipeline.set_output(output)
|
100
|
-
@pipeline.
|
100
|
+
@pipeline.emit_events('test', @es)
|
101
101
|
assert_equal 1, output.events.size
|
102
102
|
assert_equal 'value', output.events['test'].first['key']
|
103
103
|
end
|
@@ -109,7 +109,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
109
109
|
|
110
110
|
test 'set one filer' do
|
111
111
|
@pipeline.add_filter(filter)
|
112
|
-
@pipeline.
|
112
|
+
@pipeline.emit_events('test', @es)
|
113
113
|
assert_equal 1, output.events.size
|
114
114
|
assert_equal 'value', output.events['test'].first['key']
|
115
115
|
assert_equal 0, output.events['test'].first['__test__']
|
@@ -117,7 +117,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
117
117
|
|
118
118
|
test 'set one filer with multi events' do
|
119
119
|
@pipeline.add_filter(filter)
|
120
|
-
@pipeline.
|
120
|
+
@pipeline.emit_events('test', events)
|
121
121
|
assert_equal 1, output.events.size
|
122
122
|
assert_equal 5, output.events['test'].size
|
123
123
|
DEFAULT_EVENT_NUM.times { |i|
|
@@ -140,7 +140,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
140
140
|
sub_test_case 'default collector' do
|
141
141
|
test 'call default collector when no output' do
|
142
142
|
assert_rr do
|
143
|
-
mock(default_collector).
|
143
|
+
mock(default_collector).emit_events('test', is_a(OneEventStream))
|
144
144
|
event_router.emit('test', Engine.now, 'k' => 'v')
|
145
145
|
end
|
146
146
|
end
|
@@ -149,7 +149,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
149
149
|
event_router.add_rule('test', filter)
|
150
150
|
assert_rr do
|
151
151
|
# After apply Filter, EventStream becomes MultiEventStream by default
|
152
|
-
mock(default_collector).
|
152
|
+
mock(default_collector).emit_events('test', is_a(MultiEventStream))
|
153
153
|
event_router.emit('test', Engine.now, 'k' => 'v')
|
154
154
|
end
|
155
155
|
assert_equal 1, filter.num
|
@@ -158,7 +158,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
158
158
|
test "call default collector when no matched with output" do
|
159
159
|
event_router.add_rule('test', output)
|
160
160
|
assert_rr do
|
161
|
-
mock(default_collector).
|
161
|
+
mock(default_collector).emit_events('dummy', is_a(OneEventStream))
|
162
162
|
event_router.emit('dummy', Engine.now, 'k' => 'v')
|
163
163
|
end
|
164
164
|
end
|
@@ -166,7 +166,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
166
166
|
test "don't call default collector when tag matched" do
|
167
167
|
event_router.add_rule('test', output)
|
168
168
|
assert_rr do
|
169
|
-
dont_allow(default_collector).
|
169
|
+
dont_allow(default_collector).emit_events('test', is_a(OneEventStream))
|
170
170
|
event_router.emit('test', Engine.now, 'k' => 'v')
|
171
171
|
end
|
172
172
|
# check emit handler doesn't catch rr error
|
@@ -224,6 +224,7 @@ class EventRouterTest < ::Test::Unit::TestCase
|
|
224
224
|
test 'call handle_emits_error when emit failed' do
|
225
225
|
event_router.add_rule('test', error_output)
|
226
226
|
|
227
|
+
event_router.emit('test', Engine.now, 'k' => 'v')
|
227
228
|
assert_rr do
|
228
229
|
mock(emit_handler).handle_emits_error('test', is_a(OneEventStream), is_a(RuntimeError))
|
229
230
|
event_router.emit('test', Engine.now, 'k' => 'v')
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'timecop'
|
3
|
+
require 'oj'
|
4
|
+
require 'yajl'
|
5
|
+
|
6
|
+
class EventTimeTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
@now = Time.now
|
9
|
+
Timecop.freeze(@now)
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
Timecop.return
|
14
|
+
end
|
15
|
+
|
16
|
+
test '#sec' do
|
17
|
+
assert_equal(1, Fluent::EventTime.new(1, 2).sec)
|
18
|
+
end
|
19
|
+
|
20
|
+
test '#nsec' do
|
21
|
+
assert_equal(2, Fluent::EventTime.new(1, 2).nsec)
|
22
|
+
assert_equal(0, Fluent::EventTime.new(1).nsec)
|
23
|
+
end
|
24
|
+
|
25
|
+
test '#to_int' do
|
26
|
+
assert_equal(1, Fluent::EventTime.new(1, 2).to_int)
|
27
|
+
end
|
28
|
+
|
29
|
+
test '#to_r' do
|
30
|
+
assert_equal(Rational(1_000_000_002, 1_000_000_000), Fluent::EventTime.new(1, 2).to_r)
|
31
|
+
end
|
32
|
+
|
33
|
+
test '#to_s' do
|
34
|
+
time = Fluent::EventTime.new(100)
|
35
|
+
assert_equal('100', time.to_s)
|
36
|
+
assert_equal('100', "#{time}")
|
37
|
+
end
|
38
|
+
|
39
|
+
test '#to_json' do
|
40
|
+
time = Fluent::EventTime.new(100)
|
41
|
+
assert_equal('100', time.to_json)
|
42
|
+
assert_equal('{"time":100}', {'time' => time}.to_json)
|
43
|
+
assert_equal('["tag",100,{"key":"value"}]', ["tag", time, {"key" => "value"}].to_json)
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'JSON.dump' do
|
47
|
+
time = Fluent::EventTime.new(100)
|
48
|
+
assert_equal('100', JSON.dump(time))
|
49
|
+
assert_equal('{"time":100}', JSON.dump({'time' => time}))
|
50
|
+
assert_equal('["tag",100,{"key":"value"}]', JSON.dump(["tag", time, {"key" => "value"}]))
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'Oj.dump' do
|
54
|
+
time = Fluent::EventTime.new(100)
|
55
|
+
assert_equal('100', Oj.dump(time, mode: :compat))
|
56
|
+
assert_equal('{"time":100}', Oj.dump({'time' => time}, mode: :compat))
|
57
|
+
assert_equal('["tag",100,{"key":"value"}]', Oj.dump(["tag", time, {"key" => "value"}], mode: :compat))
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'Yajl.dump' do
|
61
|
+
time = Fluent::EventTime.new(100)
|
62
|
+
assert_equal('100', Yajl.dump(time))
|
63
|
+
assert_equal('{"time":100}', Yajl.dump({'time' => time}))
|
64
|
+
assert_equal('["tag",100,{"key":"value"}]', Yajl.dump(["tag", time, {"key" => "value"}]))
|
65
|
+
end
|
66
|
+
|
67
|
+
test '.from_time' do
|
68
|
+
sec = 1000
|
69
|
+
usec = 2
|
70
|
+
time = Fluent::EventTime.from_time(Time.at(sec, usec))
|
71
|
+
assert_equal(time.sec, sec)
|
72
|
+
assert_equal(time.nsec, usec * 1000)
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'now' do
|
76
|
+
assert_equal(@now.to_i, Fluent::EventTime.now.sec)
|
77
|
+
assert_equal(@now.nsec, Fluent::EventTime.now.nsec)
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'parse' do
|
81
|
+
assert_equal(Time.parse("2011-01-02 13:14:15").to_i, Fluent::EventTime.parse("2011-01-02 13:14:15").sec)
|
82
|
+
assert_equal(Time.parse("2011-01-02 13:14:15").nsec, Fluent::EventTime.parse("2011-01-02 13:14:15").nsec)
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'eq?' do
|
86
|
+
assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 2)))
|
87
|
+
refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 3)))
|
88
|
+
refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 2)))
|
89
|
+
refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 4)))
|
90
|
+
|
91
|
+
assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 1))
|
92
|
+
refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 2))
|
93
|
+
|
94
|
+
assert(Fluent::EventTime.eq?(1, Fluent::EventTime.new(1, 2)))
|
95
|
+
refute(Fluent::EventTime.eq?(2, Fluent::EventTime.new(1, 2)))
|
96
|
+
end
|
97
|
+
|
98
|
+
test '==' do
|
99
|
+
assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 2))
|
100
|
+
assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 3))
|
101
|
+
refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 2))
|
102
|
+
refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 4))
|
103
|
+
|
104
|
+
assert(Fluent::EventTime.new(1, 2) == 1)
|
105
|
+
refute(Fluent::EventTime.new(1, 2) == 2)
|
106
|
+
|
107
|
+
assert(1 == Fluent::EventTime.new(1, 2))
|
108
|
+
refute(2 == Fluent::EventTime.new(1, 2))
|
109
|
+
end
|
110
|
+
|
111
|
+
test '+' do
|
112
|
+
assert_equal(4, Fluent::EventTime.new(1, 2) + Fluent::EventTime.new(3, 4))
|
113
|
+
assert_equal(6, Fluent::EventTime.new(1, 2) + 5)
|
114
|
+
assert_equal(6, 5 + Fluent::EventTime.new(1, 2))
|
115
|
+
end
|
116
|
+
|
117
|
+
test '-' do
|
118
|
+
assert_equal(-2, Fluent::EventTime.new(1, 2) - Fluent::EventTime.new(3, 4))
|
119
|
+
assert_equal(-4, Fluent::EventTime.new(1, 2) - 5)
|
120
|
+
assert_equal(4, 5 - Fluent::EventTime.new(1, 2))
|
121
|
+
end
|
122
|
+
|
123
|
+
test '>' do
|
124
|
+
assert(Fluent::EventTime.new(2) > Fluent::EventTime.new(1))
|
125
|
+
refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(1))
|
126
|
+
refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(2))
|
127
|
+
|
128
|
+
assert(Fluent::EventTime.new(2) > 1)
|
129
|
+
refute(Fluent::EventTime.new(1) > 1)
|
130
|
+
refute(Fluent::EventTime.new(1) > 2)
|
131
|
+
|
132
|
+
assert(2 > Fluent::EventTime.new(1))
|
133
|
+
refute(1 > Fluent::EventTime.new(1))
|
134
|
+
refute(1 > Fluent::EventTime.new(2))
|
135
|
+
end
|
136
|
+
|
137
|
+
test '>=' do
|
138
|
+
assert(Fluent::EventTime.new(2) >= Fluent::EventTime.new(1))
|
139
|
+
assert(Fluent::EventTime.new(1) >= Fluent::EventTime.new(1))
|
140
|
+
refute(Fluent::EventTime.new(1) >= Fluent::EventTime.new(2))
|
141
|
+
|
142
|
+
assert(Fluent::EventTime.new(2) >= 1)
|
143
|
+
assert(Fluent::EventTime.new(1) >= 1)
|
144
|
+
refute(Fluent::EventTime.new(1) >= 2)
|
145
|
+
|
146
|
+
assert(2 >= Fluent::EventTime.new(1))
|
147
|
+
assert(1 >= Fluent::EventTime.new(1))
|
148
|
+
refute(1 >= Fluent::EventTime.new(2))
|
149
|
+
end
|
150
|
+
|
151
|
+
test '<' do
|
152
|
+
assert(Fluent::EventTime.new(1) < Fluent::EventTime.new(2))
|
153
|
+
refute(Fluent::EventTime.new(1) < Fluent::EventTime.new(1))
|
154
|
+
refute(Fluent::EventTime.new(2) < Fluent::EventTime.new(1))
|
155
|
+
|
156
|
+
assert(Fluent::EventTime.new(1) < 2)
|
157
|
+
refute(Fluent::EventTime.new(1) < 1)
|
158
|
+
refute(Fluent::EventTime.new(2) < 1)
|
159
|
+
|
160
|
+
assert(1 < Fluent::EventTime.new(2))
|
161
|
+
refute(1 < Fluent::EventTime.new(1))
|
162
|
+
refute(2 < Fluent::EventTime.new(1))
|
163
|
+
end
|
164
|
+
|
165
|
+
test '=<' do
|
166
|
+
assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(2))
|
167
|
+
assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(1))
|
168
|
+
refute(Fluent::EventTime.new(2) <= Fluent::EventTime.new(1))
|
169
|
+
|
170
|
+
assert(Fluent::EventTime.new(1) <= 2)
|
171
|
+
assert(Fluent::EventTime.new(1) <= 1)
|
172
|
+
refute(Fluent::EventTime.new(2) <= 1)
|
173
|
+
|
174
|
+
assert(1 <= Fluent::EventTime.new(2))
|
175
|
+
assert(1 <= Fluent::EventTime.new(1))
|
176
|
+
refute(2 <= Fluent::EventTime.new(1))
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'Time.at' do
|
180
|
+
sec = 1000
|
181
|
+
nsec = 2000
|
182
|
+
ntime = Fluent::EventTime.new(sec, nsec)
|
183
|
+
time = Time.at(ntime)
|
184
|
+
assert_equal(sec, time.to_i)
|
185
|
+
assert_equal(nsec, time.nsec)
|
186
|
+
end
|
187
|
+
end
|