fluentd 0.10.62 → 0.12.0.pre.1
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/.gitignore +1 -2
- data/.travis.yml +0 -4
- data/ChangeLog +0 -72
- data/Gemfile +0 -6
- data/Rakefile +12 -3
- data/example/in_http.conf +14 -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/out_copy.conf +20 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +30 -0
- data/fluent.conf +2 -12
- data/fluentd.gemspec +8 -11
- data/lib/fluent/agent.rb +180 -0
- data/lib/fluent/buffer.rb +6 -12
- data/lib/fluent/command/cat.rb +1 -3
- data/lib/fluent/command/debug.rb +1 -3
- data/lib/fluent/command/fluentd.rb +0 -10
- data/lib/fluent/config.rb +9 -3
- data/lib/fluent/config/basic_parser.rb +1 -6
- data/lib/fluent/config/configure_proxy.rb +25 -61
- data/lib/fluent/config/dsl.rb +16 -0
- data/lib/fluent/config/element.rb +21 -2
- data/lib/fluent/config/error.rb +16 -0
- data/lib/fluent/config/literal_parser.rb +9 -27
- data/lib/fluent/config/parser.rb +16 -0
- data/lib/fluent/config/section.rb +16 -2
- data/lib/fluent/config/types.rb +16 -1
- data/lib/fluent/config/v1_parser.rb +4 -12
- data/lib/fluent/configurable.rb +16 -0
- data/lib/fluent/engine.rb +43 -163
- data/lib/fluent/env.rb +16 -1
- data/lib/fluent/event.rb +20 -48
- data/lib/fluent/event_router.rb +187 -0
- data/lib/fluent/filter.rb +32 -0
- data/lib/fluent/formatter.rb +29 -101
- data/lib/fluent/input.rb +6 -4
- data/lib/fluent/label.rb +18 -0
- data/lib/fluent/load.rb +1 -3
- data/lib/fluent/log.rb +1 -3
- data/lib/fluent/match.rb +12 -19
- data/lib/fluent/mixin.rb +9 -25
- data/lib/fluent/output.rb +27 -45
- data/lib/fluent/parser.rb +93 -99
- data/lib/fluent/plugin.rb +22 -48
- data/lib/fluent/plugin/buf_file.rb +10 -7
- data/lib/fluent/plugin/buf_memory.rb +2 -3
- data/lib/fluent/plugin/buf_zfile.rb +75 -0
- data/lib/fluent/plugin/exec_util.rb +16 -0
- data/lib/fluent/plugin/in_debug_agent.rb +2 -3
- data/lib/fluent/plugin/in_exec.rb +2 -9
- data/lib/fluent/plugin/in_forward.rb +4 -22
- data/lib/fluent/plugin/in_gc_stat.rb +2 -3
- data/lib/fluent/plugin/in_http.rb +19 -59
- data/lib/fluent/plugin/in_monitor_agent.rb +21 -47
- data/lib/fluent/plugin/in_object_space.rb +2 -3
- data/lib/fluent/plugin/in_status.rb +2 -3
- data/lib/fluent/plugin/in_stream.rb +6 -16
- data/lib/fluent/plugin/in_syslog.rb +8 -17
- data/lib/fluent/plugin/in_tail.rb +17 -24
- data/lib/fluent/plugin/in_tcp.rb +16 -0
- data/lib/fluent/plugin/in_udp.rb +16 -0
- data/lib/fluent/plugin/out_copy.rb +3 -4
- data/lib/fluent/plugin/out_exec.rb +2 -4
- data/lib/fluent/plugin/out_exec_filter.rb +2 -13
- data/lib/fluent/plugin/out_file.rb +5 -6
- data/lib/fluent/plugin/out_forward.rb +4 -5
- data/lib/fluent/plugin/out_null.rb +2 -3
- data/lib/fluent/plugin/out_relabel.rb +26 -0
- data/lib/fluent/plugin/out_roundrobin.rb +3 -4
- data/lib/fluent/plugin/out_stdout.rb +2 -3
- data/lib/fluent/plugin/out_stream.rb +2 -3
- data/{test/scripts → lib}/fluent/plugin/out_test.rb +2 -3
- data/lib/fluent/plugin/socket_util.rb +19 -10
- data/lib/fluent/process.rb +4 -6
- data/lib/fluent/registry.rb +16 -0
- data/lib/fluent/root_agent.rb +212 -0
- data/lib/fluent/status.rb +2 -3
- data/lib/fluent/supervisor.rb +33 -54
- data/lib/fluent/test.rb +16 -0
- data/lib/fluent/test/base.rb +3 -17
- data/lib/fluent/test/input_test.rb +52 -7
- data/lib/fluent/test/output_test.rb +4 -20
- data/lib/fluent/version.rb +17 -1
- data/spec/config/config_parser_spec.rb +314 -0
- data/spec/config/configurable_spec.rb +524 -0
- data/spec/config/configure_proxy_spec.rb +96 -0
- data/spec/config/dsl_spec.rb +239 -0
- data/spec/config/helper.rb +49 -0
- data/spec/config/literal_parser_spec.rb +222 -0
- data/spec/config/section_spec.rb +97 -0
- data/spec/config/system_config_spec.rb +49 -0
- data/test/helper.rb +0 -25
- data/test/plugin/test_in_exec.rb +1 -1
- data/test/plugin/test_in_forward.rb +2 -1
- data/test/plugin/test_in_gc_stat.rb +1 -1
- data/test/plugin/test_in_http.rb +3 -78
- data/test/plugin/test_in_object_space.rb +1 -1
- data/test/plugin/test_in_status.rb +1 -1
- data/test/plugin/test_in_stream.rb +2 -1
- data/test/plugin/test_in_syslog.rb +2 -1
- data/test/plugin/test_in_tail.rb +6 -11
- data/test/plugin/test_in_tcp.rb +2 -1
- data/test/plugin/test_in_udp.rb +2 -1
- data/test/plugin/test_out_copy.rb +1 -12
- data/test/plugin/test_out_exec.rb +1 -1
- data/test/plugin/test_out_exec_filter.rb +1 -1
- data/test/plugin/test_out_file.rb +7 -96
- data/test/plugin/test_out_forward.rb +2 -1
- data/test/plugin/test_out_roundrobin.rb +1 -12
- data/test/plugin/test_out_stdout.rb +1 -1
- data/test/plugin/test_out_stream.rb +2 -1
- data/test/scripts/fluent/plugin/formatter_known.rb +1 -4
- data/test/scripts/fluent/plugin/parser_known.rb +1 -2
- data/test/test_config.rb +1 -1
- data/test/test_configdsl.rb +2 -1
- data/test/test_formatter.rb +3 -395
- data/test/test_match.rb +2 -1
- data/test/test_mixin.rb +3 -75
- data/test/test_output.rb +1 -112
- data/test/test_parser.rb +85 -152
- metadata +58 -167
- data/example/v1_literal_example.conf +0 -36
- data/lib/fluent/plugin/in_dummy.rb +0 -103
- data/lib/fluent/timezone.rb +0 -131
- data/test/config/assertions.rb +0 -42
- data/test/config/test_config_parser.rb +0 -389
- data/test/config/test_configurable.rb +0 -652
- data/test/config/test_configure_proxy.rb +0 -99
- data/test/config/test_dsl.rb +0 -237
- data/test/config/test_literal_parser.rb +0 -295
- data/test/config/test_section.rb +0 -112
- data/test/config/test_system_config.rb +0 -99
- data/test/config/test_types.rb +0 -63
- data/test/plugin/test_in_dummy.rb +0 -95
- data/test/test_event.rb +0 -168
- data/test/test_input.rb +0 -21
data/test/test_match.rb
CHANGED
data/test/test_mixin.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
require 'fluent/mixin'
|
3
3
|
require 'fluent/env'
|
4
4
|
require 'fluent/plugin'
|
@@ -27,17 +27,15 @@ module MixinTest
|
|
27
27
|
end
|
28
28
|
|
29
29
|
@@num = 0
|
30
|
-
|
31
30
|
def create_register_output_name
|
32
|
-
@@num
|
33
|
-
"mixin_text_#{@@num}"
|
31
|
+
"mixin_text_#{@@num+=1}"
|
34
32
|
end
|
35
33
|
|
36
34
|
def format_check(hash, tagname = 'test')
|
37
35
|
mock(Checker).format_check(tagname, @time.to_i, hash)
|
38
36
|
end
|
39
37
|
|
40
|
-
def create_driver(include_klass, conf = '', tag = "test"
|
38
|
+
def create_driver(include_klass, conf = '', tag = "test")
|
41
39
|
register_output_name = create_register_output_name
|
42
40
|
include_klasses = [include_klass].flatten
|
43
41
|
|
@@ -53,11 +51,6 @@ module MixinTest
|
|
53
51
|
def write(chunk); end
|
54
52
|
}
|
55
53
|
|
56
|
-
if block
|
57
|
-
Utils.const_set("MixinTestClass#{@@num}", klass)
|
58
|
-
klass.module_eval(&block)
|
59
|
-
end
|
60
|
-
|
61
54
|
Fluent::Test::BufferedOutputTestDriver.new(klass, tag) {
|
62
55
|
}.configure("type #{register_output_name}" + conf)
|
63
56
|
end
|
@@ -117,19 +110,6 @@ module MixinTest
|
|
117
110
|
d.emit({'a' => 1})
|
118
111
|
d.run
|
119
112
|
end
|
120
|
-
|
121
|
-
sub_test_case "mixin" do
|
122
|
-
data(
|
123
|
-
'true' => true,
|
124
|
-
'false' => false)
|
125
|
-
test 'include_tag_key' do |param|
|
126
|
-
d = create_driver(Fluent::SetTagKeyMixin) {
|
127
|
-
config_set_default :include_tag_key, param
|
128
|
-
}
|
129
|
-
|
130
|
-
assert_equal(param, d.instance.include_tag_key)
|
131
|
-
end
|
132
|
-
end
|
133
113
|
end
|
134
114
|
|
135
115
|
class SetTimeKeyMixinText < Test::Unit::TestCase
|
@@ -175,58 +155,6 @@ module MixinTest
|
|
175
155
|
d.emit({'a' => 1})
|
176
156
|
d.run
|
177
157
|
end
|
178
|
-
|
179
|
-
def test_timezone_1
|
180
|
-
format_check({
|
181
|
-
'time' => "2010-05-03T17:02:01-10:00",
|
182
|
-
'a' => 1
|
183
|
-
})
|
184
|
-
|
185
|
-
d = create_driver(Fluent::SetTimeKeyMixin, %[
|
186
|
-
include_time_key true
|
187
|
-
timezone Pacific/Honolulu
|
188
|
-
])
|
189
|
-
|
190
|
-
d.emit({'a' => 1})
|
191
|
-
d.run
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_timezone_2
|
195
|
-
format_check({
|
196
|
-
'time' => "2010-05-04T08:32:01+05:30",
|
197
|
-
'a' => 1
|
198
|
-
})
|
199
|
-
|
200
|
-
d = create_driver(Fluent::SetTimeKeyMixin, %[
|
201
|
-
include_time_key true
|
202
|
-
timezone +05:30
|
203
|
-
])
|
204
|
-
|
205
|
-
d.emit({'a' => 1})
|
206
|
-
d.run
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_timezone_invalid
|
210
|
-
assert_raise(Fluent::ConfigError) do
|
211
|
-
d = create_driver(Fluent::SetTimeKeyMixin, %[
|
212
|
-
include_time_key true
|
213
|
-
timezone Invalid/Invalid
|
214
|
-
])
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
sub_test_case "mixin" do
|
219
|
-
data(
|
220
|
-
'true' => true,
|
221
|
-
'false' => false)
|
222
|
-
test 'include_time_key' do |param|
|
223
|
-
d = create_driver(Fluent::SetTimeKeyMixin) {
|
224
|
-
config_set_default :include_time_key, param
|
225
|
-
}
|
226
|
-
|
227
|
-
assert_equal(param, d.instance.include_time_key)
|
228
|
-
end
|
229
|
-
end
|
230
158
|
end
|
231
159
|
|
232
160
|
class HandleTagMixinTest < Test::Unit::TestCase
|
data/test/test_output.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
require 'fluent/test'
|
3
3
|
require 'fluent/output'
|
4
|
-
require 'timecop'
|
5
|
-
require 'flexmock'
|
6
4
|
|
7
5
|
module FluentOutputTest
|
8
6
|
include Fluent
|
9
|
-
include FlexMock::TestCase
|
10
7
|
|
11
8
|
class BufferedOutputTest < ::Test::Unit::TestCase
|
12
9
|
include FluentOutputTest
|
@@ -45,10 +42,6 @@ module FluentOutputTest
|
|
45
42
|
# disable_retry_limit
|
46
43
|
d = create_driver(CONFIG + %[disable_retry_limit true])
|
47
44
|
assert_equal true, d.instance.disable_retry_limit
|
48
|
-
|
49
|
-
# retry_wait is converted to Float for calc_retry_wait
|
50
|
-
d = create_driver(CONFIG + %[retry_wait 1s])
|
51
|
-
assert_equal Float, d.instance.retry_wait.class
|
52
45
|
end
|
53
46
|
|
54
47
|
def test_calc_retry_wait
|
@@ -69,30 +62,6 @@ module FluentOutputTest
|
|
69
62
|
assert_equal 4, d.instance.calc_retry_wait
|
70
63
|
end
|
71
64
|
|
72
|
-
def test_calc_retry_wait_with_integer_retry_wait
|
73
|
-
d = create_driver(CONFIG + %[retry_wait 2s])
|
74
|
-
d.instance.retry_limit.times {
|
75
|
-
d.instance.instance_eval { @num_errors += 1 }
|
76
|
-
}
|
77
|
-
assert_equal true, d.instance.calc_retry_wait.finite?
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_large_num_retries
|
81
|
-
# Test that everything works properly after a very large number of
|
82
|
-
# retries and we hit the expected max_retry_wait.
|
83
|
-
exp_max_retry_wait = 300
|
84
|
-
d = create_driver(CONFIG + %[
|
85
|
-
disable_retry_limit true
|
86
|
-
max_retry_wait #{exp_max_retry_wait}
|
87
|
-
])
|
88
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
89
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
90
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
91
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
92
|
-
d.instance.instance_eval { @num_errors += 1000 }
|
93
|
-
assert_equal exp_max_retry_wait, d.instance.calc_retry_wait
|
94
|
-
end
|
95
|
-
|
96
65
|
def create_mock_driver(conf=CONFIG)
|
97
66
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedOutput) do
|
98
67
|
attr_accessor :submit_flush_threads
|
@@ -153,85 +122,5 @@ module FluentOutputTest
|
|
153
122
|
d.instance.shutdown
|
154
123
|
assert (d.instance.submit_flush_threads.size > 1), "fails if only one thread works to submit flush"
|
155
124
|
end
|
156
|
-
|
157
|
-
# for v0.12 compatibility
|
158
|
-
def test_router_emit
|
159
|
-
d = create_driver
|
160
|
-
assert_true d.instance.respond_to?(:router)
|
161
|
-
assert_true d.instance.respond_to?(:router=)
|
162
|
-
assert_true d.instance.router.respond_to?(:emit)
|
163
|
-
end
|
164
|
-
|
165
|
-
sub_test_case "test_force_flush" do
|
166
|
-
setup do
|
167
|
-
time = Time.parse("2011-01-02 13:14:15 UTC")
|
168
|
-
Timecop.freeze(time)
|
169
|
-
@time = time.to_i
|
170
|
-
end
|
171
|
-
|
172
|
-
teardown do
|
173
|
-
Timecop.return
|
174
|
-
end
|
175
|
-
|
176
|
-
test "force_flush works on retrying" do
|
177
|
-
d = create_driver(CONFIG)
|
178
|
-
d.instance.start
|
179
|
-
buffer = d.instance.instance_variable_get(:@buffer)
|
180
|
-
# imitate 10 failures
|
181
|
-
d.instance.instance_variable_set(:@num_errors, 10)
|
182
|
-
d.instance.instance_variable_set(:@next_retry_time, @time + d.instance.calc_retry_wait)
|
183
|
-
# buffer should be popped (flushed) immediately
|
184
|
-
flexmock(buffer).should_receive(:pop).once
|
185
|
-
# force_flush
|
186
|
-
buffer.emit("test", 'test', NullOutputChain.instance)
|
187
|
-
d.instance.force_flush
|
188
|
-
10.times { sleep 0.05 }
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
class TimeSlicedOutputTest < ::Test::Unit::TestCase
|
194
|
-
include FluentOutputTest
|
195
|
-
include FlexMock::TestCase
|
196
|
-
|
197
|
-
def setup
|
198
|
-
Fluent::Test.setup
|
199
|
-
FileUtils.rm_rf(TMP_DIR)
|
200
|
-
FileUtils.mkdir_p(TMP_DIR)
|
201
|
-
end
|
202
|
-
|
203
|
-
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/time_sliced_output")
|
204
|
-
|
205
|
-
CONFIG = %[]
|
206
|
-
|
207
|
-
def create_driver(conf=CONFIG)
|
208
|
-
Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::TimeSlicedOutput).configure(conf, true)
|
209
|
-
end
|
210
|
-
|
211
|
-
sub_test_case "test_force_flush" do
|
212
|
-
setup do
|
213
|
-
time = Time.parse("2011-01-02 13:14:15 UTC")
|
214
|
-
Timecop.freeze(time)
|
215
|
-
@es = OneEventStream.new(time.to_i, {"message" => "foo"})
|
216
|
-
end
|
217
|
-
|
218
|
-
teardown do
|
219
|
-
Timecop.return
|
220
|
-
end
|
221
|
-
|
222
|
-
test "force_flush immediately flushes" do
|
223
|
-
d = create_driver(CONFIG + %[
|
224
|
-
time_format %Y%m%d%H%M%S
|
225
|
-
buffer_path #{TMP_DIR}/foo
|
226
|
-
])
|
227
|
-
d.instance.start
|
228
|
-
# buffer should be popped (flushed) immediately
|
229
|
-
flexmock(d.instance.instance_variable_get(:@buffer)).should_receive(:pop).once
|
230
|
-
# force_flush
|
231
|
-
d.instance.emit('test', @es, NullOutputChain.instance)
|
232
|
-
d.instance.force_flush
|
233
|
-
10.times { sleep 0.05 }
|
234
|
-
end
|
235
|
-
end
|
236
125
|
end
|
237
126
|
end
|
data/test/test_parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
require 'fluent/test'
|
3
3
|
require 'fluent/parser'
|
4
4
|
|
@@ -13,32 +13,6 @@ module ParserTest
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
class BaseParserTest < ::Test::Unit::TestCase
|
17
|
-
include ParserTest
|
18
|
-
|
19
|
-
def create_parser
|
20
|
-
parser = Parser.new
|
21
|
-
parser.configure({})
|
22
|
-
parser
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_init
|
26
|
-
assert_true create_parser.estimate_current_event
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_parse
|
30
|
-
assert_raise NotImplementedError do
|
31
|
-
create_parser.parse('')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_call
|
36
|
-
assert_raise NotImplementedError do
|
37
|
-
create_parser.call('')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
16
|
class TimeParserTest < ::Test::Unit::TestCase
|
43
17
|
include ParserTest
|
44
18
|
|
@@ -49,18 +23,18 @@ module ParserTest
|
|
49
23
|
assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900'))
|
50
24
|
end
|
51
25
|
|
52
|
-
def
|
26
|
+
def test_call_with_strptime
|
53
27
|
parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z')
|
54
28
|
|
55
29
|
time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z')
|
56
30
|
assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900'))
|
57
31
|
end
|
58
32
|
|
59
|
-
def
|
33
|
+
def test_call_with_invalid_argument
|
60
34
|
parser = TextParser::TimeParser.new(nil)
|
61
35
|
|
62
36
|
[[], {}, nil, true, 10000].each { |v|
|
63
|
-
assert_raise
|
37
|
+
assert_raise ArgumentError do
|
64
38
|
parser.parse(v)
|
65
39
|
end
|
66
40
|
}
|
@@ -72,7 +46,7 @@ module ParserTest
|
|
72
46
|
|
73
47
|
def internal_test_case(parser)
|
74
48
|
text = '192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] [14/Feb/2013:12:00:00 +0900] "true /,/user HTTP/1.1" 200 777'
|
75
|
-
[parser.
|
49
|
+
[parser.call(text), parser.call(text) { |time, record| return time, record}].each { |time, record|
|
76
50
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
77
51
|
assert_equal({
|
78
52
|
'user' => '-',
|
@@ -86,12 +60,12 @@ module ParserTest
|
|
86
60
|
}
|
87
61
|
end
|
88
62
|
|
89
|
-
def
|
63
|
+
def test_call_with_typed
|
90
64
|
# Use Regexp.new instead of // literal to avoid different parser behaviour in 1.9 and 2.0
|
91
65
|
internal_test_case(TextParser::RegexpParser.new(Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!), 'time_format'=>"%d/%b/%Y:%H:%M:%S %z", 'types'=>'user:string,date:time:%d/%b/%Y:%H:%M:%S %z,flag:bool,path:array,code:float,size:integer'))
|
92
66
|
end
|
93
67
|
|
94
|
-
def
|
68
|
+
def test_call_with_configure
|
95
69
|
# Specify conf by configure method instaed of intializer
|
96
70
|
regexp = Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!)
|
97
71
|
parser = TextParser::RegexpParser.new(regexp)
|
@@ -101,18 +75,18 @@ module ParserTest
|
|
101
75
|
assert_equal("%d/%b/%Y:%H:%M:%S %z", parser.patterns['time_format'])
|
102
76
|
end
|
103
77
|
|
104
|
-
def
|
78
|
+
def test_call_with_typed_and_name_separator
|
105
79
|
internal_test_case(TextParser::RegexpParser.new(Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!), 'time_format'=>"%d/%b/%Y:%H:%M:%S %z", 'types'=>'user|string,date|time|%d/%b/%Y:%H:%M:%S %z,flag|bool,path|array,code|float,size|integer', 'types_label_delimiter'=>'|'))
|
106
80
|
end
|
107
81
|
|
108
|
-
def
|
82
|
+
def test_call_without_time
|
109
83
|
time_at_start = Time.now.to_i
|
110
84
|
text = "tagomori_satoshi tagomoris 34\n"
|
111
85
|
|
112
86
|
parser = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
|
113
87
|
parser.configure('types'=>'name:string,user:string,age:bool')
|
114
88
|
|
115
|
-
[parser.
|
89
|
+
[parser.call(text), parser.call(text) { |time, record| return time, record}].each { |time, record|
|
116
90
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
117
91
|
assert_equal "tagomori_satoshi", record["name"]
|
118
92
|
assert_equal "tagomoris", record["user"]
|
@@ -123,13 +97,14 @@ module ParserTest
|
|
123
97
|
parser2.configure('types'=>'name:string,user:string,age:bool')
|
124
98
|
parser2.time_default_current = false
|
125
99
|
|
126
|
-
[parser2.
|
100
|
+
[parser2.call(text), parser2.call(text) { |time, record| return time, record}].each { |time, record|
|
127
101
|
assert_equal "tagomori_satoshi", record["name"]
|
128
102
|
assert_equal "tagomoris", record["user"]
|
129
103
|
assert_equal 34, record["age"]
|
130
104
|
|
131
105
|
assert_nil time, "parser returns nil if configured so"
|
132
106
|
}
|
107
|
+
|
133
108
|
end
|
134
109
|
end
|
135
110
|
|
@@ -140,10 +115,8 @@ module ParserTest
|
|
140
115
|
@parser = TextParser::TEMPLATE_REGISTRY.lookup('apache').call
|
141
116
|
end
|
142
117
|
|
143
|
-
|
144
|
-
|
145
|
-
m = @parser.method(method_name)
|
146
|
-
m.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777') { |time, record|
|
118
|
+
def test_call
|
119
|
+
@parser.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777') { |time, record|
|
147
120
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
148
121
|
assert_equal({
|
149
122
|
'user' => '-',
|
@@ -169,22 +142,22 @@ module ParserTest
|
|
169
142
|
}
|
170
143
|
end
|
171
144
|
|
172
|
-
def
|
173
|
-
@parser.
|
145
|
+
def test_call
|
146
|
+
@parser.call('[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration') { |time, record|
|
174
147
|
assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
|
175
148
|
assert_equal(@expected, record)
|
176
149
|
}
|
177
150
|
end
|
178
151
|
|
179
|
-
def
|
180
|
-
@parser.
|
152
|
+
def test_call_with_pid
|
153
|
+
@parser.call('[Wed Oct 11 14:32:52 2000] [error] [pid 1000] [client 127.0.0.1] client denied by server configuration') { |time, record|
|
181
154
|
assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
|
182
155
|
assert_equal(@expected.merge('pid' => '1000'), record)
|
183
156
|
}
|
184
157
|
end
|
185
158
|
|
186
|
-
def
|
187
|
-
@parser.
|
159
|
+
def test_call_without_client
|
160
|
+
@parser.call('[Wed Oct 11 14:32:52 2000] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations') { |time, record|
|
188
161
|
assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
|
189
162
|
assert_equal({
|
190
163
|
'level' => 'notice',
|
@@ -199,33 +172,25 @@ module ParserTest
|
|
199
172
|
|
200
173
|
def setup
|
201
174
|
@parser = TextParser::ApacheParser.new
|
202
|
-
@expected = {
|
203
|
-
'user' => nil,
|
204
|
-
'method' => 'GET',
|
205
|
-
'code' => 200,
|
206
|
-
'size' => 777,
|
207
|
-
'host' => '192.168.0.1',
|
208
|
-
'path' => '/',
|
209
|
-
'referer' => nil,
|
210
|
-
'agent' => 'Opera/12.0'
|
211
|
-
}
|
212
175
|
end
|
213
176
|
|
214
|
-
def
|
215
|
-
@parser.
|
177
|
+
def test_call
|
178
|
+
@parser.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
|
216
179
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
217
|
-
assert_equal(
|
180
|
+
assert_equal({
|
181
|
+
'user' => nil,
|
182
|
+
'method' => 'GET',
|
183
|
+
'code' => 200,
|
184
|
+
'size' => 777,
|
185
|
+
'host' => '192.168.0.1',
|
186
|
+
'path' => '/',
|
187
|
+
'referer' => nil,
|
188
|
+
'agent' => 'Opera/12.0'
|
189
|
+
}, record)
|
218
190
|
}
|
219
191
|
assert_equal(TextParser::ApacheParser::REGEXP, @parser.patterns['format'])
|
220
192
|
assert_equal(TextParser::ApacheParser::TIME_FORMAT, @parser.patterns['time_format'])
|
221
193
|
end
|
222
|
-
|
223
|
-
def test_parse_without_http_version
|
224
|
-
@parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
|
225
|
-
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
226
|
-
assert_equal(@expected, record)
|
227
|
-
}
|
228
|
-
end
|
229
194
|
end
|
230
195
|
|
231
196
|
class SyslogParserTest < ::Test::Unit::TestCase
|
@@ -241,9 +206,9 @@ module ParserTest
|
|
241
206
|
}
|
242
207
|
end
|
243
208
|
|
244
|
-
def
|
209
|
+
def test_call
|
245
210
|
@parser.configure({})
|
246
|
-
@parser.
|
211
|
+
@parser.call('Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
|
247
212
|
assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
|
248
213
|
assert_equal(@expected, record)
|
249
214
|
}
|
@@ -251,18 +216,18 @@ module ParserTest
|
|
251
216
|
assert_equal("%b %d %H:%M:%S", @parser.patterns['time_format'])
|
252
217
|
end
|
253
218
|
|
254
|
-
def
|
219
|
+
def test_call_with_time_format
|
255
220
|
@parser.configure('time_format' => '%b %d %M:%S:%H')
|
256
|
-
@parser.
|
221
|
+
@parser.call('Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
|
257
222
|
assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
|
258
223
|
assert_equal(@expected, record)
|
259
224
|
}
|
260
225
|
assert_equal('%b %d %M:%S:%H', @parser.patterns['time_format'])
|
261
226
|
end
|
262
227
|
|
263
|
-
def
|
228
|
+
def test_call_with_priority
|
264
229
|
@parser.configure('with_priority' => true)
|
265
|
-
@parser.
|
230
|
+
@parser.call('<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
|
266
231
|
assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
|
267
232
|
assert_equal(@expected.merge('pri' => 6), record)
|
268
233
|
}
|
@@ -270,9 +235,9 @@ module ParserTest
|
|
270
235
|
assert_equal("%b %d %H:%M:%S", @parser.patterns['time_format'])
|
271
236
|
end
|
272
237
|
|
273
|
-
def
|
238
|
+
def test_call_without_colon
|
274
239
|
@parser.configure({})
|
275
|
-
@parser.
|
240
|
+
@parser.call('Feb 28 12:00:00 192.168.0.1 fluentd[11111] [error] Syslog test') { |time, record|
|
276
241
|
assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
|
277
242
|
assert_equal(@expected, record)
|
278
243
|
}
|
@@ -288,8 +253,8 @@ module ParserTest
|
|
288
253
|
@parser = TextParser::JSONParser.new
|
289
254
|
end
|
290
255
|
|
291
|
-
def
|
292
|
-
@parser.
|
256
|
+
def test_call
|
257
|
+
@parser.call('{"time":1362020400,"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
|
293
258
|
assert_equal(str2time('2013-02-28 12:00:00 +0900').to_i, time)
|
294
259
|
assert_equal({
|
295
260
|
'host' => '192.168.0.1',
|
@@ -299,10 +264,10 @@ module ParserTest
|
|
299
264
|
}
|
300
265
|
end
|
301
266
|
|
302
|
-
def
|
267
|
+
def test_call_without_time
|
303
268
|
time_at_start = Time.now.to_i
|
304
269
|
|
305
|
-
@parser.
|
270
|
+
@parser.call('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
|
306
271
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
307
272
|
assert_equal({
|
308
273
|
'host' => '192.168.0.1',
|
@@ -314,7 +279,7 @@ module ParserTest
|
|
314
279
|
parser = TextParser::JSONParser.new
|
315
280
|
parser.estimate_current_event = false
|
316
281
|
parser.configure({})
|
317
|
-
parser.
|
282
|
+
parser.call('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
|
318
283
|
assert_equal({
|
319
284
|
'host' => '192.168.0.1',
|
320
285
|
'size' => 777,
|
@@ -323,12 +288,6 @@ module ParserTest
|
|
323
288
|
assert_nil time, "parser return nil w/o time and if specified so"
|
324
289
|
}
|
325
290
|
end
|
326
|
-
|
327
|
-
def test_parse_with_invalid_time
|
328
|
-
assert_raise Fluent::ParserError do
|
329
|
-
@parser.parse('{"time":[],"k":"v"}') { |time, record| }
|
330
|
-
end
|
331
|
-
end
|
332
291
|
end
|
333
292
|
|
334
293
|
class NginxParserTest < ::Test::Unit::TestCase
|
@@ -349,26 +308,19 @@ module ParserTest
|
|
349
308
|
}
|
350
309
|
end
|
351
310
|
|
352
|
-
def
|
353
|
-
@parser.
|
311
|
+
def test_call
|
312
|
+
@parser.call('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
|
354
313
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
355
314
|
assert_equal(@expected, record)
|
356
315
|
}
|
357
316
|
end
|
358
317
|
|
359
|
-
def
|
360
|
-
@parser.
|
318
|
+
def test_call_with_empty_included_path
|
319
|
+
@parser.call('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /a[ ]b HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
|
361
320
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
362
321
|
assert_equal(@expected.merge('path' => '/a[ ]b'), record)
|
363
322
|
}
|
364
323
|
end
|
365
|
-
|
366
|
-
def test_parse_without_http_version
|
367
|
-
@parser.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
|
368
|
-
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
369
|
-
assert_equal(@expected, record)
|
370
|
-
}
|
371
|
-
end
|
372
324
|
end
|
373
325
|
|
374
326
|
class TSVParserTest < ::Test::Unit::TestCase
|
@@ -387,10 +339,10 @@ module ParserTest
|
|
387
339
|
assert_equal ",", parser.delimiter
|
388
340
|
end
|
389
341
|
|
390
|
-
def
|
342
|
+
def test_call
|
391
343
|
parser = TextParser::TSVParser.new
|
392
344
|
parser.configure('keys' => 'time,a,b', 'time_key' => 'time')
|
393
|
-
parser.
|
345
|
+
parser.call("2013/02/28 12:00:00\t192.168.0.1\t111") { |time, record|
|
394
346
|
assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
|
395
347
|
assert_equal({
|
396
348
|
'a' => '192.168.0.1',
|
@@ -399,12 +351,12 @@ module ParserTest
|
|
399
351
|
}
|
400
352
|
end
|
401
353
|
|
402
|
-
def
|
354
|
+
def test_call_with_time
|
403
355
|
time_at_start = Time.now.to_i
|
404
356
|
|
405
357
|
parser = TextParser::TSVParser.new
|
406
358
|
parser.configure('keys' => 'a,b')
|
407
|
-
parser.
|
359
|
+
parser.call("192.168.0.1\t111") { |time, record|
|
408
360
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
409
361
|
assert_equal({
|
410
362
|
'a' => '192.168.0.1',
|
@@ -415,7 +367,7 @@ module ParserTest
|
|
415
367
|
parser = TextParser::TSVParser.new
|
416
368
|
parser.estimate_current_event = false
|
417
369
|
parser.configure('keys' => 'a,b', 'time_key' => 'time')
|
418
|
-
parser.
|
370
|
+
parser.call("192.168.0.1\t111") { |time, record|
|
419
371
|
assert_equal({
|
420
372
|
'a' => '192.168.0.1',
|
421
373
|
'b' => '111',
|
@@ -423,32 +375,15 @@ module ParserTest
|
|
423
375
|
assert_nil time, "parser returns nil w/o time and if configured so"
|
424
376
|
}
|
425
377
|
end
|
426
|
-
|
427
|
-
data(
|
428
|
-
'left blank column' => ["\t@\t@", {"1" => "","2" => "@","3" => "@"}],
|
429
|
-
'center blank column' => ["@\t\t@", {"1" => "@","2" => "","3" => "@"}],
|
430
|
-
'right blank column' => ["@\t@\t", {"1" => "@","2" => "@","3" => ""}],
|
431
|
-
'2 right blank columns' => ["@\t\t", {"1" => "@","2" => "","3" => ""}],
|
432
|
-
'left blank columns' => ["\t\t@", {"1" => "","2" => "","3" => "@"}],
|
433
|
-
'all blank columns' => ["\t\t", {"1" => "","2" => "","3" => ""}])
|
434
|
-
def test_black_column(data)
|
435
|
-
line, expected = data
|
436
|
-
|
437
|
-
parser = TextParser::TSVParser.new
|
438
|
-
parser.configure('keys' => '1,2,3')
|
439
|
-
parser.parse(line) { |time, record|
|
440
|
-
assert_equal(expected, record)
|
441
|
-
}
|
442
|
-
end
|
443
378
|
end
|
444
379
|
|
445
380
|
class CSVParserTest < ::Test::Unit::TestCase
|
446
381
|
include ParserTest
|
447
382
|
|
448
|
-
def
|
383
|
+
def test_call
|
449
384
|
parser = TextParser::CSVParser.new
|
450
385
|
parser.configure('keys' => 'time,c,d', 'time_key' => 'time')
|
451
|
-
parser.
|
386
|
+
parser.call("2013/02/28 12:00:00,192.168.0.1,111") { |time, record|
|
452
387
|
assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
|
453
388
|
assert_equal({
|
454
389
|
'c' => '192.168.0.1',
|
@@ -457,12 +392,12 @@ module ParserTest
|
|
457
392
|
}
|
458
393
|
end
|
459
394
|
|
460
|
-
def
|
395
|
+
def test_call_without_time
|
461
396
|
time_at_start = Time.now.to_i
|
462
397
|
|
463
398
|
parser = TextParser::CSVParser.new
|
464
399
|
parser.configure('keys' => 'c,d')
|
465
|
-
parser.
|
400
|
+
parser.call("192.168.0.1,111") { |time, record|
|
466
401
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
467
402
|
assert_equal({
|
468
403
|
'c' => '192.168.0.1',
|
@@ -473,7 +408,7 @@ module ParserTest
|
|
473
408
|
parser = TextParser::CSVParser.new
|
474
409
|
parser.estimate_current_event = false
|
475
410
|
parser.configure('keys' => 'c,d', 'time_key' => 'time')
|
476
|
-
parser.
|
411
|
+
parser.call("192.168.0.1,111") { |time, record|
|
477
412
|
assert_equal({
|
478
413
|
'c' => '192.168.0.1',
|
479
414
|
'd' => '111',
|
@@ -501,10 +436,10 @@ module ParserTest
|
|
501
436
|
assert_equal "=", parser.label_delimiter
|
502
437
|
end
|
503
438
|
|
504
|
-
def
|
439
|
+
def test_call
|
505
440
|
parser = TextParser::LabeledTSVParser.new
|
506
441
|
parser.configure({})
|
507
|
-
parser.
|
442
|
+
parser.call("time:2013/02/28 12:00:00\thost:192.168.0.1\treq_id:111") { |time, record|
|
508
443
|
assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
|
509
444
|
assert_equal({
|
510
445
|
'host' => '192.168.0.1',
|
@@ -513,13 +448,13 @@ module ParserTest
|
|
513
448
|
}
|
514
449
|
end
|
515
450
|
|
516
|
-
def
|
451
|
+
def test_call_with_customized_delimiter
|
517
452
|
parser = TextParser::LabeledTSVParser.new
|
518
453
|
parser.configure(
|
519
454
|
'delimiter' => ',',
|
520
455
|
'label_delimiter' => '=',
|
521
456
|
)
|
522
|
-
parser.
|
457
|
+
parser.call('time=2013/02/28 12:00:00,host=192.168.0.1,req_id=111') { |time, record|
|
523
458
|
assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
|
524
459
|
assert_equal({
|
525
460
|
'host' => '192.168.0.1',
|
@@ -528,13 +463,13 @@ module ParserTest
|
|
528
463
|
}
|
529
464
|
end
|
530
465
|
|
531
|
-
def
|
466
|
+
def test_call_with_customized_time_format
|
532
467
|
parser = TextParser::LabeledTSVParser.new
|
533
468
|
parser.configure(
|
534
469
|
'time_key' => 'mytime',
|
535
470
|
'time_format' => '%d/%b/%Y:%H:%M:%S %z',
|
536
471
|
)
|
537
|
-
parser.
|
472
|
+
parser.call("mytime:28/Feb/2013:12:00:00 +0900\thost:192.168.0.1\treq_id:111") { |time, record|
|
538
473
|
assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
|
539
474
|
assert_equal({
|
540
475
|
'host' => '192.168.0.1',
|
@@ -543,12 +478,12 @@ module ParserTest
|
|
543
478
|
}
|
544
479
|
end
|
545
480
|
|
546
|
-
def
|
481
|
+
def test_call_without_time
|
547
482
|
time_at_start = Time.now.to_i
|
548
483
|
|
549
484
|
parser = TextParser::LabeledTSVParser.new
|
550
485
|
parser.configure({})
|
551
|
-
parser.
|
486
|
+
parser.call("host:192.168.0.1\treq_id:111") { |time, record|
|
552
487
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
553
488
|
assert_equal({
|
554
489
|
'host' => '192.168.0.1',
|
@@ -559,7 +494,7 @@ module ParserTest
|
|
559
494
|
parser = TextParser::LabeledTSVParser.new
|
560
495
|
parser.estimate_current_event = false
|
561
496
|
parser.configure({})
|
562
|
-
parser.
|
497
|
+
parser.call("host:192.168.0.1\treq_id:111") { |time, record|
|
563
498
|
assert_equal({
|
564
499
|
'host' => '192.168.0.1',
|
565
500
|
'req_id' => '111',
|
@@ -581,28 +516,28 @@ module ParserTest
|
|
581
516
|
assert_equal "foobar", parser.message_key
|
582
517
|
end
|
583
518
|
|
584
|
-
def
|
519
|
+
def test_call
|
585
520
|
parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
|
586
521
|
parser.configure({})
|
587
|
-
parser.
|
522
|
+
parser.call('log message!') { |time, record|
|
588
523
|
assert_equal({'message' => 'log message!'}, record)
|
589
524
|
}
|
590
525
|
end
|
591
526
|
|
592
|
-
def
|
527
|
+
def test_call_with_message_key
|
593
528
|
parser = TextParser::NoneParser.new
|
594
529
|
parser.configure('message_key' => 'foobar')
|
595
|
-
parser.
|
530
|
+
parser.call('log message!') { |time, record|
|
596
531
|
assert_equal({'foobar' => 'log message!'}, record)
|
597
532
|
}
|
598
533
|
end
|
599
534
|
|
600
|
-
def
|
535
|
+
def test_call_without_default_time
|
601
536
|
time_at_start = Time.now.to_i
|
602
537
|
|
603
538
|
parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
|
604
539
|
parser.configure({})
|
605
|
-
parser.
|
540
|
+
parser.call('log message!') { |time, record|
|
606
541
|
assert time && time >= time_at_start, "parser puts current time without time input"
|
607
542
|
assert_equal({'message' => 'log message!'}, record)
|
608
543
|
}
|
@@ -610,7 +545,7 @@ module ParserTest
|
|
610
545
|
parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
|
611
546
|
parser.estimate_current_event = false
|
612
547
|
parser.configure({})
|
613
|
-
parser.
|
548
|
+
parser.call('log message!') { |time, record|
|
614
549
|
assert_equal({'message' => 'log message!'}, record)
|
615
550
|
assert_nil time, "parser returns nil w/o time if configured so"
|
616
551
|
}
|
@@ -634,9 +569,9 @@ module ParserTest
|
|
634
569
|
}
|
635
570
|
end
|
636
571
|
|
637
|
-
def
|
572
|
+
def test_call
|
638
573
|
parser = create_parser('format1' => '/^(?<time>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) \[(?<thread>.*)\] (?<level>[^\s]+)(?<message>.*)/')
|
639
|
-
parser.
|
574
|
+
parser.call(<<EOS.chomp) { |time, record|
|
640
575
|
2013-3-03 14:27:33 [main] ERROR Main - Exception
|
641
576
|
javax.management.RuntimeErrorException: null
|
642
577
|
\tat Main.main(Main.java:16) ~[bin/:na]
|
@@ -651,9 +586,9 @@ EOS
|
|
651
586
|
}
|
652
587
|
end
|
653
588
|
|
654
|
-
def
|
589
|
+
def test_call_with_firstline
|
655
590
|
parser = create_parser('format_firstline' => '/----/', 'format1' => '/time=(?<time>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}).*message=(?<message>.*)/')
|
656
|
-
parser.
|
591
|
+
parser.call(<<EOS.chomp) { |time, record|
|
657
592
|
----
|
658
593
|
time=2013-3-03 14:27:33
|
659
594
|
message=test1
|
@@ -665,7 +600,7 @@ EOS
|
|
665
600
|
}
|
666
601
|
end
|
667
602
|
|
668
|
-
def
|
603
|
+
def test_call_with_multiple_formats
|
669
604
|
parser = create_parser('format_firstline' => '/^Started/',
|
670
605
|
'format1' => '/Started (?<method>[^ ]+) "(?<path>[^"]+)" for (?<host>[^ ]+) at (?<time>[^ ]+ [^ ]+ [^ ]+)\n/',
|
671
606
|
'format2' => '/Processing by (?<controller>[^\u0023]+)\u0023(?<controller_method>[^ ]+) as (?<format>[^ ]+?)\n/',
|
@@ -673,7 +608,7 @@ EOS
|
|
673
608
|
'format4' => '/ Rendered (?<template>[^ ]+) within (?<layout>.+) \([\d\.]+ms\)\n/',
|
674
609
|
'format5' => '/Completed (?<code>[^ ]+) [^ ]+ in (?<runtime>[\d\.]+)ms \(Views: (?<view_runtime>[\d\.]+)ms \| ActiveRecord: (?<ar_runtime>[\d\.]+)ms\)/'
|
675
610
|
)
|
676
|
-
parser.
|
611
|
+
parser.call(<<EOS.chomp) { |time, record|
|
677
612
|
Started GET "/users/123/" for 127.0.0.1 at 2013-06-14 12:00:11 +0900
|
678
613
|
Processing by UsersController#show as HTML
|
679
614
|
Parameters: {"user_id"=>"123"}
|
@@ -705,10 +640,10 @@ EOS
|
|
705
640
|
class TextParserTest < ::Test::Unit::TestCase
|
706
641
|
include ParserTest
|
707
642
|
|
708
|
-
class MultiEventTestParser
|
643
|
+
class MultiEventTestParser
|
709
644
|
include Fluent::Configurable
|
710
645
|
|
711
|
-
def
|
646
|
+
def call(text)
|
712
647
|
2.times { |i|
|
713
648
|
record = {}
|
714
649
|
record['message'] = text
|
@@ -726,13 +661,11 @@ EOS
|
|
726
661
|
end
|
727
662
|
end
|
728
663
|
|
729
|
-
|
730
|
-
def test_lookup_known_parser(data)
|
664
|
+
def test_lookup_known_parser
|
731
665
|
$LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), 'scripts'))
|
732
666
|
assert_nothing_raised ConfigError do
|
733
|
-
TextParser::TEMPLATE_REGISTRY.lookup(
|
667
|
+
TextParser::TEMPLATE_REGISTRY.lookup('known')
|
734
668
|
end
|
735
|
-
$LOAD_PATH.shift
|
736
669
|
end
|
737
670
|
|
738
671
|
def test_parse_with_return
|