fluentd 0.12.40 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +2 -0
- data/.travis.yml +33 -21
- data/CONTRIBUTING.md +1 -0
- data/ChangeLog +810 -237
- 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 +51 -595
- data/lib/fluent/plugin/in_tcp.rb +8 -1
- data/lib/fluent/plugin/in_udp.rb +8 -14
- 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 +19 -9
- 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 +120 -114
- 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 -234
- data/test/plugin/test_in_tcp.rb +14 -0
- data/test/plugin/test_in_udp.rb +21 -13
- 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 +180 -54
- 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
data/test/plugin/test_in_tail.rb
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
require_relative '../helper'
|
|
2
2
|
require 'fluent/test'
|
|
3
|
+
require 'fluent/plugin/in_tail'
|
|
4
|
+
require 'fluent/plugin/buffer'
|
|
5
|
+
require 'fluent/system_config'
|
|
3
6
|
require 'net/http'
|
|
4
7
|
require 'flexmock/test_unit'
|
|
5
|
-
require 'timecop'
|
|
6
8
|
|
|
7
9
|
class TailInputTest < Test::Unit::TestCase
|
|
8
10
|
include FlexMock::TestCase
|
|
9
11
|
|
|
10
12
|
def setup
|
|
11
13
|
Fluent::Test.setup
|
|
12
|
-
FileUtils.rm_rf(TMP_DIR)
|
|
14
|
+
FileUtils.rm_rf(TMP_DIR, secure: true)
|
|
15
|
+
if File.exist?(TMP_DIR)
|
|
16
|
+
# ensure files are closed for Windows, on which deleted files
|
|
17
|
+
# are still visible from filesystem
|
|
18
|
+
GC.start(full_mark: true, immediate_mark: true, immediate_sweep: true)
|
|
19
|
+
FileUtils.remove_entry_secure(TMP_DIR)
|
|
20
|
+
end
|
|
13
21
|
FileUtils.mkdir_p(TMP_DIR)
|
|
14
22
|
end
|
|
15
23
|
|
|
@@ -50,7 +58,6 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
50
58
|
assert_equal 2, d.instance.rotate_wait
|
|
51
59
|
assert_equal "#{TMP_DIR}/tail.pos", d.instance.pos_file
|
|
52
60
|
assert_equal 1000, d.instance.read_lines_limit
|
|
53
|
-
assert_equal false, d.instance.ignore_repeated_permission_error
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def test_configure_encoding
|
|
@@ -64,45 +71,20 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
64
71
|
end
|
|
65
72
|
end
|
|
66
73
|
|
|
67
|
-
def test_configure_from_encoding
|
|
68
|
-
# If only specified from_encoding raise ConfigError
|
|
69
|
-
assert_raise(Fluent::ConfigError) do
|
|
70
|
-
d = create_driver(SINGLE_LINE_CONFIG + 'from_encoding utf-8')
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# valid setting
|
|
74
|
-
d = create_driver %[
|
|
75
|
-
format /(?<message>.*)/
|
|
76
|
-
read_from_head true
|
|
77
|
-
from_encoding utf-8
|
|
78
|
-
encoding utf-8
|
|
79
|
-
]
|
|
80
|
-
assert_equal Encoding::UTF_8, d.instance.from_encoding
|
|
81
|
-
|
|
82
|
-
# invalid from_encoding
|
|
83
|
-
assert_raise(Fluent::ConfigError) do
|
|
84
|
-
d = create_driver %[
|
|
85
|
-
format /(?<message>.*)/
|
|
86
|
-
read_from_head true
|
|
87
|
-
from_encoding no-such-encoding
|
|
88
|
-
encoding utf-8
|
|
89
|
-
]
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
74
|
# TODO: Should using more better approach instead of sleep wait
|
|
94
75
|
|
|
95
76
|
def test_emit
|
|
96
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
77
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
|
|
97
78
|
f.puts "test1"
|
|
98
79
|
f.puts "test2"
|
|
99
80
|
}
|
|
100
81
|
|
|
101
82
|
d = create_driver
|
|
83
|
+
|
|
102
84
|
d.run do
|
|
103
85
|
sleep 1
|
|
104
86
|
|
|
105
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
87
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
106
88
|
f.puts "test3"
|
|
107
89
|
f.puts "test4"
|
|
108
90
|
}
|
|
@@ -113,35 +95,69 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
113
95
|
assert_equal(true, emits.length > 0)
|
|
114
96
|
assert_equal({"message" => "test3"}, emits[0][2])
|
|
115
97
|
assert_equal({"message" => "test4"}, emits[1][2])
|
|
98
|
+
assert(emits[0][1].is_a?(Fluent::EventTime))
|
|
99
|
+
assert(emits[1][1].is_a?(Fluent::EventTime))
|
|
116
100
|
assert_equal(1, d.emit_streams.size)
|
|
117
101
|
end
|
|
118
102
|
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
class TestWithSystem < self
|
|
104
|
+
include Fluent::SystemConfig::Mixin
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
OVERRIDE_FILE_PERMISSION = 0620
|
|
107
|
+
CONFIG_SYSTEM = %[
|
|
108
|
+
<system>
|
|
109
|
+
file_permission #{OVERRIDE_FILE_PERMISSION}
|
|
110
|
+
</system>
|
|
111
|
+
]
|
|
128
112
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
113
|
+
def setup
|
|
114
|
+
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
|
|
115
|
+
# Store default permission
|
|
116
|
+
@default_permission = system_config.instance_variable_get(:@file_permission)
|
|
117
|
+
end
|
|
135
118
|
|
|
136
|
-
|
|
119
|
+
def teardown
|
|
120
|
+
# Restore default permission
|
|
121
|
+
system_config.instance_variable_set(:@file_permission, @default_permission)
|
|
137
122
|
end
|
|
138
123
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
124
|
+
def parse_system(text)
|
|
125
|
+
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
|
126
|
+
Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_emit_with_system
|
|
130
|
+
system_conf = parse_system(CONFIG_SYSTEM)
|
|
131
|
+
sc = Fluent::SystemConfig.new(system_conf)
|
|
132
|
+
Fluent::Engine.init(sc)
|
|
133
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
|
|
134
|
+
f.puts "test1"
|
|
135
|
+
f.puts "test2"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
d = create_driver
|
|
139
|
+
|
|
140
|
+
d.run do
|
|
141
|
+
sleep 1
|
|
142
|
+
|
|
143
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
144
|
+
f.puts "test3"
|
|
145
|
+
f.puts "test4"
|
|
146
|
+
}
|
|
147
|
+
sleep 1
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
emits = d.emits
|
|
151
|
+
assert_equal(true, emits.length > 0)
|
|
152
|
+
assert_equal({"message" => "test3"}, emits[0][2])
|
|
153
|
+
assert_equal({"message" => "test4"}, emits[1][2])
|
|
154
|
+
assert(emits[0][1].is_a?(Fluent::EventTime))
|
|
155
|
+
assert(emits[1][1].is_a?(Fluent::EventTime))
|
|
156
|
+
assert_equal(1, d.emit_streams.size)
|
|
157
|
+
pos = d.instance.instance_variable_get(:@pf_file)
|
|
158
|
+
mode = "%o" % File.stat(pos).mode
|
|
159
|
+
assert_equal OVERRIDE_FILE_PERMISSION, mode[-3, 3].to_i
|
|
160
|
+
end
|
|
145
161
|
end
|
|
146
162
|
|
|
147
163
|
data('1' => [1, 2], '10' => [10, 1])
|
|
@@ -153,7 +169,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
153
169
|
d.run do
|
|
154
170
|
sleep 1
|
|
155
171
|
|
|
156
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
172
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
157
173
|
f.puts msg
|
|
158
174
|
f.puts msg
|
|
159
175
|
}
|
|
@@ -168,7 +184,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
168
184
|
end
|
|
169
185
|
|
|
170
186
|
def test_emit_with_read_from_head
|
|
171
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
187
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
|
|
172
188
|
f.puts "test1"
|
|
173
189
|
f.puts "test2"
|
|
174
190
|
}
|
|
@@ -178,7 +194,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
178
194
|
d.run do
|
|
179
195
|
sleep 1
|
|
180
196
|
|
|
181
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
197
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
182
198
|
f.puts "test3"
|
|
183
199
|
f.puts "test4"
|
|
184
200
|
}
|
|
@@ -241,13 +257,13 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
241
257
|
|
|
242
258
|
def test_rotate_file_with_write_old
|
|
243
259
|
emits = sub_test_rotate_file(SINGLE_LINE_CONFIG) { |rotated_file|
|
|
244
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
260
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
245
261
|
rotated_file.puts "test7"
|
|
246
262
|
rotated_file.puts "test8"
|
|
247
263
|
rotated_file.flush
|
|
248
264
|
|
|
249
265
|
sleep 1
|
|
250
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
266
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
251
267
|
f.puts "test5"
|
|
252
268
|
f.puts "test6"
|
|
253
269
|
}
|
|
@@ -275,7 +291,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
275
291
|
end
|
|
276
292
|
|
|
277
293
|
def sub_test_rotate_file(config = nil)
|
|
278
|
-
file =
|
|
294
|
+
file = Fluent::FileWrapper.open("#{TMP_DIR}/tail.txt", "wb")
|
|
279
295
|
file.puts "test1"
|
|
280
296
|
file.puts "test2"
|
|
281
297
|
file.flush
|
|
@@ -295,10 +311,10 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
295
311
|
sleep 1
|
|
296
312
|
else
|
|
297
313
|
sleep 1
|
|
298
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
314
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
299
315
|
sleep 1
|
|
300
316
|
|
|
301
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
317
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
302
318
|
f.puts "test5"
|
|
303
319
|
f.puts "test6"
|
|
304
320
|
}
|
|
@@ -312,21 +328,21 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
312
328
|
|
|
313
329
|
d.emits
|
|
314
330
|
ensure
|
|
315
|
-
file.close
|
|
331
|
+
file.close if file
|
|
316
332
|
end
|
|
317
333
|
|
|
318
334
|
def test_lf
|
|
319
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
335
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f| }
|
|
320
336
|
|
|
321
337
|
d = create_driver
|
|
322
338
|
|
|
323
339
|
d.run do
|
|
324
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
340
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
325
341
|
f.print "test3"
|
|
326
342
|
}
|
|
327
343
|
sleep 1
|
|
328
344
|
|
|
329
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
345
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
330
346
|
f.puts "test4"
|
|
331
347
|
}
|
|
332
348
|
sleep 1
|
|
@@ -338,14 +354,14 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
338
354
|
end
|
|
339
355
|
|
|
340
356
|
def test_whitespace
|
|
341
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
357
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f| }
|
|
342
358
|
|
|
343
359
|
d = create_driver
|
|
344
360
|
|
|
345
361
|
d.run do
|
|
346
362
|
sleep 1
|
|
347
363
|
|
|
348
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
364
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
349
365
|
f.puts " " # 4 spaces
|
|
350
366
|
f.puts " 4 spaces"
|
|
351
367
|
f.puts "4 spaces "
|
|
@@ -387,32 +403,10 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
387
403
|
assert_equal(encoding, emits[0][2]['message'].encoding)
|
|
388
404
|
end
|
|
389
405
|
|
|
390
|
-
def test_from_encoding
|
|
391
|
-
d = create_driver %[
|
|
392
|
-
format /(?<message>.*)/
|
|
393
|
-
read_from_head true
|
|
394
|
-
from_encoding cp932
|
|
395
|
-
encoding utf-8
|
|
396
|
-
]
|
|
397
|
-
|
|
398
|
-
d.run do
|
|
399
|
-
sleep 1
|
|
400
|
-
|
|
401
|
-
File.open("#{TMP_DIR}/tail.txt", "w:cp932") {|f|
|
|
402
|
-
f.puts "\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932)
|
|
403
|
-
}
|
|
404
|
-
sleep 1
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
emits = d.emits
|
|
408
|
-
assert_equal("\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932).encode(Encoding::UTF_8), emits[0][2]['message'])
|
|
409
|
-
assert_equal(Encoding::UTF_8, emits[0][2]['message'].encoding)
|
|
410
|
-
end
|
|
411
|
-
|
|
412
406
|
# multiline mode test
|
|
413
407
|
|
|
414
408
|
def test_multiline
|
|
415
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
409
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
416
410
|
|
|
417
411
|
d = create_driver %[
|
|
418
412
|
format multiline
|
|
@@ -420,7 +414,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
420
414
|
format_firstline /^[s]/
|
|
421
415
|
]
|
|
422
416
|
d.run do
|
|
423
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
417
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
424
418
|
f.puts "f test1"
|
|
425
419
|
f.puts "s test2"
|
|
426
420
|
f.puts "f test3"
|
|
@@ -448,44 +442,6 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
448
442
|
assert_equal({"message1" => "test8"}, emits[3][2])
|
|
449
443
|
end
|
|
450
444
|
|
|
451
|
-
def test_multiline_with_emit_unmatched_lines_true
|
|
452
|
-
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
453
|
-
|
|
454
|
-
d = create_driver %[
|
|
455
|
-
format multiline
|
|
456
|
-
format1 /^s (?<message1>[^\\n]+)(\\nf (?<message2>[^\\n]+))?(\\nf (?<message3>.*))?/
|
|
457
|
-
format_firstline /^[s]/
|
|
458
|
-
emit_unmatched_lines true
|
|
459
|
-
]
|
|
460
|
-
d.run do
|
|
461
|
-
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
462
|
-
f.puts "f test1"
|
|
463
|
-
f.puts "s test2"
|
|
464
|
-
f.puts "f test3"
|
|
465
|
-
f.puts "f test4"
|
|
466
|
-
f.puts "s test5"
|
|
467
|
-
f.puts "s test6"
|
|
468
|
-
f.puts "f test7"
|
|
469
|
-
f.puts "s test8"
|
|
470
|
-
}
|
|
471
|
-
sleep 1
|
|
472
|
-
|
|
473
|
-
events = d.emits
|
|
474
|
-
assert_equal(4, events.length)
|
|
475
|
-
assert_equal({"unmatched_line" => "f test1"}, events[0][2])
|
|
476
|
-
assert_equal({"message1" => "test2", "message2" => "test3", "message3" => "test4"}, events[1][2])
|
|
477
|
-
assert_equal({"message1" => "test5"}, events[2][2])
|
|
478
|
-
assert_equal({"message1" => "test6", "message2" => "test7"}, events[3][2])
|
|
479
|
-
|
|
480
|
-
sleep 3
|
|
481
|
-
assert_equal(4, d.emits.length)
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
emits = d.emits
|
|
485
|
-
assert_equal(5, emits.length)
|
|
486
|
-
assert_equal({"message1" => "test8"}, emits[4][2])
|
|
487
|
-
end
|
|
488
|
-
|
|
489
445
|
def test_multiline_with_flush_interval
|
|
490
446
|
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
491
447
|
|
|
@@ -551,33 +507,8 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
551
507
|
end
|
|
552
508
|
end
|
|
553
509
|
|
|
554
|
-
def test_multiline_from_encoding_of_flushed_record
|
|
555
|
-
d = create_driver %[
|
|
556
|
-
format multiline
|
|
557
|
-
format1 /^s (?<message1>[^\\n]+)(\\nf (?<message2>[^\\n]+))?(\\nf (?<message3>.*))?/
|
|
558
|
-
format_firstline /^[s]/
|
|
559
|
-
multiline_flush_interval 2s
|
|
560
|
-
read_from_head true
|
|
561
|
-
from_encoding cp932
|
|
562
|
-
encoding utf-8
|
|
563
|
-
]
|
|
564
|
-
|
|
565
|
-
d.run do
|
|
566
|
-
sleep 1
|
|
567
|
-
File.open("#{TMP_DIR}/tail.txt", "w:cp932") { |f|
|
|
568
|
-
f.puts "s \x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932)
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
sleep 4
|
|
572
|
-
emits = d.emits
|
|
573
|
-
assert_equal(1, emits.length)
|
|
574
|
-
assert_equal("\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932).encode(Encoding::UTF_8), emits[0][2]['message1'])
|
|
575
|
-
assert_equal(Encoding::UTF_8, emits[0][2]['message1'].encoding)
|
|
576
|
-
end
|
|
577
|
-
end
|
|
578
|
-
|
|
579
510
|
def test_multiline_with_multiple_formats
|
|
580
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
511
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
581
512
|
|
|
582
513
|
d = create_driver %[
|
|
583
514
|
format multiline
|
|
@@ -587,7 +518,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
587
518
|
format_firstline /^[s]/
|
|
588
519
|
]
|
|
589
520
|
d.run do
|
|
590
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
521
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
591
522
|
f.puts "f test1"
|
|
592
523
|
f.puts "s test2"
|
|
593
524
|
f.puts "f test3"
|
|
@@ -610,7 +541,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
610
541
|
|
|
611
542
|
def test_multilinelog_with_multiple_paths
|
|
612
543
|
files = ["#{TMP_DIR}/tail1.txt", "#{TMP_DIR}/tail2.txt"]
|
|
613
|
-
files.each { |file| File.open(file, "
|
|
544
|
+
files.each { |file| File.open(file, "wb") { |f| } }
|
|
614
545
|
|
|
615
546
|
d = create_driver(%[
|
|
616
547
|
path #{files[0]},#{files[1]}
|
|
@@ -621,7 +552,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
621
552
|
], false)
|
|
622
553
|
d.run do
|
|
623
554
|
files.each do |file|
|
|
624
|
-
File.open(file, '
|
|
555
|
+
File.open(file, 'ab') { |f|
|
|
625
556
|
f.puts "f #{file} line should be ignored"
|
|
626
557
|
f.puts "s test1"
|
|
627
558
|
f.puts "f test2"
|
|
@@ -641,7 +572,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
641
572
|
end
|
|
642
573
|
|
|
643
574
|
def test_multiline_without_firstline
|
|
644
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
575
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
|
|
645
576
|
|
|
646
577
|
d = create_driver %[
|
|
647
578
|
format multiline
|
|
@@ -650,7 +581,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
650
581
|
format3 /(?<var3>baz \\d)/
|
|
651
582
|
]
|
|
652
583
|
d.run do
|
|
653
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
584
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
|
|
654
585
|
f.puts "foo 1"
|
|
655
586
|
f.puts "bar 1"
|
|
656
587
|
f.puts "baz 1"
|
|
@@ -699,32 +630,13 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
699
630
|
assert_equal EX_PATHS - [EX_PATHS.last], plugin.expand_paths.sort
|
|
700
631
|
end
|
|
701
632
|
|
|
702
|
-
def
|
|
703
|
-
expected_files = [
|
|
704
|
-
'test/plugin/data/log/bar',
|
|
705
|
-
'test/plugin/data/log/foo/bar.log',
|
|
706
|
-
'test/plugin/data/log/foo/bar2',
|
|
707
|
-
'test/plugin/data/log/test.log'
|
|
708
|
-
]
|
|
709
|
-
|
|
710
|
-
config = config_element("", "", {
|
|
711
|
-
"tag" => "tail",
|
|
712
|
-
"path" => "test/plugin/data/log/**/*",
|
|
713
|
-
"format" => "none",
|
|
714
|
-
"pos_file" => "#{TMP_DIR}/tail.pos"
|
|
715
|
-
})
|
|
716
|
-
|
|
717
|
-
plugin = create_driver(config, false).instance
|
|
718
|
-
assert_equal expected_files, plugin.expand_paths.sort
|
|
719
|
-
end
|
|
720
|
-
|
|
721
|
-
def test_refresh_watchers
|
|
633
|
+
def test_z_refresh_watchers
|
|
722
634
|
plugin = create_driver(EX_CONFIG, false).instance
|
|
723
635
|
sio = StringIO.new
|
|
724
636
|
plugin.instance_eval do
|
|
725
637
|
@pf = Fluent::NewTailInput::PositionFile.parse(sio)
|
|
726
638
|
@loop = Coolio::Loop.new
|
|
727
|
-
|
|
639
|
+
end
|
|
728
640
|
|
|
729
641
|
flexstub(Time) do |timeclass|
|
|
730
642
|
timeclass.should_receive(:now).with_no_args.and_return(Time.new(2010, 1, 2, 3, 4, 5), Time.new(2010, 1, 2, 3, 4, 6), Time.new(2010, 1, 2, 3, 4, 7))
|
|
@@ -820,24 +732,12 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
820
732
|
engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
|
|
821
733
|
plugin.receive_lines(['foo', 'bar'], DummyWatcher.new('foo.bar.log'))
|
|
822
734
|
end
|
|
823
|
-
|
|
824
|
-
config = %[
|
|
825
|
-
tag *
|
|
826
|
-
path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
|
|
827
|
-
format none
|
|
828
|
-
read_from_head true
|
|
829
|
-
]
|
|
830
|
-
plugin = create_driver(config, false).instance
|
|
831
|
-
flexstub(plugin.router) do |engineclass|
|
|
832
|
-
engineclass.should_receive(:emit_stream).with('foo.bar.log', any).once
|
|
833
|
-
plugin.receive_lines(['foo', 'bar'], DummyWatcher.new('foo.bar.log'))
|
|
834
|
-
end
|
|
835
735
|
end
|
|
836
736
|
|
|
837
737
|
# Ensure that no fatal exception is raised when a file is missing and that
|
|
838
738
|
# files that do exist are still tailed as expected.
|
|
839
739
|
def test_missing_file
|
|
840
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
740
|
+
File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
|
|
841
741
|
f.puts "test1"
|
|
842
742
|
f.puts "test2"
|
|
843
743
|
}
|
|
@@ -856,7 +756,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
856
756
|
d = create_driver(config, false)
|
|
857
757
|
d.run do
|
|
858
758
|
sleep 1
|
|
859
|
-
File.open("#{TMP_DIR}/tail.txt", "
|
|
759
|
+
File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
|
|
860
760
|
f.puts "test3"
|
|
861
761
|
f.puts "test4"
|
|
862
762
|
}
|
|
@@ -871,7 +771,7 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
871
771
|
|
|
872
772
|
sub_test_case 'emit error cases' do
|
|
873
773
|
def test_emit_error_with_buffer_queue_limit_error
|
|
874
|
-
emits = execute_test(
|
|
774
|
+
emits = execute_test(Fluent::Plugin::Buffer::BufferOverflowError, "buffer space has too many data")
|
|
875
775
|
assert_equal(10, emits.length)
|
|
876
776
|
10.times { |i|
|
|
877
777
|
assert_equal({"message" => "test#{i}"}, emits[i][2])
|
|
@@ -1025,43 +925,4 @@ class TailInputTest < Test::Unit::TestCase
|
|
|
1025
925
|
assert_equal(files, [emits[2][2]["path"], emits[3][2]["path"]].sort)
|
|
1026
926
|
end
|
|
1027
927
|
end
|
|
1028
|
-
|
|
1029
|
-
def test_limit_recently_modified
|
|
1030
|
-
now = Time.new(2010, 1, 2, 3, 4, 5)
|
|
1031
|
-
FileUtils.touch("#{TMP_DIR}/tail_unwatch.txt", mtime: (now - 3601))
|
|
1032
|
-
FileUtils.touch("#{TMP_DIR}/tail_watch1.txt", mtime: (now - 3600))
|
|
1033
|
-
FileUtils.touch("#{TMP_DIR}/tail_watch2.txt", mtime: now)
|
|
1034
|
-
|
|
1035
|
-
config = config_element('', '', {
|
|
1036
|
-
'tag' => 'tail',
|
|
1037
|
-
'path' => "#{TMP_DIR}/*.txt",
|
|
1038
|
-
'format' => 'none',
|
|
1039
|
-
'limit_recently_modified' => '3600s'
|
|
1040
|
-
})
|
|
1041
|
-
|
|
1042
|
-
expected_files = [
|
|
1043
|
-
"#{TMP_DIR}/tail_watch1.txt",
|
|
1044
|
-
"#{TMP_DIR}/tail_watch2.txt"
|
|
1045
|
-
]
|
|
1046
|
-
|
|
1047
|
-
Timecop.freeze(now) do
|
|
1048
|
-
plugin = create_driver(config, false).instance
|
|
1049
|
-
assert_equal expected_files, plugin.expand_paths.sort
|
|
1050
|
-
end
|
|
1051
|
-
end
|
|
1052
|
-
|
|
1053
|
-
def test_skip_refresh_on_startup
|
|
1054
|
-
FileUtils.touch("#{TMP_DIR}/tail.txt")
|
|
1055
|
-
config = config_element('', '', {
|
|
1056
|
-
'tag' => 'tail',
|
|
1057
|
-
'path' => "#{TMP_DIR}/*.txt",
|
|
1058
|
-
'format' => 'none',
|
|
1059
|
-
'refresh_interval' => 1,
|
|
1060
|
-
'skip_refresh_on_startup' => true
|
|
1061
|
-
})
|
|
1062
|
-
d = create_driver(config, false)
|
|
1063
|
-
d.run {
|
|
1064
|
-
sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1
|
|
1065
|
-
}
|
|
1066
|
-
end
|
|
1067
928
|
end
|