fluentd 0.10.50 → 0.10.51

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.

@@ -22,6 +22,14 @@ class FileOutputTest < Test::Unit::TestCase
22
22
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::FileOutput).configure(conf)
23
23
  end
24
24
 
25
+ def with_timezone(timezone = 'UTC', &block)
26
+ old = ENV['TZ']
27
+ ENV['TZ'] = timezone
28
+ output = yield
29
+ ENV['TZ'] = old
30
+ output
31
+ end
32
+
25
33
  def test_configure
26
34
  d = create_driver %[
27
35
  path test_path
@@ -31,6 +39,17 @@ class FileOutputTest < Test::Unit::TestCase
31
39
  assert_equal :gz, d.instance.compress
32
40
  end
33
41
 
42
+ def test_default_localtime
43
+ d = create_driver(%[path #{TMP_DIR}/out_file_test])
44
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
45
+
46
+ with_timezone('Asia/Taipei') do
47
+ d.emit({"a"=>1}, time)
48
+ d.expect_format %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n]
49
+ d.run
50
+ end
51
+ end
52
+
34
53
  def test_format
35
54
  d = create_driver
36
55
 
@@ -10,6 +10,13 @@ class ConfigTest < Test::Unit::TestCase
10
10
 
11
11
  TMP_DIR = File.dirname(__FILE__) + "/tmp/config#{ENV['TEST_ENV_NUMBER']}"
12
12
 
13
+ def read_config(path)
14
+ path = File.expand_path(path)
15
+ File.open(path) { |io|
16
+ Fluent::Config::Parser.parse(io, File.basename(path), File.dirname(path))
17
+ }
18
+ end
19
+
13
20
  def prepare_config
14
21
  write_config "#{TMP_DIR}/config_test_1.conf", %[
15
22
  k1 root_config
@@ -63,7 +70,7 @@ class ConfigTest < Test::Unit::TestCase
63
70
 
64
71
  def test_include
65
72
  prepare_config
66
- c = Config.read("#{TMP_DIR}/config_test_1.conf")
73
+ c = read_config("#{TMP_DIR}/config_test_1.conf")
67
74
  assert_equal 'root_config', c['k1']
68
75
  assert_equal 'relative_path_include', c['k2']
69
76
  assert_equal 'relative_include_in_included_file', c['k3']
@@ -112,7 +119,7 @@ class ConfigTest < Test::Unit::TestCase
112
119
  </rule>
113
120
  </match>
114
121
  ]
115
- root_conf = Config.read("#{TMP_DIR}/config_test_not_fetched.conf")
122
+ root_conf = read_config("#{TMP_DIR}/config_test_not_fetched.conf")
116
123
  match_conf = root_conf.elements.first
117
124
  rule_conf = match_conf.elements.first
118
125
 
@@ -37,29 +37,33 @@ module FormatterTest
37
37
  @time = Engine.now
38
38
  end
39
39
 
40
+ def configure(conf)
41
+ @formatter.configure({'utc' => true}.merge(conf))
42
+ end
43
+
40
44
  def test_format
41
- @formatter.configure({})
45
+ configure({})
42
46
  formatted = @formatter.format(tag, @time, record)
43
47
 
44
48
  assert_equal("#{time2str(@time)}\t#{tag}\t#{Yajl.dump(record)}\n", formatted)
45
49
  end
46
50
 
47
51
  def test_format_without_time
48
- @formatter.configure('output_time' => 'false')
52
+ configure('output_time' => 'false')
49
53
  formatted = @formatter.format(tag, @time, record)
50
54
 
51
55
  assert_equal("#{tag}\t#{Yajl.dump(record)}\n", formatted)
52
56
  end
53
57
 
54
58
  def test_format_without_tag
55
- @formatter.configure('output_tag' => 'false')
59
+ configure('output_tag' => 'false')
56
60
  formatted = @formatter.format(tag, @time, record)
57
61
 
58
62
  assert_equal("#{time2str(@time)}\t#{Yajl.dump(record)}\n", formatted)
59
63
  end
60
64
 
61
65
  def test_format_without_time_and_tag
62
- @formatter.configure('output_tag' => 'false', 'output_time' => 'false')
66
+ configure('output_tag' => 'false', 'output_time' => 'false')
63
67
  formatted = @formatter.format('tag', @time, record)
64
68
 
65
69
  assert_equal("#{Yajl.dump(record)}\n", formatted)
@@ -67,14 +67,45 @@ module ParserTest
67
67
 
68
68
  def test_call_with_configure
69
69
  # Specify conf by configure method instaed of intializer
70
- parser = TextParser::RegexpParser.new(Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!))
70
+ regexp = Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!)
71
+ parser = TextParser::RegexpParser.new(regexp)
71
72
  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')
