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,265 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/buffer/memory_chunk'
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class BufferMemoryChunkTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
@c = Fluent::Plugin::Buffer::MemoryChunk.new(Object.new)
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'has blank chunk initially' do
|
12
|
+
assert @c.empty?
|
13
|
+
assert_equal '', @c.instance_eval{ @chunk }
|
14
|
+
assert_equal 0, @c.instance_eval{ @chunk_bytes }
|
15
|
+
assert_equal 0, @c.instance_eval{ @adding_bytes }
|
16
|
+
assert_equal 0, @c.instance_eval{ @adding_size }
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'can #append, #commit and #read it' do
|
20
|
+
assert @c.empty?
|
21
|
+
|
22
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
23
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
24
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
25
|
+
@c.append(data)
|
26
|
+
@c.commit
|
27
|
+
|
28
|
+
content = @c.read
|
29
|
+
ds = content.split("\n").select{|d| !d.empty? }
|
30
|
+
|
31
|
+
assert_equal 2, ds.size
|
32
|
+
assert_equal d1, JSON.parse(ds[0])
|
33
|
+
assert_equal d2, JSON.parse(ds[1])
|
34
|
+
|
35
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
36
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
37
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
38
|
+
@c.commit
|
39
|
+
|
40
|
+
content = @c.read
|
41
|
+
ds = content.split("\n").select{|d| !d.empty? }
|
42
|
+
|
43
|
+
assert_equal 4, ds.size
|
44
|
+
assert_equal d1, JSON.parse(ds[0])
|
45
|
+
assert_equal d2, JSON.parse(ds[1])
|
46
|
+
assert_equal d3, JSON.parse(ds[2])
|
47
|
+
assert_equal d4, JSON.parse(ds[3])
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'can #concat, #commit and #read it' do
|
51
|
+
assert @c.empty?
|
52
|
+
|
53
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
54
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
55
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"].join
|
56
|
+
@c.concat(data, 2)
|
57
|
+
@c.commit
|
58
|
+
|
59
|
+
content = @c.read
|
60
|
+
ds = content.split("\n").select{|d| !d.empty? }
|
61
|
+
|
62
|
+
assert_equal 2, ds.size
|
63
|
+
assert_equal d1, JSON.parse(ds[0])
|
64
|
+
assert_equal d2, JSON.parse(ds[1])
|
65
|
+
|
66
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
67
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
68
|
+
@c.concat([d3.to_json + "\n", d4.to_json + "\n"].join, 2)
|
69
|
+
@c.commit
|
70
|
+
|
71
|
+
content = @c.read
|
72
|
+
ds = content.split("\n").select{|d| !d.empty? }
|
73
|
+
|
74
|
+
assert_equal 4, ds.size
|
75
|
+
assert_equal d1, JSON.parse(ds[0])
|
76
|
+
assert_equal d2, JSON.parse(ds[1])
|
77
|
+
assert_equal d3, JSON.parse(ds[2])
|
78
|
+
assert_equal d4, JSON.parse(ds[3])
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'has its contents in binary (ascii-8bit)' do
|
82
|
+
data1 = "aaa bbb ccc".force_encoding('utf-8')
|
83
|
+
@c.append([data1])
|
84
|
+
@c.commit
|
85
|
+
assert_equal Encoding::ASCII_8BIT, @c.instance_eval{ @chunk.encoding }
|
86
|
+
|
87
|
+
content = @c.read
|
88
|
+
assert_equal Encoding::ASCII_8BIT, content.encoding
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'has #bytesize and #size' do
|
92
|
+
assert @c.empty?
|
93
|
+
|
94
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
95
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
96
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
97
|
+
@c.append(data)
|
98
|
+
|
99
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
100
|
+
assert_equal 2, @c.size
|
101
|
+
|
102
|
+
@c.commit
|
103
|
+
|
104
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
105
|
+
assert_equal 2, @c.size
|
106
|
+
|
107
|
+
first_bytesize = @c.bytesize
|
108
|
+
|
109
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
110
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
111
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
112
|
+
|
113
|
+
assert_equal first_bytesize + (d3.to_json + "\n" + d4.to_json + "\n").bytesize, @c.bytesize
|
114
|
+
assert_equal 4, @c.size
|
115
|
+
|
116
|
+
@c.commit
|
117
|
+
|
118
|
+
assert_equal first_bytesize + (d3.to_json + "\n" + d4.to_json + "\n").bytesize, @c.bytesize
|
119
|
+
assert_equal 4, @c.size
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'can #rollback to revert non-committed data' do
|
123
|
+
assert @c.empty?
|
124
|
+
|
125
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
126
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
127
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
128
|
+
@c.append(data)
|
129
|
+
|
130
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
131
|
+
assert_equal 2, @c.size
|
132
|
+
|
133
|
+
@c.rollback
|
134
|
+
|
135
|
+
assert @c.empty?
|
136
|
+
|
137
|
+
assert @c.empty?
|
138
|
+
|
139
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
140
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
141
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
142
|
+
@c.append(data)
|
143
|
+
@c.commit
|
144
|
+
|
145
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
146
|
+
assert_equal 2, @c.size
|
147
|
+
|
148
|
+
first_bytesize = @c.bytesize
|
149
|
+
|
150
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
151
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
152
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
153
|
+
|
154
|
+
assert_equal first_bytesize + (d3.to_json + "\n" + d4.to_json + "\n").bytesize, @c.bytesize
|
155
|
+
assert_equal 4, @c.size
|
156
|
+
|
157
|
+
@c.rollback
|
158
|
+
|
159
|
+
assert_equal first_bytesize, @c.bytesize
|
160
|
+
assert_equal 2, @c.size
|
161
|
+
end
|
162
|
+
|
163
|
+
test 'can #rollback to revert non-committed data from #concat' do
|
164
|
+
assert @c.empty?
|
165
|
+
|
166
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
167
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
168
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"].join
|
169
|
+
@c.concat(data, 2)
|
170
|
+
|
171
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
172
|
+
assert_equal 2, @c.size
|
173
|
+
|
174
|
+
@c.rollback
|
175
|
+
|
176
|
+
assert @c.empty?
|
177
|
+
|
178
|
+
assert @c.empty?
|
179
|
+
|
180
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
181
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
182
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
183
|
+
@c.append(data)
|
184
|
+
@c.commit
|
185
|
+
|
186
|
+
assert_equal (d1.to_json + "\n" + d2.to_json + "\n").bytesize, @c.bytesize
|
187
|
+
assert_equal 2, @c.size
|
188
|
+
|
189
|
+
first_bytesize = @c.bytesize
|
190
|
+
|
191
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
192
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
193
|
+
@c.concat([d3.to_json + "\n", d4.to_json + "\n"].join, 2)
|
194
|
+
|
195
|
+
assert_equal first_bytesize + (d3.to_json + "\n" + d4.to_json + "\n").bytesize, @c.bytesize
|
196
|
+
assert_equal 4, @c.size
|
197
|
+
|
198
|
+
@c.rollback
|
199
|
+
|
200
|
+
assert_equal first_bytesize, @c.bytesize
|
201
|
+
assert_equal 2, @c.size
|
202
|
+
end
|
203
|
+
|
204
|
+
test 'does nothing for #close' do
|
205
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
206
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
207
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
208
|
+
@c.append(data)
|
209
|
+
@c.commit
|
210
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
211
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
212
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
213
|
+
@c.commit
|
214
|
+
|
215
|
+
content = @c.read
|
216
|
+
|
217
|
+
@c.close
|
218
|
+
|
219
|
+
assert_equal content, @c.read
|
220
|
+
end
|
221
|
+
|
222
|
+
test 'deletes all data by #purge' do
|
223
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
224
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
225
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
226
|
+
@c.append(data)
|
227
|
+
@c.commit
|
228
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
229
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
230
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
231
|
+
@c.commit
|
232
|
+
|
233
|
+
@c.purge
|
234
|
+
|
235
|
+
assert @c.empty?
|
236
|
+
assert_equal 0, @c.bytesize
|
237
|
+
assert_equal 0, @c.size
|
238
|
+
assert_equal '', @c.read
|
239
|
+
end
|
240
|
+
|
241
|
+
test 'can #open its contents as io' do
|
242
|
+
d1 = {"f1" => 'v1', "f2" => 'v2', "f3" => 'v3'}
|
243
|
+
d2 = {"f1" => 'vv1', "f2" => 'vv2', "f3" => 'vv3'}
|
244
|
+
data = [d1.to_json + "\n", d2.to_json + "\n"]
|
245
|
+
@c.append(data)
|
246
|
+
@c.commit
|
247
|
+
d3 = {"f1" => 'x', "f2" => 'y', "f3" => 'z'}
|
248
|
+
d4 = {"f1" => 'a', "f2" => 'b', "f3" => 'c'}
|
249
|
+
@c.append([d3.to_json + "\n", d4.to_json + "\n"])
|
250
|
+
@c.commit
|
251
|
+
|
252
|
+
lines = []
|
253
|
+
@c.open do |io|
|
254
|
+
assert io
|
255
|
+
io.readlines.each do |l|
|
256
|
+
lines << l
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
assert_equal d1.to_json + "\n", lines[0]
|
261
|
+
assert_equal d2.to_json + "\n", lines[1]
|
262
|
+
assert_equal d3.to_json + "\n", lines[2]
|
263
|
+
assert_equal d4.to_json + "\n", lines[3]
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/filter'
|
3
|
+
require 'fluent/event'
|
4
|
+
require 'flexmock/test_unit'
|
5
|
+
|
6
|
+
module FluentPluginFilterTest
|
7
|
+
class DummyPlugin < Fluent::Plugin::Filter
|
8
|
+
end
|
9
|
+
class NumDoublePlugin < Fluent::Plugin::Filter
|
10
|
+
def filter(tag, time, record)
|
11
|
+
r = record.dup
|
12
|
+
r["num"] = r["num"].to_i * 2
|
13
|
+
r
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class IgnoreForNumPlugin < Fluent::Plugin::Filter
|
17
|
+
def filter(tag, time, record)
|
18
|
+
if record["num"].is_a? Numeric
|
19
|
+
nil
|
20
|
+
else
|
21
|
+
record
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class RaiseForNumPlugin < Fluent::Plugin::Filter
|
26
|
+
def filter(tag, time, record)
|
27
|
+
if record["num"].is_a? Numeric
|
28
|
+
raise "Value of num is Number!"
|
29
|
+
end
|
30
|
+
record
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class FilterPluginTest < Test::Unit::TestCase
|
36
|
+
DummyRouter = Struct.new(:emits) do
|
37
|
+
def emit_error_event(tag, time, record, error)
|
38
|
+
self.emits << [tag, time, record, error]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
teardown do
|
43
|
+
if @p
|
44
|
+
@p.stop unless @p.stopped?
|
45
|
+
@p.before_shutdown unless @p.before_shutdown?
|
46
|
+
@p.shutdown unless @p.shutdown?
|
47
|
+
@p.after_shutdown unless @p.after_shutdown?
|
48
|
+
@p.close unless @p.closed?
|
49
|
+
@p.terminate unless @p.terminated?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
sub_test_case 'for basic dummy plugin' do
|
54
|
+
setup do
|
55
|
+
Fluent::Test.setup
|
56
|
+
@p = FluentPluginFilterTest::DummyPlugin.new
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'has healthy lifecycle' do
|
60
|
+
assert !@p.configured?
|
61
|
+
@p.configure(config_element())
|
62
|
+
assert @p.configured?
|
63
|
+
|
64
|
+
assert !@p.started?
|
65
|
+
@p.start
|
66
|
+
assert @p.start
|
67
|
+
|
68
|
+
assert !@p.stopped?
|
69
|
+
@p.stop
|
70
|
+
assert @p.stopped?
|
71
|
+
|
72
|
+
assert !@p.before_shutdown?
|
73
|
+
@p.before_shutdown
|
74
|
+
assert @p.before_shutdown?
|
75
|
+
|
76
|
+
assert !@p.shutdown?
|
77
|
+
@p.shutdown
|
78
|
+
assert @p.shutdown?
|
79
|
+
|
80
|
+
assert !@p.after_shutdown?
|
81
|
+
@p.after_shutdown
|
82
|
+
assert @p.after_shutdown?
|
83
|
+
|
84
|
+
assert !@p.closed?
|
85
|
+
@p.close
|
86
|
+
assert @p.closed?
|
87
|
+
|
88
|
+
assert !@p.terminated?
|
89
|
+
@p.terminate
|
90
|
+
assert @p.terminated?
|
91
|
+
end
|
92
|
+
|
93
|
+
test 'has plugin_id automatically generated' do
|
94
|
+
assert @p.respond_to?(:plugin_id_configured?)
|
95
|
+
assert @p.respond_to?(:plugin_id)
|
96
|
+
|
97
|
+
@p.configure(config_element())
|
98
|
+
|
99
|
+
assert !@p.plugin_id_configured?
|
100
|
+
assert @p.plugin_id
|
101
|
+
assert{ @p.plugin_id != 'mytest' }
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'has plugin_id manually configured' do
|
105
|
+
@p.configure(config_element('ROOT', '', {'@id' => 'mytest'}))
|
106
|
+
assert @p.plugin_id_configured?
|
107
|
+
assert_equal 'mytest', @p.plugin_id
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'has plugin logger' do
|
111
|
+
assert @p.respond_to?(:log)
|
112
|
+
assert @p.log
|
113
|
+
|
114
|
+
# default logger
|
115
|
+
original_logger = @p.log
|
116
|
+
|
117
|
+
@p.configure(config_element('ROOT', '', {'@log_level' => 'debug'}))
|
118
|
+
|
119
|
+
assert{ @p.log.object_id != original_logger.object_id }
|
120
|
+
assert_equal Fluent::Log::LEVEL_DEBUG, @p.log.level
|
121
|
+
end
|
122
|
+
|
123
|
+
test 'can load plugin helpers' do
|
124
|
+
assert_nothing_raised do
|
125
|
+
class FluentPluginFilterTest::DummyPlugin2 < Fluent::Plugin::Filter
|
126
|
+
helpers :storage
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'plugin does not define #filter raises error' do
|
132
|
+
es = [
|
133
|
+
[event_time('2016-04-19 13:01:00 -0700'), {"num" => "1", "message" => "Hello filters!"}],
|
134
|
+
[event_time('2016-04-19 13:01:03 -0700'), {"num" => "2", "message" => "Hello filters!"}],
|
135
|
+
[event_time('2016-04-19 13:01:05 -0700'), {"num" => "3", "message" => "Hello filters!"}],
|
136
|
+
]
|
137
|
+
assert_raise NotImplementedError do
|
138
|
+
@p.filter_stream('testing', es)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sub_test_case 'normal filter plugin' do
|
144
|
+
setup do
|
145
|
+
Fluent::Test.setup
|
146
|
+
@p = FluentPluginFilterTest::NumDoublePlugin.new
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'filters events correctly' do
|
150
|
+
test_es = [
|
151
|
+
[event_time('2016-04-19 13:01:00 -0700'), {"num" => "1", "message" => "Hello filters!"}],
|
152
|
+
[event_time('2016-04-19 13:01:03 -0700'), {"num" => "2", "message" => "Hello filters!"}],
|
153
|
+
[event_time('2016-04-19 13:01:05 -0700'), {"num" => "3", "message" => "Hello filters!"}],
|
154
|
+
]
|
155
|
+
es = @p.filter_stream('testing', test_es)
|
156
|
+
assert es.is_a? Fluent::EventStream
|
157
|
+
|
158
|
+
ary = []
|
159
|
+
es.each do |time, r|
|
160
|
+
ary << [time, r]
|
161
|
+
end
|
162
|
+
|
163
|
+
assert_equal 3, ary.size
|
164
|
+
|
165
|
+
assert_equal event_time('2016-04-19 13:01:00 -0700'), ary[0][0]
|
166
|
+
assert_equal "Hello filters!", ary[0][1]["message"]
|
167
|
+
assert_equal 2, ary[0][1]["num"]
|
168
|
+
|
169
|
+
assert_equal event_time('2016-04-19 13:01:03 -0700'), ary[1][0]
|
170
|
+
assert_equal 4, ary[1][1]["num"]
|
171
|
+
|
172
|
+
assert_equal event_time('2016-04-19 13:01:05 -0700'), ary[2][0]
|
173
|
+
assert_equal 6, ary[2][1]["num"]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
sub_test_case 'filter plugin returns nil for some records' do
|
178
|
+
setup do
|
179
|
+
Fluent::Test.setup
|
180
|
+
@p = FluentPluginFilterTest::IgnoreForNumPlugin.new
|
181
|
+
end
|
182
|
+
|
183
|
+
test 'filter_stream ignores records which #filter return nil' do
|
184
|
+
test_es = [
|
185
|
+
[event_time('2016-04-19 13:01:00 -0700'), {"num" => "1", "message" => "Hello filters!"}],
|
186
|
+
[event_time('2016-04-19 13:01:03 -0700'), {"num" => 2, "message" => "Ignored, yay!"}],
|
187
|
+
[event_time('2016-04-19 13:01:05 -0700'), {"num" => "3", "message" => "Hello filters!"}],
|
188
|
+
]
|
189
|
+
es = @p.filter_stream('testing', test_es)
|
190
|
+
assert es.is_a? Fluent::EventStream
|
191
|
+
|
192
|
+
ary = []
|
193
|
+
es.each do |time, r|
|
194
|
+
ary << [time, r]
|
195
|
+
end
|
196
|
+
|
197
|
+
assert_equal 2, ary.size
|
198
|
+
|
199
|
+
assert_equal event_time('2016-04-19 13:01:00 -0700'), ary[0][0]
|
200
|
+
assert_equal "Hello filters!", ary[0][1]["message"]
|
201
|
+
assert_equal "1", ary[0][1]["num"]
|
202
|
+
|
203
|
+
assert_equal event_time('2016-04-19 13:01:05 -0700'), ary[1][0]
|
204
|
+
assert_equal "3", ary[1][1]["num"]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
sub_test_case 'filter plugin raises error' do
|
209
|
+
setup do
|
210
|
+
Fluent::Test.setup
|
211
|
+
@p = FluentPluginFilterTest::RaiseForNumPlugin.new
|
212
|
+
end
|
213
|
+
|
214
|
+
test 'has router and can emit events to error streams' do
|
215
|
+
assert @p.has_router?
|
216
|
+
|
217
|
+
@p.configure(config_element())
|
218
|
+
assert @p.router
|
219
|
+
|
220
|
+
@p.router = DummyRouter.new([])
|
221
|
+
|
222
|
+
test_es = [
|
223
|
+
[event_time('2016-04-19 13:01:00 -0700'), {"num" => "1", "message" => "Hello filters!"}],
|
224
|
+
[event_time('2016-04-19 13:01:03 -0700'), {"num" => 2, "message" => "Hello error router!"}],
|
225
|
+
[event_time('2016-04-19 13:01:05 -0700'), {"num" => "3", "message" => "Hello filters!"}],
|
226
|
+
]
|
227
|
+
es = @p.filter_stream('testing', test_es)
|
228
|
+
assert es.is_a? Fluent::EventStream
|
229
|
+
|
230
|
+
ary = []
|
231
|
+
es.each do |time, r|
|
232
|
+
ary << [time, r]
|
233
|
+
end
|
234
|
+
|
235
|
+
assert_equal 2, ary.size
|
236
|
+
|
237
|
+
assert_equal event_time('2016-04-19 13:01:00 -0700'), ary[0][0]
|
238
|
+
assert_equal "Hello filters!", ary[0][1]["message"]
|
239
|
+
assert_equal "1", ary[0][1]["num"]
|
240
|
+
|
241
|
+
assert_equal event_time('2016-04-19 13:01:05 -0700'), ary[1][0]
|
242
|
+
assert_equal "3", ary[1][1]["num"]
|
243
|
+
|
244
|
+
assert_equal 1, @p.router.emits.size
|
245
|
+
|
246
|
+
error_emits = @p.router.emits
|
247
|
+
|
248
|
+
assert_equal "testing", error_emits[0][0]
|
249
|
+
assert_equal event_time('2016-04-19 13:01:03 -0700'), error_emits[0][1]
|
250
|
+
assert_equal({"num" => 2, "message" => "Hello error router!"}, error_emits[0][2])
|
251
|
+
assert{ error_emits[0][3].is_a? RuntimeError }
|
252
|
+
assert_equal "Value of num is Number!", error_emits[0][3].message
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|