fluentd 0.14.0 → 0.14.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.

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/example/copy_roundrobin.conf +39 -0
  3. data/example/filter_stdout.conf +5 -5
  4. data/example/in_forward.conf +2 -2
  5. data/example/in_http.conf +2 -2
  6. data/example/in_syslog.conf +2 -2
  7. data/example/in_tail.conf +2 -2
  8. data/example/in_tcp.conf +2 -2
  9. data/example/in_udp.conf +2 -2
  10. data/example/out_buffered_null.conf +32 -0
  11. data/example/out_copy.conf +4 -4
  12. data/example/out_file.conf +2 -2
  13. data/example/out_forward.conf +2 -2
  14. data/example/v0_12_filter.conf +8 -8
  15. data/fluentd.gemspec +1 -1
  16. data/lib/fluent/command/fluentd.rb +6 -1
  17. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  18. data/lib/fluent/compat/input.rb +1 -0
  19. data/lib/fluent/compat/output.rb +1 -0
  20. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  21. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  22. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  23. data/lib/fluent/compat/type_converter.rb +90 -0
  24. data/lib/fluent/config/configure_proxy.rb +24 -4
  25. data/lib/fluent/config/dsl.rb +18 -1
  26. data/lib/fluent/config/v1_parser.rb +3 -2
  27. data/lib/fluent/configurable.rb +1 -1
  28. data/lib/fluent/event.rb +37 -9
  29. data/lib/fluent/mixin.rb +12 -286
  30. data/lib/fluent/plugin/buffer.rb +2 -2
  31. data/lib/fluent/plugin/in_dummy.rb +5 -1
  32. data/lib/fluent/plugin/in_gc_stat.rb +7 -37
  33. data/lib/fluent/plugin/in_http.rb +2 -0
  34. data/lib/fluent/plugin/{in_stream.rb → in_unix.rb} +0 -0
  35. data/lib/fluent/plugin/out_buffered_stdout.rb +60 -0
  36. data/lib/fluent/plugin/out_copy.rb +8 -51
  37. data/lib/fluent/plugin/out_null.rb +5 -5
  38. data/lib/fluent/plugin/out_relabel.rb +5 -5
  39. data/lib/fluent/plugin/out_roundrobin.rb +13 -40
  40. data/lib/fluent/plugin/output.rb +9 -0
  41. data/lib/fluent/plugin_helper.rb +2 -0
  42. data/lib/fluent/plugin_helper/formatter.rb +138 -0
  43. data/lib/fluent/plugin_helper/inject.rb +112 -0
  44. data/lib/fluent/plugin_helper/parser.rb +138 -0
  45. data/lib/fluent/plugin_helper/storage.rb +64 -50
  46. data/lib/fluent/process.rb +6 -1
  47. data/lib/fluent/registry.rb +1 -1
  48. data/lib/fluent/supervisor.rb +20 -2
  49. data/lib/fluent/test.rb +30 -5
  50. data/lib/fluent/test/base.rb +2 -66
  51. data/lib/fluent/test/driver/base.rb +3 -0
  52. data/lib/fluent/test/driver/base_owned.rb +106 -0
  53. data/lib/fluent/test/driver/formatter.rb +30 -0
  54. data/lib/fluent/test/driver/multi_output.rb +52 -0
  55. data/lib/fluent/test/driver/owner.rb +32 -0
  56. data/lib/fluent/test/driver/parser.rb +30 -0
  57. data/lib/fluent/test/helpers.rb +54 -0
  58. data/lib/fluent/test/log.rb +73 -0
  59. data/lib/fluent/time.rb +71 -0
  60. data/lib/fluent/version.rb +1 -1
  61. data/test/compat/test_parser.rb +82 -0
  62. data/test/config/test_configure_proxy.rb +15 -0
  63. data/test/config/test_dsl.rb +180 -2
  64. data/test/helper.rb +2 -24
  65. data/test/plugin/test_in_gc_stat.rb +6 -6
  66. data/test/plugin/test_in_http.rb +49 -32
  67. data/test/plugin/{test_in_stream.rb → test_in_unix.rb} +1 -1
  68. data/test/plugin/test_out_buffered_stdout.rb +108 -0
  69. data/test/plugin/test_out_copy.rb +88 -127
  70. data/test/plugin/test_out_null.rb +29 -0
  71. data/test/plugin/test_out_relabel.rb +28 -0
  72. data/test/plugin/test_out_roundrobin.rb +35 -29
  73. data/test/plugin/test_out_stdout.rb +4 -4
  74. data/test/plugin/test_output_as_buffered.rb +51 -0
  75. data/test/plugin/test_output_as_buffered_secondary.rb +13 -0
  76. data/test/plugin/test_parser_apache.rb +38 -0
  77. data/test/plugin/test_parser_apache2.rb +38 -0
  78. data/test/plugin/test_parser_apache_error.rb +40 -0
  79. data/test/plugin/test_parser_base.rb +32 -0
  80. data/test/plugin/test_parser_csv.rb +94 -0
  81. data/test/plugin/test_parser_json.rb +107 -0
  82. data/test/plugin/test_parser_labeled_tsv.rb +129 -0
  83. data/test/plugin/test_parser_multiline.rb +100 -0
  84. data/test/plugin/test_parser_nginx.rb +42 -0
  85. data/test/plugin/test_parser_none.rb +53 -0
  86. data/test/plugin/test_parser_regexp.rb +110 -0
  87. data/test/plugin/test_parser_syslog.rb +66 -0
  88. data/test/plugin/test_parser_time.rb +46 -0
  89. data/test/plugin/test_parser_tsv.rb +125 -0
  90. data/test/plugin_helper/test_child_process.rb +11 -2
  91. data/test/plugin_helper/test_formatter.rb +212 -0
  92. data/test/plugin_helper/test_inject.rb +388 -0
  93. data/test/plugin_helper/test_parser.rb +223 -0
  94. data/test/plugin_helper/test_retry_state.rb +40 -40
  95. data/test/plugin_helper/test_storage.rb +77 -10
  96. data/test/scripts/fluent/plugin/out_test.rb +22 -17
  97. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  98. data/test/test_event.rb +57 -0
  99. data/test/test_formatter.rb +0 -178
  100. data/test/test_output.rb +2 -152
  101. data/test/test_root_agent.rb +3 -2
  102. data/test/test_supervisor.rb +93 -26
  103. data/test/test_time_formatter.rb +186 -0
  104. metadata +69 -7
  105. data/test/test_parser.rb +0 -1087