72
73
  internal_test_case(parser)
74
+ assert_equal(regexp, parser.patterns['format'])
75
+ assert_equal("%d/%b/%Y:%H:%M:%S %z", parser.patterns['time_format'])
73
76
  end
74
77
 
75
78
  def test_call_with_typed_and_name_separator
76
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'=>'|'))
77
80
  end
81
+
82
+ def test_call_without_time
83
+ time_at_start = Time.now.to_i
84
+ text = "tagomori_satoshi tagomoris 34\n"
85
+
86
+ parser = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
87
+ parser.configure('types'=>'name:string,user:string,age:bool')
88
+
89
+ [parser.call(text), parser.call(text) { |time, record| return time, record}].each { |time, record|
90
+ assert time && time >= time_at_start, "parser puts current time without time input"
91
+ assert_equal "tagomori_satoshi", record["name"]
92
+ assert_equal "tagomoris", record["user"]
93
+ assert_equal 34, record["age"]
94
+ }
95
+
96
+ parser2 = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
97
+ parser2.configure('types'=>'name:string,user:string,age:bool')
98
+ parser2.time_default_current = false
99
+
100
+ [parser2.call(text), parser2.call(text) { |time, record| return time, record}].each { |time, record|
101
+ assert_equal "tagomori_satoshi", record["name"]
102
+ assert_equal "tagomoris", record["user"]
103
+ assert_equal 34, record["age"]
104
+
105
+ assert_nil time, "parser returns nil if configured so"
106
+ }
107
+
108
+ end
78
109
  end
79
110
 
80
111
  class ApacheParserTest < ::Test::Unit::TestCase
@@ -120,6 +151,8 @@ module ParserTest
120
151
  'agent' => 'Opera/12.0'
121
152
  }, record)
122
153
  }
154
+ assert_equal(TextParser::ApacheParser::REGEXP, @parser.patterns['format'])
155
+ assert_equal(TextParser::ApacheParser::TIME_FORMAT, @parser.patterns['time_format'])
123
156
  end
124
157
  end
125
158
 
@@ -131,6 +164,7 @@ module ParserTest
131
164
  end
132
165
 
133
166
  def test_call
167
+ @parser.configure({})
134
168
  @parser.call('Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
135
169
  assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
136
170
  assert_equal({
@@ -140,6 +174,24 @@ module ParserTest
140
174
  'message' => '[error] Syslog test'
141
175
  }, record)
142
176
  }
177
+ assert_equal(TextParser::SyslogParser::REGEXP, @parser.patterns['format'])
178
+ assert_equal(TextParser::SyslogParser::TIME_FORMAT, @parser.patterns['time_format'])
179
+ end
180
+
181
+ def test_call_with_priority
182
+ @parser.configure('with_priority' => true)
183
+ @parser.call('<6>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test') { |time, record|
184
+ assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
185
+ assert_equal({
186
+ 'pri' => 6,
187
+ 'host' => '192.168.0.1',
188
+ 'ident' => 'fluentd',
189
+ 'pid' => '11111',
190
+ 'message' => '[error] Syslog test'
191
+ }, record)
192
+ }
193
+ assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, @parser.patterns['format'])
194
+ assert_equal(TextParser::SyslogParser::TIME_FORMAT, @parser.patterns['time_format'])
143
195
  end
144
196
  end
145
197
 
@@ -160,6 +212,31 @@ module ParserTest
160
212
  }, record)
