fluentd 0.14.4-x86-mingw32
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 +7 -0
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +26 -0
- data/.travis.yml +45 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +35 -0
- data/COPYING +14 -0
- data/ChangeLog +276 -0
- data/Gemfile +9 -0
- data/README.md +51 -0
- data/Rakefile +53 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +41 -0
- data/bin/fluent-debug +5 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_forward.conf +11 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_buffered_null.conf +32 -0
- data/example/out_copy.conf +20 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +194 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +319 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +273 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +49 -0
- data/lib/fluent/compat/output.rb +677 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +180 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +366 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +212 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +176 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +220 -0
- data/lib/fluent/env.rb +27 -0
- data/lib/fluent/event.rb +287 -0
- data/lib/fluent/event_router.rb +259 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +38 -0
- data/lib/fluent/load.rb +36 -0
- data/lib/fluent/log.rb +445 -0
- data/lib/fluent/match.rb +141 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +26 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +161 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +130 -0
- data/lib/fluent/plugin/buf_file.rb +154 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +603 -0
- data/lib/fluent/plugin/buffer/chunk.rb +160 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +342 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +45 -0
- data/lib/fluent/plugin/formatter_csv.rb +47 -0
- data/lib/fluent/plugin/formatter_hash.rb +29 -0
- data/lib/fluent/plugin/formatter_json.rb +44 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
- data/lib/fluent/plugin/formatter_out_file.rb +78 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +74 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +135 -0
- data/lib/fluent/plugin/in_exec.rb +149 -0
- data/lib/fluent/plugin/in_forward.rb +366 -0
- data/lib/fluent/plugin/in_gc_stat.rb +52 -0
- data/lib/fluent/plugin/in_http.rb +422 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
- data/lib/fluent/plugin/in_object_space.rb +90 -0
- data/lib/fluent/plugin/in_syslog.rb +204 -0
- data/lib/fluent/plugin/in_tail.rb +838 -0
- data/lib/fluent/plugin/in_tcp.rb +41 -0
- data/lib/fluent/plugin/in_udp.rb +37 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- 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_buffered_stdout.rb +70 -0
- data/lib/fluent/plugin/out_copy.rb +42 -0
- data/lib/fluent/plugin/out_exec.rb +114 -0
- data/lib/fluent/plugin/out_exec_filter.rb +393 -0
- data/lib/fluent/plugin/out_file.rb +167 -0
- data/lib/fluent/plugin/out_forward.rb +646 -0
- data/lib/fluent/plugin/out_null.rb +27 -0
- data/lib/fluent/plugin/out_relabel.rb +28 -0
- data/lib/fluent/plugin/out_roundrobin.rb +80 -0
- data/lib/fluent/plugin/out_stdout.rb +48 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1020 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +175 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +33 -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 +104 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +73 -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 +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +132 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +42 -0
- data/lib/fluent/plugin_helper/child_process.rb +298 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +224 -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/formatter.rb +149 -0
- data/lib/fluent/plugin_helper/inject.rb +125 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +177 -0
- data/lib/fluent/plugin_helper/storage.rb +331 -0
- data/lib/fluent/plugin_helper/thread.rb +147 -0
- data/lib/fluent/plugin_helper/timer.rb +90 -0
- data/lib/fluent/plugin_id.rb +63 -0
- data/lib/fluent/process.rb +504 -0
- data/lib/fluent/registry.rb +99 -0
- data/lib/fluent/root_agent.rb +314 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +680 -0
- data/lib/fluent/system_config.rb +122 -0
- data/lib/fluent/test.rb +56 -0
- data/lib/fluent/test/base.rb +85 -0
- data/lib/fluent/test/driver/base.rb +179 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +125 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +52 -0
- data/lib/fluent/test/driver/output.rb +76 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +79 -0
- data/lib/fluent/test/input_test.rb +172 -0
- data/lib/fluent/test/log.rb +73 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/time.rb +175 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +82 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +507 -0
- data/test/config/test_configurable.rb +1194 -0
- data/test/config/test_configure_proxy.rb +386 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +120 -0
- data/test/config/test_types.rb +171 -0
- data/test/helper.rb +119 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +75 -0
- data/test/plugin/test_buf_file.rb +571 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1200 -0
- data/test/plugin/test_buffer_chunk.rb +168 -0
- data/test/plugin/test_buffer_file_chunk.rb +771 -0
- data/test/plugin/test_buffer_memory_chunk.rb +265 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +353 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_record_transformer.rb +600 -0
- data/test/plugin/test_filter_stdout.rb +211 -0
- data/test/plugin/test_formatter_csv.rb +94 -0
- data/test/plugin/test_formatter_json.rb +30 -0
- data/test/plugin/test_formatter_ltsv.rb +52 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +188 -0
- data/test/plugin/test_in_exec.rb +133 -0
- data/test/plugin/test_in_forward.rb +635 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +442 -0
- data/test/plugin/test_in_monitor_agent.rb +329 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +205 -0
- data/test/plugin/test_in_tail.rb +1001 -0
- data/test/plugin/test_in_tcp.rb +102 -0
- data/test/plugin/test_in_udp.rb +121 -0
- data/test/plugin/test_in_unix.rb +126 -0
- 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_buffered_stdout.rb +122 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +155 -0
- data/test/plugin/test_out_exec_filter.rb +262 -0
- data/test/plugin/test_out_file.rb +383 -0
- data/test/plugin/test_out_forward.rb +590 -0
- data/test/plugin/test_out_null.rb +29 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_stdout.rb +92 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +568 -0
- data/test/plugin/test_output_as_buffered.rb +1604 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +817 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +38 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_base.rb +32 -0
- data/test/plugin/test_parser_csv.rb +104 -0
- data/test/plugin/test_parser_json.rb +107 -0
- data/test/plugin/test_parser_labeled_tsv.rb +129 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +53 -0
- data/test/plugin/test_parser_regexp.rb +277 -0
- data/test/plugin/test_parser_syslog.rb +66 -0
- data/test/plugin/test_parser_time.rb +46 -0
- data/test/plugin/test_parser_tsv.rb +121 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +8 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +608 -0
- data/test/plugin_helper/test_compat_parameters.rb +242 -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_formatter.rb +252 -0
- data/test/plugin_helper/test_inject.rb +487 -0
- data/test/plugin_helper/test_parser.rb +263 -0
- data/test/plugin_helper/test_retry_state.rb +399 -0
- data/test/plugin_helper/test_storage.rb +521 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +131 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +329 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +184 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +319 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +572 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +214 -0
- data/test/test_plugin_classes.rb +136 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_process.rb +48 -0
- data/test/test_root_agent.rb +278 -0
- data/test/test_supervisor.rb +339 -0
- data/test/test_time_formatter.rb +186 -0
- data/test/test_unique_id.rb +47 -0
- metadata +823 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/filter_grep'
|
3
|
+
require 'fluent/test/driver/filter'
|
4
|
+
|
5
|
+
class GrepFilterTest < Test::Unit::TestCase
|
6
|
+
include Fluent
|
7
|
+
|
8
|
+
setup do
|
9
|
+
Fluent::Test.setup
|
10
|
+
@time = event_time
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_driver(conf = '')
|
14
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::GrepFilter).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
sub_test_case 'configure' do
|
18
|
+
test 'check default' do
|
19
|
+
d = create_driver
|
20
|
+
assert_empty(d.instance.regexps)
|
21
|
+
assert_empty(d.instance.excludes)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "regexpN can contain a space" do
|
25
|
+
d = create_driver(%[regexp1 message foo])
|
26
|
+
assert_equal(Regexp.compile(/ foo/), d.instance.regexps['message'])
|
27
|
+
end
|
28
|
+
|
29
|
+
test "excludeN can contain a space" do
|
30
|
+
d = create_driver(%[exclude1 message foo])
|
31
|
+
assert_equal(Regexp.compile(/ foo/), d.instance.excludes['message'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
sub_test_case 'filter_stream' do
|
36
|
+
def messages
|
37
|
+
[
|
38
|
+
"2013/01/13T07:02:11.124202 INFO GET /ping",
|
39
|
+
"2013/01/13T07:02:13.232645 WARN POST /auth",
|
40
|
+
"2013/01/13T07:02:21.542145 WARN GET /favicon.ico",
|
41
|
+
"2013/01/13T07:02:43.632145 WARN POST /login",
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def filter(config, msgs)
|
46
|
+
d = create_driver(config)
|
47
|
+
d.run {
|
48
|
+
msgs.each { |msg|
|
49
|
+
d.feed("filter.test", @time, {'foo' => 'bar', 'message' => msg})
|
50
|
+
}
|
51
|
+
}
|
52
|
+
d.filtered_records
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'empty config' do
|
56
|
+
filtered_records = filter('', messages)
|
57
|
+
assert_equal(4, filtered_records.size)
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'regexpN' do
|
61
|
+
filtered_records = filter('regexp1 message WARN', messages)
|
62
|
+
assert_equal(3, filtered_records.size)
|
63
|
+
assert_block('only WARN logs') do
|
64
|
+
filtered_records.all? { |r|
|
65
|
+
!r['message'].include?('INFO')
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'excludeN' do
|
71
|
+
filtered_records = filter('exclude1 message favicon', messages)
|
72
|
+
assert_equal(3, filtered_records.size)
|
73
|
+
assert_block('remove favicon logs') do
|
74
|
+
filtered_records.all? { |r|
|
75
|
+
!r['message'].include?('favicon')
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
sub_test_case 'with invalid sequence' do
|
81
|
+
def messages
|
82
|
+
[
|
83
|
+
"\xff".force_encoding('UTF-8'),
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
test "don't raise an exception" do
|
88
|
+
assert_nothing_raised {
|
89
|
+
filter(%[regexp1 message WARN], ["\xff".force_encoding('UTF-8')])
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
sub_test_case 'grep non-string jsonable values' do
|
96
|
+
def filter(msg, config = 'regexp1 message 0')
|
97
|
+
d = create_driver(config)
|
98
|
+
d.run do
|
99
|
+
d.feed("filter.test", @time, {'foo' => 'bar', 'message' => msg})
|
100
|
+
end
|
101
|
+
d.filtered_records
|
102
|
+
end
|
103
|
+
|
104
|
+
data(
|
105
|
+
'array' => ["0"],
|
106
|
+
'hash' => ["0" => "0"],
|
107
|
+
'integer' => 0,
|
108
|
+
'float' => 0.1)
|
109
|
+
test "value" do |data|
|
110
|
+
filtered_records = filter(data)
|
111
|
+
assert_equal(1, filtered_records.size)
|
112
|
+
end
|
113
|
+
|
114
|
+
test "value boolean" do
|
115
|
+
filtered_records = filter(true, %[regexp1 message true])
|
116
|
+
assert_equal(1, filtered_records.size)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,600 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'timecop'
|
3
|
+
require 'fluent/test/driver/filter'
|
4
|
+
require 'fluent/plugin/filter_record_transformer'
|
5
|
+
|
6
|
+
class RecordTransformerFilterTest < Test::Unit::TestCase
|
7
|
+
include Fluent
|
8
|
+
|
9
|
+
setup do
|
10
|
+
Test.setup
|
11
|
+
@hostname = Socket.gethostname.chomp
|
12
|
+
@tag = 'test.tag'
|
13
|
+
@tag_parts = @tag.split('.')
|
14
|
+
@time = event_time('2010-05-04 03:02:01 UTC')
|
15
|
+
Timecop.freeze(@time)
|
16
|
+
end
|
17
|
+
|
18
|
+
teardown do
|
19
|
+
Timecop.return
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_driver(conf = '')
|
23
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::RecordTransformerFilter).configure(conf)
|
24
|
+
end
|
25
|
+
|
26
|
+
sub_test_case 'configure' do
|
27
|
+
test 'check default' do
|
28
|
+
assert_nothing_raised do
|
29
|
+
create_driver
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "keep_keys must be specified together with renew_record true" do
|
34
|
+
assert_raise(Fluent::ConfigError) do
|
35
|
+
create_driver(%[keep_keys a])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
sub_test_case "test options" do
|
41
|
+
def filter(config, msgs = [''])
|
42
|
+
d = create_driver(config)
|
43
|
+
d.run {
|
44
|
+
msgs.each { |msg|
|
45
|
+
d.feed(@tag, @time, {'foo' => 'bar', 'message' => msg})
|
46
|
+
}
|
47
|
+
}
|
48
|
+
d.filtered
|
49
|
+
end
|
50
|
+
|
51
|
+
CONFIG = %[
|
52
|
+
<record>
|
53
|
+
hostname ${hostname}
|
54
|
+
tag ${tag}
|
55
|
+
time ${time}
|
56
|
+
message ${hostname} ${tag_parts[-1]} ${message}
|
57
|
+
</record>
|
58
|
+
]
|
59
|
+
|
60
|
+
test 'typical usage' do
|
61
|
+
msgs = ['1', '2']
|
62
|
+
filtered = filter(CONFIG, msgs)
|
63
|
+
filtered.each_with_index do |(_t, r), i|
|
64
|
+
assert_equal('bar', r['foo'])
|
65
|
+
assert_equal(@hostname, r['hostname'])
|
66
|
+
assert_equal(@tag, r['tag'])
|
67
|
+
assert_equal(Time.at(@time).localtime.to_s, r['time'])
|
68
|
+
assert_equal("#{@hostname} #{@tag_parts[-1]} #{msgs[i]}", r['message'])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'remove_keys' do
|
73
|
+
config = CONFIG + %[remove_keys foo,message]
|
74
|
+
filtered = filter(config)
|
75
|
+
filtered.each_with_index do |(_t, r), i|
|
76
|
+
assert_not_include(r, 'foo')
|
77
|
+
assert_equal(@hostname, r['hostname'])
|
78
|
+
assert_equal(@tag, r['tag'])
|
79
|
+
assert_equal(Time.at(@time).localtime.to_s, r['time'])
|
80
|
+
assert_not_include(r, 'message')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'renew_record' do
|
85
|
+
config = CONFIG + %[renew_record true]
|
86
|
+
msgs = ['1', '2']
|
87
|
+
filtered = filter(config, msgs)
|
88
|
+
filtered.each_with_index do |(_t, r), i|
|
89
|
+
assert_not_include(r, 'foo')
|
90
|
+
assert_equal(@hostname, r['hostname'])
|
91
|
+
assert_equal(@tag, r['tag'])
|
92
|
+
assert_equal(Time.at(@time).localtime.to_s, r['time'])
|
93
|
+
assert_equal("#{@hostname} #{@tag_parts[-1]} #{msgs[i]}", r['message'])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'renew_time_key' do
|
98
|
+
config = %[renew_time_key message]
|
99
|
+
times = [ Time.local(2,2,3,4,5,2010,nil,nil,nil,nil), Time.local(3,2,3,4,5,2010,nil,nil,nil,nil) ]
|
100
|
+
msgs = times.map{|t| t.to_f.to_s }
|
101
|
+
filtered = filter(config, msgs)
|
102
|
+
filtered.each_with_index do |(time, _record), i|
|
103
|
+
assert_equal(times[i].to_i, time)
|
104
|
+
assert(time.is_a?(Fluent::EventTime))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'keep_keys' do
|
109
|
+
config = %[renew_record true\nkeep_keys foo,message]
|
110
|
+
msgs = ['1', '2']
|
111
|
+
filtered = filter(config, msgs)
|
112
|
+
filtered.each_with_index do |(_t, r), i|
|
113
|
+
assert_equal('bar', r['foo'])
|
114
|
+
assert_equal(msgs[i], r['message'])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'enable_ruby' do
|
119
|
+
config = %[
|
120
|
+
enable_ruby yes
|
121
|
+
<record>
|
122
|
+
message ${hostname} ${tag_parts.last} ${"'" + message + "'"}
|
123
|
+
</record>
|
124
|
+
]
|
125
|
+
msgs = ['1', '2']
|
126
|
+
filtered = filter(config, msgs)
|
127
|
+
filtered.each_with_index do |(_t, r), i|
|
128
|
+
assert_equal("#{@hostname} #{@tag_parts[-1]} '#{msgs[i]}'", r['message'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'hash_value' do
|
133
|
+
config = %[
|
134
|
+
<record>
|
135
|
+
hash_field {"k1":100, "k2":"foobar"}
|
136
|
+
</record>
|
137
|
+
%]
|
138
|
+
msgs = ['1', '2']
|
139
|
+
filtered = filter(config, msgs)
|
140
|
+
filtered.each_with_index do |(_t, r), i|
|
141
|
+
assert_equal({"k1"=>100, "k2"=>"foobar"}, r['hash_field'])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'array_value' do
|
146
|
+
config = %[
|
147
|
+
<record>
|
148
|
+
array_field [1, 2, 3]
|
149
|
+
</record>
|
150
|
+
%]
|
151
|
+
msgs = ['1', '2']
|
152
|
+
filtered = filter(config, msgs)
|
153
|
+
filtered.each_with_index do |(_t, r), i|
|
154
|
+
assert_equal([1,2,3], r['array_field'])
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'array_hash_mixed' do
|
159
|
+
config = %[
|
160
|
+
<record>
|
161
|
+
mixed_field {"hello":[1,2,3], "world":{"foo":"bar"}}
|
162
|
+
</record>
|
163
|
+
%]
|
164
|
+
msgs = ['1', '2']
|
165
|
+
filtered = filter(config, msgs)
|
166
|
+
filtered.each_with_index do |(_t, r), i|
|
167
|
+
assert_equal({"hello"=>[1,2,3], "world"=>{"foo"=>"bar"}}, r['mixed_field'])
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
sub_test_case 'test placeholders' do
|
173
|
+
def filter(config, msgs = [''])
|
174
|
+
d = create_driver(config)
|
175
|
+
yield d if block_given?
|
176
|
+
d.run {
|
177
|
+
records = msgs.map do |msg|
|
178
|
+
next msg if msg.is_a?(Hash)
|
179
|
+
{ 'eventType0' => 'bar', 'message' => msg }
|
180
|
+
end
|
181
|
+
records.each do |record|
|
182
|
+
d.feed(@tag, @time, record)
|
183
|
+
end
|
184
|
+
}
|
185
|
+
d.filtered
|
186
|
+
end
|
187
|
+
|
188
|
+
%w[yes no].each do |enable_ruby|
|
189
|
+
test "hostname with enble_ruby #{enable_ruby}" do
|
190
|
+
config = %[
|
191
|
+
enable_ruby #{enable_ruby}
|
192
|
+
<record>
|
193
|
+
message ${hostname}
|
194
|
+
</record>
|
195
|
+
]
|
196
|
+
filtered = filter(config)
|
197
|
+
filtered.each do |t, r|
|
198
|
+
assert_equal(@hostname, r['message'])
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
test "tag with enable_ruby #{enable_ruby}" do
|
203
|
+
config = %[
|
204
|
+
enable_ruby #{enable_ruby}
|
205
|
+
<record>
|
206
|
+
message ${tag}
|
207
|
+
</record>
|
208
|
+
]
|
209
|
+
filtered = filter(config)
|
210
|
+
filtered.each do |t, r|
|
211
|
+
assert_equal(@tag, r['message'])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
test "tag_parts with enable_ruby #{enable_ruby}" do
|
216
|
+
config = %[
|
217
|
+
enable_ruby #{enable_ruby}
|
218
|
+
<record>
|
219
|
+
message ${tag_parts[0]} ${tag_parts[-1]}
|
220
|
+
</record>
|
221
|
+
]
|
222
|
+
expected = "#{@tag.split('.').first} #{@tag.split('.').last}"
|
223
|
+
filtered = filter(config)
|
224
|
+
filtered.each do |t, r|
|
225
|
+
assert_equal(expected, r['message'])
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
test "${tag_prefix[N]} and ${tag_suffix[N]} with enable_ruby #{enable_ruby}" do
|
230
|
+
config = %[
|
231
|
+
enable_ruby #{enable_ruby}
|
232
|
+
<record>
|
233
|
+
message ${tag_prefix[1]} ${tag_prefix[-2]} ${tag_suffix[2]} ${tag_suffix[-3]}
|
234
|
+
</record>
|
235
|
+
]
|
236
|
+
@tag = 'prefix.test.tag.suffix'
|
237
|
+
expected = "prefix.test prefix.test.tag tag.suffix test.tag.suffix"
|
238
|
+
filtered = filter(config)
|
239
|
+
filtered.each do |t, r|
|
240
|
+
assert_equal(expected, r['message'])
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
test "time with enable_ruby #{enable_ruby}" do
|
245
|
+
config = %[
|
246
|
+
enable_ruby #{enable_ruby}
|
247
|
+
<record>
|
248
|
+
message ${time}
|
249
|
+
</record>
|
250
|
+
]
|
251
|
+
filtered = filter(config)
|
252
|
+
filtered.each do |t, r|
|
253
|
+
assert_equal(Time.at(@time).localtime.to_s, r['message'])
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
test "record keys with enable_ruby #{enable_ruby}" do
|
258
|
+
config = %[
|
259
|
+
enable_ruby #{enable_ruby}
|
260
|
+
remove_keys eventType0
|
261
|
+
<record>
|
262
|
+
message bar ${message}
|
263
|
+
eventtype ${eventType0}
|
264
|
+
</record>
|
265
|
+
]
|
266
|
+
msgs = ['1', '2']
|
267
|
+
filtered = filter(config, msgs)
|
268
|
+
filtered.each_with_index do |(_t, r), i|
|
269
|
+
assert_not_include(r, 'eventType0')
|
270
|
+
assert_equal("bar", r['eventtype'])
|
271
|
+
assert_equal("bar #{msgs[i]}", r['message'])
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
test "Prevent overwriting reserved keys such as tag with enable_ruby #{enable_ruby}" do
|
276
|
+
config = %[
|
277
|
+
enable_ruby #{enable_ruby}
|
278
|
+
<record>
|
279
|
+
new_tag ${tag}
|
280
|
+
new_record_tag ${record["tag"]}
|
281
|
+
</record>
|
282
|
+
]
|
283
|
+
records = [{'tag' => 'tag', 'time' => 'time'}]
|
284
|
+
filtered = filter(config, records)
|
285
|
+
filtered.each_with_index do |(_t, r), i|
|
286
|
+
assert_not_equal('tag', r['new_tag'])
|
287
|
+
assert_equal(@tag, r['new_tag'])
|
288
|
+
assert_equal('tag', r['new_record_tag'])
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
test "hash values with placeholders with enable_ruby #{enable_ruby}" do
|
293
|
+
config = %[
|
294
|
+
enable_ruby #{enable_ruby}
|
295
|
+
<record>
|
296
|
+
hash_field {
|
297
|
+
"hostname":"${hostname}",
|
298
|
+
"tag":"${tag}",
|
299
|
+
"${tag}":100
|
300
|
+
}
|
301
|
+
</record>
|
302
|
+
]
|
303
|
+
msgs = ['1', '2']
|
304
|
+
filtered = filter(config, msgs)
|
305
|
+
filtered.each_with_index do |(_t, r), i|
|
306
|
+
assert_equal({"hostname" => @hostname, "tag" => @tag, "#{@tag}" => 100}, r['hash_field'])
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
test "array values with placeholders with enable_ruby #{enable_ruby}" do
|
311
|
+
config = %[
|
312
|
+
enable_ruby #{enable_ruby}
|
313
|
+
<record>
|
314
|
+
array_field ["${hostname}", "${tag}"]
|
315
|
+
</record>
|
316
|
+
]
|
317
|
+
msgs = ['1', '2']
|
318
|
+
filtered = filter(config, msgs)
|
319
|
+
filtered.each_with_index do |(_t, r), i|
|
320
|
+
assert_equal([@hostname, @tag], r['array_field'])
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
test "array and hash values with placeholders with enable_ruby #{enable_ruby}" do
|
325
|
+
config = %[
|
326
|
+
enable_ruby #{enable_ruby}
|
327
|
+
<record>
|
328
|
+
mixed_field [{"tag":"${tag}"}]
|
329
|
+
</record>
|
330
|
+
]
|
331
|
+
msgs = ['1', '2']
|
332
|
+
filtered = filter(config, msgs)
|
333
|
+
filtered.each_with_index do |(_t, r), i|
|
334
|
+
assert_equal([{"tag" => @tag}], r['mixed_field'])
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
test "keys with placeholders with enable_ruby #{enable_ruby}" do
|
339
|
+
config = %[
|
340
|
+
enable_ruby #{enable_ruby}
|
341
|
+
renew_record true
|
342
|
+
<record>
|
343
|
+
${hostname} hostname
|
344
|
+
foo.${tag} tag
|
345
|
+
</record>
|
346
|
+
]
|
347
|
+
msgs = ['1', '2']
|
348
|
+
filtered = filter(config, msgs)
|
349
|
+
filtered.each_with_index do |(_t, r), i|
|
350
|
+
assert_equal({@hostname=>'hostname',"foo.#{@tag}"=>'tag'}, r)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
test "disabled typecasting of values with enable_ruby #{enable_ruby}" do
|
355
|
+
config = %[
|
356
|
+
auto_typecast false
|
357
|
+
enable_ruby #{enable_ruby}
|
358
|
+
<record>
|
359
|
+
single ${source}
|
360
|
+
multiple ${source}${source}
|
361
|
+
with_prefix prefix-${source}
|
362
|
+
with_suffix ${source}-suffix
|
363
|
+
with_quote source[""]
|
364
|
+
</record>
|
365
|
+
]
|
366
|
+
msgs = [
|
367
|
+
{ "source" => "string" },
|
368
|
+
{ "source" => 123 },
|
369
|
+
{ "source" => [1, 2] },
|
370
|
+
{ "source" => {a:1, b:2} },
|
371
|
+
{ "source" => nil },
|
372
|
+
]
|
373
|
+
expected_results = [
|
374
|
+
{ single: "string",
|
375
|
+
multiple: "stringstring",
|
376
|
+
with_prefix: "prefix-string",
|
377
|
+
with_suffix: "string-suffix",
|
378
|
+
with_quote: %Q{source[""]} },
|
379
|
+
{ single: 123.to_s,
|
380
|
+
multiple: "#{123.to_s}#{123.to_s}",
|
381
|
+
with_prefix: "prefix-#{123.to_s}",
|
382
|
+
with_suffix: "#{123.to_s}-suffix",
|
383
|
+
with_quote: %Q{source[""]} },
|
384
|
+
{ single: [1, 2].to_s,
|
385
|
+
multiple: "#{[1, 2].to_s}#{[1, 2].to_s}",
|
386
|
+
with_prefix: "prefix-#{[1, 2].to_s}",
|
387
|
+
with_suffix: "#{[1, 2].to_s}-suffix",
|
388
|
+
with_quote: %Q{source[""]} },
|
389
|
+
{ single: {a:1, b:2}.to_s,
|
390
|
+
multiple: "#{{a:1, b:2}.to_s}#{{a:1, b:2}.to_s}",
|
391
|
+
with_prefix: "prefix-#{{a:1, b:2}.to_s}",
|
392
|
+
with_suffix: "#{{a:1, b:2}.to_s}-suffix",
|
393
|
+
with_quote: %Q{source[""]} },
|
394
|
+
{ single: nil.to_s,
|
395
|
+
multiple: "#{nil.to_s}#{nil.to_s}",
|
396
|
+
with_prefix: "prefix-#{nil.to_s}",
|
397
|
+
with_suffix: "#{nil.to_s}-suffix",
|
398
|
+
with_quote: %Q{source[""]} },
|
399
|
+
]
|
400
|
+
actual_results = []
|
401
|
+
filtered = filter(config, msgs)
|
402
|
+
filtered.each_with_index do |(_t, r), i|
|
403
|
+
actual_results << {
|
404
|
+
single: r["single"],
|
405
|
+
multiple: r["multiple"],
|
406
|
+
with_prefix: r["with_prefix"],
|
407
|
+
with_suffix: r["with_suffix"],
|
408
|
+
with_quote: r["with_quote"],
|
409
|
+
}
|
410
|
+
end
|
411
|
+
assert_equal(expected_results, actual_results)
|
412
|
+
end
|
413
|
+
|
414
|
+
test "enabled typecasting of values with enable_ruby #{enable_ruby}" do
|
415
|
+
config = %[
|
416
|
+
auto_typecast yes
|
417
|
+
enable_ruby #{enable_ruby}
|
418
|
+
<record>
|
419
|
+
single ${source}
|
420
|
+
multiple ${source}${source}
|
421
|
+
with_prefix prefix-${source}
|
422
|
+
with_suffix ${source}-suffix
|
423
|
+
</record>
|
424
|
+
]
|
425
|
+
msgs = [
|
426
|
+
{ "source" => "string" },
|
427
|
+
{ "source" => 123 },
|
428
|
+
{ "source" => [1, 2] },
|
429
|
+
{ "source" => {a:1, b:2} },
|
430
|
+
{ "source" => nil },
|
431
|
+
]
|
432
|
+
expected_results = [
|
433
|
+
{ single: "string",
|
434
|
+
multiple: "stringstring",
|
435
|
+
with_prefix: "prefix-string",
|
436
|
+
with_suffix: "string-suffix" },
|
437
|
+
{ single: 123,
|
438
|
+
multiple: "#{123.to_s}#{123.to_s}",
|
439
|
+
with_prefix: "prefix-#{123.to_s}",
|
440
|
+
with_suffix: "#{123.to_s}-suffix" },
|
441
|
+
{ single: [1, 2],
|
442
|
+
multiple: "#{[1, 2].to_s}#{[1, 2].to_s}",
|
443
|
+
with_prefix: "prefix-#{[1, 2].to_s}",
|
444
|
+
with_suffix: "#{[1, 2].to_s}-suffix" },
|
445
|
+
{ single: {a:1, b:2},
|
446
|
+
multiple: "#{{a:1, b:2}.to_s}#{{a:1, b:2}.to_s}",
|
447
|
+
with_prefix: "prefix-#{{a:1, b:2}.to_s}",
|
448
|
+
with_suffix: "#{{a:1, b:2}.to_s}-suffix" },
|
449
|
+
{ single: nil,
|
450
|
+
multiple: "#{nil.to_s}#{nil.to_s}",
|
451
|
+
with_prefix: "prefix-#{nil.to_s}",
|
452
|
+
with_suffix: "#{nil.to_s}-suffix" },
|
453
|
+
]
|
454
|
+
actual_results = []
|
455
|
+
filtered = filter(config, msgs)
|
456
|
+
filtered.each_with_index do |(_t, r), i|
|
457
|
+
actual_results << {
|
458
|
+
single: r["single"],
|
459
|
+
multiple: r["multiple"],
|
460
|
+
with_prefix: r["with_prefix"],
|
461
|
+
with_suffix: r["with_suffix"],
|
462
|
+
}
|
463
|
+
end
|
464
|
+
assert_equal(expected_results, actual_results)
|
465
|
+
end
|
466
|
+
|
467
|
+
test %Q[record["key"] with enable_ruby #{enable_ruby}] do
|
468
|
+
config = %[
|
469
|
+
enable_ruby #{enable_ruby}
|
470
|
+
auto_typecast yes
|
471
|
+
<record>
|
472
|
+
_timestamp ${record["@timestamp"]}
|
473
|
+
_foo_bar ${record["foo.bar"]}
|
474
|
+
</record>
|
475
|
+
]
|
476
|
+
d = create_driver(config)
|
477
|
+
record = {
|
478
|
+
"foo.bar" => "foo.bar",
|
479
|
+
"@timestamp" => 10,
|
480
|
+
}
|
481
|
+
d.run { d.feed(@tag, @time, record) }
|
482
|
+
filtered = d.filtered
|
483
|
+
filtered.each do |t, r|
|
484
|
+
assert { r['_timestamp'] == record['@timestamp'] }
|
485
|
+
assert { r['_foo_bar'] == record['foo.bar'] }
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
test 'unknown placeholder (enable_ruby no)' do
|
491
|
+
config = %[
|
492
|
+
enable_ruby no
|
493
|
+
<record>
|
494
|
+
message ${unknown}
|
495
|
+
</record>
|
496
|
+
]
|
497
|
+
filter(config) { |d|
|
498
|
+
mock(d.instance.log).warn("unknown placeholder `${unknown}` found")
|
499
|
+
}
|
500
|
+
end
|
501
|
+
|
502
|
+
test 'failed to expand (enable_ruby yes)' do
|
503
|
+
config = %[
|
504
|
+
enable_ruby yes
|
505
|
+
<record>
|
506
|
+
message ${unknown['bar']}
|
507
|
+
</record>
|
508
|
+
]
|
509
|
+
filtered = filter(config) { |d|
|
510
|
+
mock(d.instance.log).warn("failed to expand `%Q[\#{unknown['bar']}]`", anything)
|
511
|
+
}
|
512
|
+
filtered.each do |t, r|
|
513
|
+
assert_nil(r['message'])
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
test 'expand fields starting with @ (enable_ruby no)' do
|
518
|
+
config = %[
|
519
|
+
enable_ruby no
|
520
|
+
<record>
|
521
|
+
foo ${@timestamp}
|
522
|
+
</record>
|
523
|
+
]
|
524
|
+
d = create_driver(config)
|
525
|
+
message = {"@timestamp" => "foo"}
|
526
|
+
d.run { d.feed(@tag, @time, message) }
|
527
|
+
filtered = d.filtered
|
528
|
+
filtered.each do |t, r|
|
529
|
+
assert_equal(message["@timestamp"], r['foo'])
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
test 'auto_typecast placeholder containing {} (enable_ruby yes)' do
|
534
|
+
config = %[
|
535
|
+
tag tag
|
536
|
+
enable_ruby yes
|
537
|
+
auto_typecast yes
|
538
|
+
<record>
|
539
|
+
foo ${record.map{|k,v|v}}
|
540
|
+
</record>
|
541
|
+
]
|
542
|
+
d = create_driver(config)
|
543
|
+
message = {"@timestamp" => "foo"}
|
544
|
+
d.run { d.feed(@tag, @time, message) }
|
545
|
+
filtered = d.filtered
|
546
|
+
filtered.each do |t, r|
|
547
|
+
assert_equal([message["@timestamp"]], r['foo'])
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
test 'expand fields starting with @ (enable_ruby yes)' do
|
552
|
+
config = %[
|
553
|
+
enable_ruby yes
|
554
|
+
<record>
|
555
|
+
foo ${__send__("@timestamp")}
|
556
|
+
</record>
|
557
|
+
]
|
558
|
+
d = create_driver(config)
|
559
|
+
message = {"@timestamp" => "foo"}
|
560
|
+
d.run { d.feed(@tag, @time, message) }
|
561
|
+
filtered = d.filtered
|
562
|
+
filtered.each do |t, r|
|
563
|
+
assert_equal(message["@timestamp"], r['foo'])
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end # test placeholders
|
567
|
+
|
568
|
+
test "compatibility test (enable_ruby yes)" do
|
569
|
+
config = %[
|
570
|
+
enable_ruby yes
|
571
|
+
auto_typecast yes
|
572
|
+
<record>
|
573
|
+
_message prefix-${message}-suffix
|
574
|
+
_time ${Time.at(time)}
|
575
|
+
_number ${number == '-' ? 0 : number}
|
576
|
+
_match ${/0x[0-9a-f]+/.match(hex)[0]}
|
577
|
+
_timestamp ${__send__("@timestamp")}
|
578
|
+
_foo_bar ${__send__('foo.bar')}
|
579
|
+
</record>
|
580
|
+
]
|
581
|
+
d = create_driver(config)
|
582
|
+
record = {
|
583
|
+
"number" => "-",
|
584
|
+
"hex" => "0x10",
|
585
|
+
"foo.bar" => "foo.bar",
|
586
|
+
"@timestamp" => 10,
|
587
|
+
"message" => "10",
|
588
|
+
}
|
589
|
+
d.run { d.feed(@tag, @time, record) }
|
590
|
+
filtered = d.filtered
|
591
|
+
filtered.each do |t, r|
|
592
|
+
assert { r['_message'] == "prefix-#{record['message']}-suffix" }
|
593
|
+
assert { r['_time'] == Time.at(@time) }
|
594
|
+
assert { r['_number'] == 0 }
|
595
|
+
assert { r['_match'] == record['hex'] }
|
596
|
+
assert { r['_timestamp'] == record['@timestamp'] }
|
597
|
+
assert { r['_foo_bar'] == record['foo.bar'] }
|
598
|
+
end
|
599
|
+
end
|
600
|
+
end
|