@@ -1,1087 +0,0 @@
1
- require_relative 'helper'
2
- require 'fluent/test'
3
- require 'fluent/parser'
4
-
5
- module ParserTest
6
- include Fluent
7
-
8
- def setup
9
- Fluent::Test.setup
10
- end
11
-
12
- def str2time(str_time, format = nil)
13
- if format
14
- Fluent::EventTime.from_time(Time.strptime(str_time, format))
15
- else
16
- Fluent::EventTime.parse(str_time)
17
- end
18
- end
19
-
20
- class BaseParserTest < ::Test::Unit::TestCase
21
- include ParserTest
22
-
23
- def create_parser
24
- parser = Parser.new
25
- parser.configure({})
26
- parser
27
- end
28
-
29
- def test_init
30
- assert_true create_parser.estimate_current_event
31
- end
32
-
33
- def test_parse
34
- assert_raise NotImplementedError do
35
- create_parser.parse('')
36
- end
37
- end
38
-
39
- def test_call
40
- assert_raise NotImplementedError do
41
- create_parser.call('')
42
- end
43
- end
44
- end
45
-
46
- class BaseParserTestWithTestDriver < ::Test::Unit::TestCase
47
- include ParserTest
48
-
49
- def create_driver(conf={})
50
- Fluent::Test::ParserTestDriver.new(Fluent::Parser).configure(conf)
51
- end
52
-
53
- def test_init
54
- d = create_driver
55
- assert_true d.instance.estimate_current_event
56
- end
57
-
58
- def test_configure_against_string_literal
59
- d = create_driver('keep_time_key true')
60
- assert_true d.instance.keep_time_key
61
- end
62
-
63
- def test_parse
64
- d = create_driver
65
- assert_raise NotImplementedError do
66
- d.parse('')
67
- end
68
- end
69
- end
70
-
71
- class TimeParserTest < ::Test::Unit::TestCase
72
- include ParserTest
73
-
74
- def test_call_with_parse
75
- parser = TextParser::TimeParser.new(nil)
76
-
77
- assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::EventTime))
78
-
79
- time = str2time('2013-09-18 12:00:00 +0900')
80
- assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900'))
81
- end
82
-
83
- def test_parse_with_strptime
84
- parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z')
85
-
86
- assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::EventTime))
87
-
88
- time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z')
89
- assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900'))
90
- end
91
-
92
- def test_parse_nsec_with_strptime
93
- parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S:%N %z')
94
-
95
- assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::EventTime))
96
-
97
- time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z')
98
- assert_equal_event_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900'))
99
- end
100
-
101
- def test_parse_with_invalid_argument
102
- parser = TextParser::TimeParser.new(nil)
103
-
104
- [[], {}, nil, true, 10000, //, ->{}, '', :symbol].each { |v|
105
- assert_raise Fluent::ParserError do
106
- parser.parse(v)
107
- end
108
- }
109
- end
110
- end
111
-
112
- class RegexpParserTest < ::Test::Unit::TestCase
113
- include ParserTest
114
-
115
- def internal_test_case(parser)
116
- 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'
117
- parser.parse(text) { |time, record|
118
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
119
- assert_equal({
120
- 'user' => '-',
121
- 'flag' => true,
122
- 'code' => 200.0,
123
- 'size' => 777,
124
- 'date' => str2time('14/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'),
125
- 'host' => '192.168.0.1',
126
- 'path' => ['/', '/user']
127
- }, record)
128
- }
129
- end
130
-
131
- def test_parse_with_typed
132
- # Use Regexp.new instead of // literal to avoid different parser behaviour in 1.9 and 2.0
133
- 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'))
134
- end
135
-
136
- def test_parse_with_configure
137
- # Specify conf by configure method instaed of intializer
138
- regexp = Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!)
139
- parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, regexp)
140
- parser.configure('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')
141
- internal_test_case(parser)
142
- assert_equal(regexp, parser.instance.patterns['format'])
143
- assert_equal("%d/%b/%Y:%H:%M:%S %z", parser.instance.patterns['time_format'])
144
- end
145
-
146
- def test_parse_with_typed_and_name_separator
147
- internal_test_case(Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, 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'=>'|'))
148
- end
149
-
150
- def test_parse_with_time_key
151
- parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, /(?<logtime>[^\]]*)/)
152
- parser.configure(
153
- 'time_format'=>"%Y-%m-%d %H:%M:%S %z",
154
- 'time_key'=>'logtime',
155
- )
156
- text = '2013-02-28 12:00:00 +0900'
157
- parser.parse(text) do |time, record|
158
- assert_equal Fluent::EventTime.parse(text), time
159
- end
160
- end
161
-
162
- def test_parse_without_time
163
- time_at_start = Time.now.to_i
164
- text = "tagomori_satoshi tagomoris 34\n"
165
-
166
- parser = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
167
- parser.configure('types'=>'name:string,user:string,age:integer')
168
-
169
- parser.parse(text) { |time, record|
170
- assert time && time >= time_at_start, "parser puts current time without time input"
171
- assert_equal "tagomori_satoshi", record["name"]
172
- assert_equal "tagomoris", record["user"]
173
- assert_equal 34, record["age"]
174
- }
175
-
176
- parser2 = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
177
- parser2.configure('types'=>'name:string,user:string,age:integer')
178
- parser2.instance.estimate_current_event = false
179
-
180
- parser2.parse(text) { |time, record|
181
- assert_equal "tagomori_satoshi", record["name"]
182
- assert_equal "tagomoris", record["user"]
183
- assert_equal 34, record["age"]
184
-
185
- assert_nil time, "parser returns nil if configured so"
186
- }
187
- end
188
-
189
- def test_parse_with_keep_time_key
190
- parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser,
191
- Regexp.new(%q!(?<time>.*)!),
192
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
193
- 'keep_time_key'=>'true',
194
- )
195
- text = '28/Feb/2013:12:00:00 +0900'
196
- parser.parse(text) do |time, record|
197
- assert_equal text, record['time']
198
- end
199
- end
200
-
201
- def test_parse_with_keep_time_key_with_typecast
202
- parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser,
203
- Regexp.new(%q!(?<time>.*)!),
204
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
205
- 'keep_time_key'=>'true',
206
- 'types'=>'time:time:%d/%b/%Y:%H:%M:%S %z',
207
- )
208
- text = '28/Feb/2013:12:00:00 +0900'
209
- parser.parse(text) do |time, record|
210
- assert_equal 1362020400, record['time']
211
- end
212
- end
213
- end
214
-
215
- class ApacheParserTest < ::Test::Unit::TestCase
216
- include ParserTest
217
-
218
- def setup
219
- @parser = Fluent::Plugin.new_parser('apache')
220
- end
221
-
222
- data('parse' => :parse, 'call' => :call)
223
- def test_call(method_name)
224
- m = @parser.method(method_name)
225
- m.call('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777') { |time, record|
226
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
227
- assert_equal({
228
- 'user' => '-',
229
- 'method' => 'GET',
230
- 'code' => '200',
231
- 'size' => '777',
232
- 'host' => '192.168.0.1',
233
- 'path' => '/'
234
- }, record)
235
- }
236
- end
237
-
238
- def test_parse_with_keep_time_key
239
- parser = TextParser::ApacheParser.new
240
- parser.configure(
241
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
242
- 'keep_time_key'=>'true',
243
- )
244
- text = '192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777'
245
- parser.parse(text) do |time, record|
246
- assert_equal "28/Feb/2013:12:00:00 +0900", record['time']
247
- end
248
- end
249
- end
250
-
251
- class ApacheErrorParserTest < ::Test::Unit::TestCase
252
- include ParserTest
253
-
254
- def setup
255
- @parser = Fluent::Plugin.new_parser('apache_error')
256
- @parser.configure({})
257
- @expected = {
258
- 'level' => 'error',
259
- 'client' => '127.0.0.1',
260
- 'message' => 'client denied by server configuration'
261
- }
262
- end
263
-
264
- def test_parse
265
- @parser.parse('[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration') { |time, record|
266
- assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
267
- assert_equal(@expected, record)
268
- }
269
- end
270
-
271
- def test_parse_with_pid
272
- @parser.parse('[Wed Oct 11 14:32:52 2000] [error] [pid 1000] [client 127.0.0.1] client denied by server configuration') { |time, record|
273
- assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
274
- assert_equal(@expected.merge('pid' => '1000'), record)
275
- }
276
- end
277
-
278
- def test_parse_without_client
279
- @parser.parse('[Wed Oct 11 14:32:52 2000] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations') { |time, record|
280
- assert_equal(str2time('Wed Oct 11 14:32:52 2000'), time)
281
- assert_equal({
282
- 'level' => 'notice',
283
- 'message' => 'Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations'
284
- }, record)
285
- }
286
- end
287
- end
288
-
289
- class Apache2ParserTest < ::Test::Unit::TestCase
290
- include ParserTest
291
-
292
- def setup
293
- @parser = TextParser::ApacheParser.new
294
- @expected = {
295
- 'user' => nil,
296
- 'method' => 'GET',
297
- 'code' => 200,
298
- 'size' => 777,
299
- 'host' => '192.168.0.1',
300
- 'path' => '/',
301
- 'referer' => nil,
302
- 'agent' => 'Opera/12.0'
303
- }
304
- end
305
-
306
- def test_parse
307
- @parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
308
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
309
- assert_equal(@expected, record)
310
- }
311
- assert_equal(TextParser::ApacheParser::REGEXP, @parser.patterns['format'])
312
- assert_equal(TextParser::ApacheParser::TIME_FORMAT, @parser.patterns['time_format'])
313
- end
314
-
315
- def test_parse_without_http_version
316
- @parser.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
317
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
318
- assert_equal(@expected, record)
319
- }
320
- end
321
- end
322
-
323
- class SyslogParserTest < ::Test::Unit::TestCase
324
- include ParserTest
325
-
326
- def setup
327
- @parser = Fluent::Test::ParserTestDriver.new('syslog')
328
- @expected = {
329
- 'host' => '192.168.0.1',
330
- 'ident' => 'fluentd',
331
- 'pid' => '11111',
332
- 'message' => '[error] Syslog test'
333
- }
334
- end
335
-
336
- def test_parse
337
- @parser.configure({})
338
- @parser.parse('Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
339
- assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
340
- assert_equal(@expected, record)
341
- }
342
- assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
343
- assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
344
- end
345
-
346
- def test_parse_with_time_format
347
- @parser.configure('time_format' => '%b %d %M:%S:%H')
348
- @parser.parse('Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
349
- assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
350
- assert_equal(@expected, record)
351
- }
352
- assert_equal('%b %d %M:%S:%H', @parser.instance.patterns['time_format'])
353
- end
354
-
355
- def test_parse_with_priority
356
- @parser.configure('with_priority' => true)
357
- @parser.parse('<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
358
- assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
359
- assert_equal(@expected.merge('pri' => 6), record)
360
- }
361
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
362
- assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
363
- end
364
-
365
- def test_parse_without_colon
366
- @parser.configure({})
367
- @parser.parse('Feb 28 12:00:00 192.168.0.1 fluentd[11111] [error] Syslog test') { |time, record|
368
- assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
369
- assert_equal(@expected, record)
370
- }
371
- assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
372
- assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
373
- end
374
-
375
- def test_parse_with_keep_time_key
376
- @parser.configure(
377
- 'time_format' => '%b %d %M:%S:%H',
378
- 'keep_time_key'=>'true',
379
- )
380
- text = 'Feb 28 00:00:12 192.168.0.1 fluentd[11111]: [error] Syslog test'
381
- @parser.parse(text) do |time, record|
382
- assert_equal "Feb 28 00:00:12", record['time']
383
- end
384
- end
385
- end
386
-
387
- class JsonParserTest < ::Test::Unit::TestCase
388
- include ParserTest
389
-
390
- def setup
391
- @parser = TextParser::JSONParser.new
392
- end
393
-
394
- data('oj' => 'oj', 'yajl' => 'yajl')
395
- def test_parse(data)
396
- @parser.configure('json_parser' => data)
397
- @parser.parse('{"time":1362020400,"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
398
- assert_equal(str2time('2013-02-28 12:00:00 +0900').to_i, time)
399
- assert_equal({
400
- 'host' => '192.168.0.1',
401
- 'size' => 777,
402
- 'method' => 'PUT',
403
- }, record)
404
- }
405
- end
406
-
407
- data('oj' => 'oj', 'yajl' => 'yajl')
408
- def test_parse_with_large_float(data)
409
- @parser.configure('json_parser' => data)
410
- @parser.parse('{"num":999999999999999999999999999999.99999}') { |time, record|
411
- assert_equal(Float, record['num'].class)
412
- }
413
- end
414
-
415
- data('oj' => 'oj', 'yajl' => 'yajl')
416
- def test_parse_without_time(data)
417
- time_at_start = Time.now.to_i
418
-
419
- @parser.configure('json_parser' => data)
420
- @parser.parse('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
421
- assert time && time >= time_at_start, "parser puts current time without time input"
422
- assert_equal({
423
- 'host' => '192.168.0.1',
424
- 'size' => 777,
425
- 'method' => 'PUT',
426
- }, record)
427
- }
428
-
429
- parser = TextParser::JSONParser.new
430
- parser.estimate_current_event = false
431
- parser.configure('json_parser' => data)
432
- parser.parse('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
433
- assert_equal({
434
- 'host' => '192.168.0.1',
435
- 'size' => 777,
436
- 'method' => 'PUT',
437
- }, record)
438
- assert_nil time, "parser return nil w/o time and if specified so"
439
- }
440
- end
441
-
442
- data('oj' => 'oj', 'yajl' => 'yajl')
443
- def test_parse_with_invalid_time(data)
444
- @parser.configure('json_parser' => data)
445
- assert_raise Fluent::ParserError do
446
- @parser.parse('{"time":[],"k":"v"}') { |time, record| }
447
- end
448
- end
449
-
450
- data('oj' => 'oj', 'yajl' => 'yajl')
451
- def test_parse_float_time(data)
452
- parser = TextParser::JSONParser.new
453
- parser.configure('json_parser' => data)
454
- text = "100.1"
455
- parser.parse("{\"time\":\"#{text}\"}") do |time, record|
456
- assert_equal Time.at(text.to_f).to_i, time.sec
457
- assert_equal Time.at(text.to_f).nsec, time.nsec
458
- end
459
- end
460
-
461
- data('oj' => 'oj', 'yajl' => 'yajl')
462
- def test_parse_with_keep_time_key(data)
463
- parser = TextParser::JSONParser.new
464
- format = "%d/%b/%Y:%H:%M:%S %z"
465
- parser.configure(
466
- 'time_format' => format,
467
- 'keep_time_key' => 'true',
468
- 'json_parser' => data
469
- )
470
- text = "28/Feb/2013:12:00:00 +0900"
471
- parser.parse("{\"time\":\"#{text}\"}") do |time, record|
472
- assert_equal Time.strptime(text, format).to_i, time.sec
473
- assert_equal text, record['time']
474
- end
475
- end
476
-
477
- data('oj' => 'oj', 'yajl' => 'yajl')
478
- def test_parse_with_keep_time_key_without_time_format(data)
479
- parser = TextParser::JSONParser.new
480
- parser.configure(
481
- 'keep_time_key' => 'true',
482
- 'json_parser' => data
483
- )
484
- text = "100"
485
- parser.parse("{\"time\":\"#{text}\"}") do |time, record|
486
- assert_equal text.to_i, time.sec
487
- assert_equal text, record['time']
488
- end
489
- end
490
- end
491
-
492
- class NginxParserTest < ::Test::Unit::TestCase
493
- include ParserTest
494
-
495
- def setup
496
- @parser = Fluent::Plugin.new_parser('nginx')
497
- @expected = {
498
- 'remote' => '127.0.0.1',
499
- 'host' => '192.168.0.1',
500
- 'user' => '-',
501
- 'method' => 'GET',
502
- 'path' => '/',
503
- 'code' => '200',
504
- 'size' => '777',
505
- 'referer' => '-',
506
- 'agent' => 'Opera/12.0'
507
- }
508
- end
509
-
510
- def test_parse
511
- @parser.parse('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|
512
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
513
- assert_equal(@expected, record)
514
- }
515
- end
516
-
517
- def test_parse_with_empty_included_path
518
- @parser.parse('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|
519
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
520
- assert_equal(@expected.merge('path' => '/a[ ]b'), record)
521
- }
522
- end
523
-
524
- def test_parse_without_http_version
525
- @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|
526
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
527
- assert_equal(@expected, record)
528
- }
529
- end
530
- end
531
-
532
- class TSVParserTest < ::Test::Unit::TestCase
533
- include ParserTest
534
-
535
- data('array param' => '["a","b"]', 'string param' => 'a,b')
536
- def test_config_params(param)
537
- parser = TextParser::TSVParser.new
538
-
539
- assert_equal "\t", parser.delimiter
540
-
541
- parser.configure(
542
- 'keys' => param,
543
- 'delimiter' => ',',
544
- )
545
-
546
- assert_equal ['a', 'b'], parser.keys
547
- assert_equal ",", parser.delimiter
548
- end
549
-
550
- data('array param' => '["time","a","b"]', 'string param' => 'time,a,b')
551
- def test_parse(param)
552
- parser = TextParser::TSVParser.new
553
- parser.configure('keys' => param, 'time_key' => 'time')
554
- parser.parse("2013/02/28 12:00:00\t192.168.0.1\t111") { |time, record|
555
- assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
556
- assert_equal({
557
- 'a' => '192.168.0.1',
558
- 'b' => '111',
559
- }, record)
560
- }
561
- end
562
-
563
- def test_parse_with_time
564
- time_at_start = Time.now.to_i
565
-
566
- parser = TextParser::TSVParser.new
567
- parser.configure('keys' => 'a,b')
568
- parser.parse("192.168.0.1\t111") { |time, record|
569
- assert time && time >= time_at_start, "parser puts current time without time input"
570
- assert_equal({
571
- 'a' => '192.168.0.1',
572
- 'b' => '111',
573
- }, record)
574
- }
575
-
576
- parser = TextParser::TSVParser.new
577
- parser.estimate_current_event = false
578
- parser.configure('keys' => 'a,b', 'time_key' => 'time')
579
- parser.parse("192.168.0.1\t111") { |time, record|
580
- assert_equal({
581
- 'a' => '192.168.0.1',
582
- 'b' => '111',
583
- }, record)
584
- assert_nil time, "parser returns nil w/o time and if configured so"
585
- }
586
- end
587
-
588
- data(
589
- 'left blank column' => ["\t@\t@", {"1" => "","2" => "@","3" => "@"}],
590
- 'center blank column' => ["@\t\t@", {"1" => "@","2" => "","3" => "@"}],
591
- 'right blank column' => ["@\t@\t", {"1" => "@","2" => "@","3" => ""}],
592
- '2 right blank columns' => ["@\t\t", {"1" => "@","2" => "","3" => ""}],
593
- 'left blank columns' => ["\t\t@", {"1" => "","2" => "","3" => "@"}],
594
- 'all blank columns' => ["\t\t", {"1" => "","2" => "","3" => ""}])
595
- def test_black_column(data)
596
- line, expected = data
597
-
598
- parser = TextParser::TSVParser.new
599
- parser.configure('keys' => '1,2,3')
600
- parser.parse(line) { |time, record|
601
- assert_equal(expected, record)
602
- }
603
- end
604
-
605
- def test_parse_with_keep_time_key
606
- parser = TextParser::TSVParser.new
607
- parser.configure(
608
- 'keys'=>'time',
609
- 'time_key'=>'time',
610
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
611
- 'keep_time_key'=>'true',
612
- )
613
- text = '28/Feb/2013:12:00:00 +0900'
614
- parser.parse(text) do |time, record|
615
- assert_equal text, record['time']
616
- end
617
- end
618
-
619
- data('array param' => '["a","b","c","d","e","f"]', 'string param' => 'a,b,c,d,e,f')
620
- def test_parse_with_null_value_pattern
621
- parser = TextParser::TSVParser.new
622
- parser.configure(
623
- 'keys'=>param,
624
- 'time_key'=>'time',
625
- 'null_value_pattern'=>'^(-|null|NULL)$'
626
- )
627
- parser.parse("-\tnull\tNULL\t\t--\tnuLL") do |time, record|
628
- assert_nil record['a']
629
- assert_nil record['b']
630
- assert_nil record['c']
631
- assert_equal record['d'], ''
632
- assert_equal record['e'], '--'
633
- assert_equal record['f'], 'nuLL'
634
- end
635
- end
636
-
637
- data('array param' => '["a","b"]', 'string param' => 'a,b')
638
- def test_parse_with_null_empty_string
639
- parser = TextParser::TSVParser.new
640
- parser.configure(
641
- 'keys'=>param,
642
- 'time_key'=>'time',
643
- 'null_empty_string'=>true
644
- )
645
- parser.parse("\t ") do |time, record|
646
- assert_nil record['a']
647
- assert_equal record['b'], ' '
648
- end
649
- end
650
- end
651
-
652
- class CSVParserTest < ::Test::Unit::TestCase
653
- include ParserTest
654
-
655
- data('array param' => '["time","c","d"]', 'string param' => 'time,c,d')
656
- def test_parse(param)
657
- parser = TextParser::CSVParser.new
658
- parser.configure('keys' => param, 'time_key' => 'time')
659
- parser.parse("2013/02/28 12:00:00,192.168.0.1,111") { |time, record|
660
- assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
661
- assert_equal({
662
- 'c' => '192.168.0.1',
663
- 'd' => '111',
664
- }, record)
665
- }
666
- end
667
-
668
- data('array param' => '["c","d"]', 'string param' => 'c,d')
669
- def test_parse_without_time(param)
670
- time_at_start = Time.now.to_i
671
-
672
- parser = TextParser::CSVParser.new
673
- parser.configure('keys' => param)
674
- parser.parse("192.168.0.1,111") { |time, record|
675
- assert time && time >= time_at_start, "parser puts current time without time input"
676
- assert_equal({
677
- 'c' => '192.168.0.1',
678
- 'd' => '111',
679
- }, record)
680
- }
681
-
682
- parser = TextParser::CSVParser.new
683
- parser.estimate_current_event = false
684
- parser.configure('keys' => param, 'time_key' => 'time')
685
- parser.parse("192.168.0.1,111") { |time, record|
686
- assert_equal({
687
- 'c' => '192.168.0.1',
688
- 'd' => '111',
689
- }, record)
690
- assert_nil time, "parser returns nil w/o time and if configured so"
691
- }
692
- end
693
-
694
- def test_parse_with_keep_time_key
695
- parser = TextParser::CSVParser.new
696
- parser.configure(
697
- 'keys'=>'time',
698
- 'time_key'=>'time',
699
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
700
- 'keep_time_key'=>'true',
701
- )
702
- text = '28/Feb/2013:12:00:00 +0900'
703
- parser.parse(text) do |time, record|
704
- assert_equal text, record['time']
705
- end
706
- end
707
-
708
- data('array param' => '["a","b","c","d","e","f"]', 'string param' => 'a,b,c,d,e,f')
709
- def test_parse_with_null_value_pattern
710
- parser = TextParser::CSVParser.new
711
- parser.configure(
712
- 'keys'=>param,
713
- 'time_key'=>'time',
714
- 'null_value_pattern'=>'^(-|null|NULL)$'
715
- )
716
- parser.parse("-,null,NULL,,--,nuLL") do |time, record|
717
- assert_nil record['a']
718
- assert_nil record['b']
719
- assert_nil record['c']
720
- assert_equal record['d'], ''
721
- assert_equal record['e'], '--'
722
- assert_equal record['f'], 'nuLL'
723
- end
724
- end
725
-
726
- data('array param' => '["a","b"]', 'string param' => 'a,b')
727
- def test_parse_with_null_empty_string
728
- parser = TextParser::CSVParser.new
729
- parser.configure(
730
- 'keys'=>param,
731
- 'time_key'=>'time',
732
- 'null_empty_string'=>true
733
- )
734
- parser.parse(", ") do |time, record|
735
- assert_nil record['a']
736
- assert_equal record['b'], ' '
737
- end
738
- end
739
- end
740
-
741
- class LabeledTSVParserTest < ::Test::Unit::TestCase
742
- include ParserTest
743
-
744
- def test_config_params
745
- parser = TextParser::LabeledTSVParser.new
746
-
747
- assert_equal "\t", parser.delimiter
748
- assert_equal ":", parser.label_delimiter
749
-
750
- parser.configure(
751
- 'delimiter' => ',',
752
- 'label_delimiter' => '=',
753
- )
754
-
755
- assert_equal ",", parser.delimiter
756
- assert_equal "=", parser.label_delimiter
757
- end
758
-
759
- def test_parse
760
- parser = TextParser::LabeledTSVParser.new
761
- parser.configure({})
762
- parser.parse("time:2013/02/28 12:00:00\thost:192.168.0.1\treq_id:111") { |time, record|
763
- assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
764
- assert_equal({
765
- 'host' => '192.168.0.1',
766
- 'req_id' => '111',
767
- }, record)
768
- }
769
- end
770
-
771
- def test_parse_with_customized_delimiter
772
- parser = TextParser::LabeledTSVParser.new
773
- parser.configure(
774
- 'delimiter' => ',',
775
- 'label_delimiter' => '=',
776
- )
777
- parser.parse('time=2013/02/28 12:00:00,host=192.168.0.1,req_id=111') { |time, record|
778
- assert_equal(str2time('2013/02/28 12:00:00', '%Y/%m/%d %H:%M:%S'), time)
779
- assert_equal({
780
- 'host' => '192.168.0.1',
781
- 'req_id' => '111',
782
- }, record)
783
- }
784
- end
785
-
786
- def test_parse_with_customized_time_format
787
- parser = TextParser::LabeledTSVParser.new
788
- parser.configure(
789
- 'time_key' => 'mytime',
790
- 'time_format' => '%d/%b/%Y:%H:%M:%S %z',
791
- )
792
- parser.parse("mytime:28/Feb/2013:12:00:00 +0900\thost:192.168.0.1\treq_id:111") { |time, record|
793
- assert_equal(str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z'), time)
794
- assert_equal({
795
- 'host' => '192.168.0.1',
796
- 'req_id' => '111',
797
- }, record)
798
- }
799
- end
800
-
801
- def test_parse_without_time
802
- time_at_start = Time.now.to_i
803
-
804
- parser = TextParser::LabeledTSVParser.new
805
- parser.configure({})
806
- parser.parse("host:192.168.0.1\treq_id:111") { |time, record|
807
- assert time && time >= time_at_start, "parser puts current time without time input"
808
- assert_equal({
809
- 'host' => '192.168.0.1',
810
- 'req_id' => '111',
811
- }, record)
812
- }
813
-
814
- parser = TextParser::LabeledTSVParser.new
815
- parser.estimate_current_event = false
816
- parser.configure({})
817
- parser.parse("host:192.168.0.1\treq_id:111") { |time, record|
818
- assert_equal({
819
- 'host' => '192.168.0.1',
820
- 'req_id' => '111',
821
- }, record)
822
- assert_nil time, "parser returns nil w/o time and if configured so"
823
- }
824
- end
825
-
826
- def test_parse_with_keep_time_key
827
- parser = TextParser::LabeledTSVParser.new
828
- parser.configure(
829
- 'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
830
- 'keep_time_key'=>'true',
831
- )
832
- text = '28/Feb/2013:12:00:00 +0900'
833
- parser.parse("time:#{text}") do |time, record|
834
- assert_equal text, record['time']
835
- end
836
- end
837
-
838
- def test_parse_with_null_value_pattern
839
- parser = TextParser::LabeledTSVParser.new
840
- parser.configure(
841
- 'null_value_pattern'=>'^(-|null|NULL)$'
842
- )
843
- parser.parse("a:-\tb:null\tc:NULL\td:\te:--\tf:nuLL") do |time, record|
844
- assert_nil record['a']
845
- assert_nil record['b']
846
- assert_nil record['c']
847
- assert_equal record['d'], ''
848
- assert_equal record['e'], '--'
849
- assert_equal record['f'], 'nuLL'
850
- end
851
- end
852
-
853
- def test_parse_with_null_empty_string
854
- parser = TextParser::LabeledTSVParser.new
855
- parser.configure(
856
- 'null_empty_string'=>true
857
- )
858
- parser.parse("a:\tb: ") do |time, record|
859
- assert_nil record['a']
860
- assert_equal record['b'], ' '
861
- end
862
- end
863
- end
864
-
865
- class NoneParserTest < ::Test::Unit::TestCase
866
- include ParserTest
867
-
868
- def test_config_params
869
- parser = TextParser::NoneParser.new
870
- parser.configure({})
871
- assert_equal "message", parser.message_key
872
-
873
- parser.configure('message_key' => 'foobar')
874
- assert_equal "foobar", parser.message_key
875
- end
876
-
877
- def test_parse
878
- parser = Fluent::Plugin.new_parser('none')
879
- parser.configure({})
880
- parser.parse('log message!') { |time, record|
881
- assert_equal({'message' => 'log message!'}, record)
882
- }
883
- end
884
-
885
- def test_parse_with_message_key
886
- parser = TextParser::NoneParser.new
887
- parser.configure('message_key' => 'foobar')
888
- parser.parse('log message!') { |time, record|
889
- assert_equal({'foobar' => 'log message!'}, record)
890
- }
891
- end
892
-
893
- def test_parse_without_default_time
894
- time_at_start = Time.now.to_i
895
-
896
- parser = Fluent::Plugin.new_parser('none')
897
- parser.configure({})
898
- parser.parse('log message!') { |time, record|
899
- assert time && time >= time_at_start, "parser puts current time without time input"
900
- assert_equal({'message' => 'log message!'}, record)
901
- }
902
-
903
- parser = Fluent::Plugin.new_parser('none')
904
- parser.estimate_current_event = false
905
- parser.configure({})
906
- parser.parse('log message!') { |time, record|
907
- assert_equal({'message' => 'log message!'}, record)
908
- assert_nil time, "parser returns nil w/o time if configured so"
909
- }
910
- end
911
- end
912
-
913
- class MultilineParserTest < ::Test::Unit::TestCase
914
- include ParserTest
915
-
916
- def create_parser(conf)
917
- parser = Fluent::Plugin.new_parser('multiline')
918
- parser.configure(conf)
919
- parser
920
- end
921
-
922
- def test_configure_with_invalid_params
923
- [{'format100' => '/(?<msg>.*)/'}, {'format1' => '/(?<msg>.*)/', 'format3' => '/(?<msg>.*)/'}, 'format1' => '/(?<msg>.*)'].each { |config|
924
- assert_raise(ConfigError) {
925
- create_parser(config)
926
- }
927
- }
928
- end
929
-
930
- def test_parse
931
- 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>.*)/')
932
- parser.parse(<<EOS.chomp) { |time, record|
933
- 2013-3-03 14:27:33 [main] ERROR Main - Exception
934
- javax.management.RuntimeErrorException: null
935
- \tat Main.main(Main.java:16) ~[bin/:na]
936
- EOS
937
-
938
- assert_equal(str2time('2013-3-03 14:27:33').to_i, time)
939
- assert_equal({
940
- "thread" => "main",
941
- "level" => "ERROR",
942
- "message" => " Main - Exception\njavax.management.RuntimeErrorException: null\n\tat Main.main(Main.java:16) ~[bin/:na]"
943
- }, record)
944
- }
945
- end
946
-
947
- def test_parse_with_firstline
948
- 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>.*)/')
949
- parser.parse(<<EOS.chomp) { |time, record|
950
- ----
951
- time=2013-3-03 14:27:33
952
- message=test1
953
- EOS
954
-
955
- assert(parser.firstline?('----'))
956
- assert_equal(str2time('2013-3-03 14:27:33').to_i, time)
957
- assert_equal({"message" => "test1"}, record)
958
- }
959
- end
960
-
961
- def test_parse_with_multiple_formats
962
- parser = create_parser('format_firstline' => '/^Started/',
963
- 'format1' => '/Started (?<method>[^ ]+) "(?<path>[^"]+)" for (?<host>[^ ]+) at (?<time>[^ ]+ [^ ]+ [^ ]+)\n/',
964
- 'format2' => '/Processing by (?<controller>[^\u0023]+)\u0023(?<controller_method>[^ ]+) as (?<format>[^ ]+?)\n/',
965
- 'format3' => '/( Parameters: (?<parameters>[^ ]+)\n)?/',
966
- 'format4' => '/ Rendered (?<template>[^ ]+) within (?<layout>.+) \([\d\.]+ms\)\n/',
967
- 'format5' => '/Completed (?<code>[^ ]+) [^ ]+ in (?<runtime>[\d\.]+)ms \(Views: (?<view_runtime>[\d\.]+)ms \| ActiveRecord: (?<ar_runtime>[\d\.]+)ms\)/'
968
- )
969
- parser.parse(<<EOS.chomp) { |time, record|
970
- Started GET "/users/123/" for 127.0.0.1 at 2013-06-14 12:00:11 +0900
971
- Processing by UsersController#show as HTML
972
- Parameters: {"user_id"=>"123"}
973
- Rendered users/show.html.erb within layouts/application (0.3ms)
974
- Completed 200 OK in 4ms (Views: 3.2ms | ActiveRecord: 0.0ms)
975
- EOS
976
-
977
- assert(parser.firstline?('Started GET "/users/123/" for 127.0.0.1...'))
978
- assert_equal(str2time('2013-06-14 12:00:11 +0900').to_i, time)
979
- assert_equal({
980
- "method" => "GET",
981
- "path" => "/users/123/",
982
- "host" => "127.0.0.1",
983
- "controller" => "UsersController",
984
- "controller_method" => "show",
985
- "format" => "HTML",
986
- "parameters" => "{\"user_id\"=>\"123\"}",
987
- "template" => "users/show.html.erb",
988
- "layout" => "layouts/application",
989
- "code" => "200",
990
- "runtime" => "4",
991
- "view_runtime" => "3.2",
992
- "ar_runtime" => "0.0"
993
- }, record)
994
- }
995
- end
996
-
997
- def test_parse_with_keep_time_key
998
- parser = TextParser::MultilineParser.new
999
- parser.configure(
1000
- 'format1' => '/^(?<time>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})/',
1001
- 'keep_time_key' => 'true'
1002
- )
1003
- text = '2013-3-03 14:27:33'
1004
- parser.parse(text) { |time, record|
1005
- assert_equal text, record['time']
1006
- }
1007
- end
1008
- end
1009
-
1010
- class TextParserTest < ::Test::Unit::TestCase
1011
- include ParserTest
1012
-
1013
- class MultiEventTestParser < ::Fluent::Parser
1014
- include Fluent::Configurable
1015
-
1016
- def parse(text)
1017
- 2.times { |i|
1018
- record = {}
1019
- record['message'] = text
1020
- record['number'] = i
1021
- yield Fluent::Engine.now, record
1022
- }
1023
- end
1024
- end
1025
-
1026
- TextParser.register_template('multi_event_test', Proc.new { MultiEventTestParser.new })
1027
-
1028
- def test_lookup_unknown_format
1029
- assert_raise ConfigError do
1030
- Fluent::Plugin.new_parser('unknown')
1031
- end
1032
- end
1033
-
1034
- data('register_formatter' => 'known', 'register_template' => 'known_old')
1035
- def test_lookup_known_parser(data)
1036
- $LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), 'scripts'))
1037
- assert_nothing_raised ConfigError do
1038
- Fluent::Plugin.new_parser(data)
1039
- end
1040
- $LOAD_PATH.shift
1041
- end
1042
-
1043
- def test_parse_with_return
1044
- parser = TextParser.new
1045
- parser.configure('format' => 'none')
1046
- _time, record = parser.parse('log message!')
1047
- assert_equal({'message' => 'log message!'}, record)
1048
- end
1049
-
1050
- def test_parse_with_block
1051
- parser = TextParser.new
1052
- parser.configure('format' => 'none')
1053
- parser.parse('log message!') { |time, record|
1054
- assert_equal({'message' => 'log message!'}, record)
1055
- }
1056
- end
1057
-
1058
- def test_multi_event_parser
1059
- parser = TextParser.new
1060
- parser.configure('format' => 'multi_event_test')
1061
- i = 0
1062
- parser.parse('log message!') { |time, record|
1063
- assert_equal('log message!', record['message'])
1064
- assert_equal(i, record['number'])
1065
- i += 1
1066
- }
1067
- end
1068
-
1069
- def test_setting_estimate_current_event_value
1070
- p1 = TextParser.new
1071
- assert_nil p1.estimate_current_event
1072
- assert_nil p1.parser
1073
-
1074
- p1.configure('format' => 'none')
1075
- assert_equal true, p1.parser.estimate_current_event
1076
-
1077
- p2 = TextParser.new
1078
- assert_nil p2.estimate_current_event
1079
- assert_nil p2.parser
1080
-
1081
- p2.estimate_current_event = false
1082
-
1083
- p2.configure('format' => 'none')
1084
- assert_equal false, p2.parser.estimate_current_event
1085
- end
1086
- end
1087
- end