161
213
  }
162
214
  end
215
+
216
+ def test_call_without_time
217
+ time_at_start = Time.now.to_i
218
+
219
+ @parser.call('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
220
+ assert time && time >= time_at_start, "parser puts current time without time input"
221
+ assert_equal({
222
+ 'host' => '192.168.0.1',
223
+ 'size' => 777,
224
+ 'method' => 'PUT',
225
+ }, record)
226
+ }
227
+
228
+ parser = TextParser::JSONParser.new
229
+ parser.estimate_current_event = false
230
+ parser.configure({})
231
+ parser.call('{"host":"192.168.0.1","size":777,"method":"PUT"}') { |time, record|
232
+ assert_equal({
233
+ 'host' => '192.168.0.1',
234
+ 'size' => 777,
235
+ 'method' => 'PUT',
236
+ }, record)
237
+ assert_nil time, "parser return nil w/o time and if specified so"
238
+ }
239
+ end
163
240
  end
164
241
 
165
242
  class NginxParserTest < ::Test::Unit::TestCase
@@ -222,6 +299,31 @@ module ParserTest
222
299
  }, record)
223
300
  }
224
301
  end
302
+
303
+ def test_call_with_time
304
+ time_at_start = Time.now.to_i
305
+
306
+ parser = TextParser::TSVParser.new
307
+ parser.configure('keys' => 'a,b')
308
+ parser.call("192.168.0.1\t111") { |time, record|
309
+ assert time && time >= time_at_start, "parser puts current time without time input"
310
+ assert_equal({
311
+ 'a' => '192.168.0.1',
312
+ 'b' => '111',
313
+ }, record)
314
+ }
315
+
316
+ parser = TextParser::TSVParser.new
317
+ parser.estimate_current_event = false
318
+ parser.configure('keys' => 'a,b', 'time_key' => 'time')
319
+ parser.call("192.168.0.1\t111") { |time, record|
320
+ assert_equal({
321
+ 'a' => '192.168.0.1',
322
+ 'b' => '111',
323
+ }, record)
324
+ assert_nil time, "parser returns nil w/o time and if configured so"
325
+ }
326
+ end
225
327
  end
226
328
 
227
329
  class CSVParserTest < ::Test::Unit::TestCase
@@ -238,6 +340,31 @@ module ParserTest
238
340
  }, record)
239
341
  }
240
342
  end
343
+
344
+ def test_call_without_time
345
+ time_at_start = Time.now.to_i
346
+
347
+ parser = TextParser::CSVParser.new
348
+ parser.configure('keys' => 'c,d')
349
+ parser.call("192.168.0.1,111") { |time, record|
350
+ assert time && time >= time_at_start, "parser puts current time without time input"
351
+ assert_equal({
352
+ 'c' => '192.168.0.1',
353
+ 'd' => '111',
354
+ }, record)
355
+ }
356
+
357
+ parser = TextParser::CSVParser.new
358
+ parser.estimate_current_event = false
359
+ parser.configure('keys' => 'c,d', 'time_key' => 'time')
360
+ parser.call("192.168.0.1,111") { |time, record|
361
+ assert_equal({
362
+ 'c' => '192.168.0.1',
363
+ 'd' => '111',
364
+ }, record)
365
+ assert_nil time, "parser returns nil w/o time and if configured so"
366
+ }
367
+ end
241
368
  end
242
369
 
243
370
  class LabeledTSVParserTest < ::Test::Unit::TestCase
@@ -299,13 +426,39 @@ module ParserTest
299
426
  }, record)
300
427
  }
301
428
  end
302
- end
429
+
430
+ def test_call_without_time
431
+ time_at_start = Time.now.to_i
432
+
433
+ parser = TextParser::LabeledTSVParser.new
434
+ parser.configure({})
435
+ parser.call("host:192.168.0.1\treq_id:111") { |time, record|
436
+ assert time && time >= time_at_start, "parser puts current time without time input"
437
+ assert_equal({
438
+ 'host' => '192.168.0.1',
439
+ 'req_id' => '111',
440
+ }, record)
441
+ }
442
+
443
+ parser = TextParser::LabeledTSVParser.new
444
+ parser.estimate_current_event = false
445
+ parser.configure({})
446
+ parser.call("host:192.168.0.1\treq_id:111") { |time, record|
447
+ assert_equal({
448
+ 'host' => '192.168.0.1',
449
+ 'req_id' => '111',
450
+ }, record)
451
+ assert_nil time, "parser returns nil w/o time and if configured so"
452
+ }
453
+ end
454
+ end
303
455
 
304
456
  class NoneParserTest < ::Test::Unit::TestCase
305
457
  include ParserTest
306
458
 
307
459
  def test_config_params
308
460
  parser = TextParser::NoneParser.new
461
+ parser.configure({})
309
462
  assert_equal "message", parser.message_key
310
463
 
311
464
  parser.configure('message_key' => 'foobar')
@@ -314,6 +467,7 @@ module ParserTest
314
467
 
315
468
  def test_call
316
469
  parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
470
+ parser.configure({})
317
471
  parser.call('log message!') { |time, record|
318
472
  assert_equal({'message' => 'log message!'}, record)
319
473
  }
@@ -326,6 +480,25 @@ module ParserTest
326
480
  assert_equal({'foobar' => 'log message!'}, record)
327
481
  }
328
482
  end
483
+
484
+ def test_call_without_default_time
485
+ time_at_start = Time.now.to_i
486
+
487
+ parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
488
+ parser.configure({})
489
+ parser.call('log message!') { |time, record|
490
+ assert time && time >= time_at_start, "parser puts current time without time input"
491
+ assert_equal({'message' => 'log message!'}, record)
492
+ }
493
+
494
+ parser = TextParser::TEMPLATE_REGISTRY.lookup('none').call
495
+ parser.estimate_current_event = false
496
+ parser.configure({})
497
+ parser.call('log message!') { |time, record|
498
+ assert_equal({'message' => 'log message!'}, record)
499
+ assert_nil time, "parser returns nil w/o time if configured so"
500
+ }
501
+ end
329
502
  end
330
503
 
331
504
  class MultilineParserTest < ::Test::Unit::TestCase
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluentd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.50
4
+ version: 0.10.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -255,6 +255,7 @@ files:
255
255
  - ".gitignore"
256
256
  - ".travis.yml"
257
257
  - AUTHORS
258
+ - CONTRIBUTING.md
258
259
  - COPYING
259
260
  - ChangeLog
260
261
  - Gemfile
@@ -311,6 +312,8 @@ files:
311
312
  - lib/fluent/plugin/in_stream.rb
312
313
  - lib/fluent/plugin/in_syslog.rb
313
314
  - lib/fluent/plugin/in_tail.rb
315
+ - lib/fluent/plugin/in_tcp.rb
316
+ - lib/fluent/plugin/in_udp.rb
314
317
  - lib/fluent/plugin/out_copy.rb
315
318
  - lib/fluent/plugin/out_exec.rb
316
319
  - lib/fluent/plugin/out_exec_filter.rb
@@ -355,6 +358,8 @@ files:
355
358
  - test/plugin/test_in_stream.rb
356
359
  - test/plugin/test_in_syslog.rb
357
360
  - test/plugin/test_in_tail.rb
361
+ - test/plugin/test_in_tcp.rb
362
+ - test/plugin/test_in_udp.rb
358
363
  - test/plugin/test_out_copy.rb
359
364
  - test/plugin/test_out_exec.rb
360
365
  - test/plugin/test_out_exec_filter.rb
@@ -421,6 +426,8 @@ test_files:
421
426
  - test/plugin/test_in_stream.rb
422
427
  - test/plugin/test_in_syslog.rb
423
428
  - test/plugin/test_in_tail.rb
429
+ - test/plugin/test_in_tcp.rb
430
+ - test/plugin/test_in_udp.rb
424
431
  - test/plugin/test_out_copy.rb
425
432
  - test/plugin/test_out_exec.rb
426
433
  - test/plugin/test_out_exec_filter.rb