fluentd 0.12.17 → 0.12.18

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/ChangeLog +25 -0
  4. data/lib/fluent/buffer.rb +2 -0
  5. data/lib/fluent/config/configure_proxy.rb +2 -2
  6. data/lib/fluent/configurable.rb +2 -2
  7. data/lib/fluent/log.rb +1 -0
  8. data/lib/fluent/plugin/buf_file.rb +2 -0
  9. data/lib/fluent/plugin/buf_memory.rb +1 -0
  10. data/lib/fluent/plugin/exec_util.rb +21 -0
  11. data/lib/fluent/plugin/filter_record_transformer.rb +6 -0
  12. data/lib/fluent/plugin/filter_stdout.rb +1 -0
  13. data/lib/fluent/plugin/in_exec.rb +33 -22
  14. data/lib/fluent/plugin/in_forward.rb +5 -0
  15. data/lib/fluent/plugin/in_http.rb +9 -0
  16. data/lib/fluent/plugin/in_stream.rb +2 -0
  17. data/lib/fluent/plugin/in_syslog.rb +6 -0
  18. data/lib/fluent/plugin/in_tail.rb +16 -1
  19. data/lib/fluent/plugin/in_tcp.rb +1 -0
  20. data/lib/fluent/plugin/out_copy.rb +1 -0
  21. data/lib/fluent/plugin/out_exec.rb +6 -0
  22. data/lib/fluent/plugin/out_exec_filter.rb +15 -0
  23. data/lib/fluent/plugin/out_file.rb +5 -0
  24. data/lib/fluent/plugin/out_forward.rb +15 -0
  25. data/lib/fluent/plugin/out_stdout.rb +1 -0
  26. data/lib/fluent/plugin/socket_util.rb +5 -0
  27. data/lib/fluent/process.rb +19 -9
  28. data/lib/fluent/supervisor.rb +19 -1
  29. data/lib/fluent/test.rb +2 -0
  30. data/lib/fluent/test/formatter_test.rb +60 -0
  31. data/lib/fluent/test/parser_test.rb +66 -0
  32. data/lib/fluent/version.rb +1 -1
  33. data/test/config/test_configure_proxy.rb +1 -10
  34. data/test/plugin/test_in_exec.rb +31 -3
  35. data/test/plugin/test_out_forward.rb +6 -0
  36. data/test/scripts/exec_script.rb +6 -0
  37. data/test/test_formatter.rb +35 -2
  38. data/test/test_parser.rb +43 -19
  39. data/test/test_process.rb +47 -0
  40. metadata +7 -3
@@ -44,9 +44,18 @@ class ExecInputTest < Test::Unit::TestCase
44
44
  ]
45
45
  end
46
46
 
47
+ def regexp_config
48
+ %[
49
+ command ruby #{@script} "2011-01-02 13:14:15" 3
50
+ format /(?<time>[^\\\]]*) (?<message>[^ ]*)/
51
+ tag regex_tag
52
+ run_interval 1s
53
+ ]
54
+ end
55
+
47
56
  def test_configure
48
57
  d = create_driver
49
- assert_equal :tsv, d.instance.format
58
+ assert_equal 'tsv', d.instance.format
50
59
  assert_equal ["time","tag","k1"], d.instance.keys
51
60
  assert_equal "tag", d.instance.tag_key
52
61
  assert_equal "time", d.instance.time_key
@@ -55,16 +64,22 @@ class ExecInputTest < Test::Unit::TestCase
55
64
 
56
65
  def test_configure_with_json
57
66
  d = create_driver json_config
58
- assert_equal :json, d.instance.format
67
+ assert_equal 'json', d.instance.format
59
68
  assert_equal [], d.instance.keys
60
69
  end
61
70
 
62
71
  def test_configure_with_msgpack
63
72
  d = create_driver msgpack_config
64
- assert_equal :msgpack, d.instance.format
73
+ assert_equal 'msgpack', d.instance.format
65
74
  assert_equal [], d.instance.keys
66
75
  end
67
76
 
77
+ def test_configure_with_regexp
78
+ d = create_driver regexp_config
79
+ assert_equal '/(?<time>[^\]]*) (?<message>[^ ]*)/', d.instance.format
80
+ assert_equal 'regex_tag', d.instance.tag
81
+ end
82
+
68
83
  # TODO: Merge following tests into one case with parameters
69
84
 
70
85
  def test_emit
@@ -102,4 +117,17 @@ class ExecInputTest < Test::Unit::TestCase
102
117
  assert_equal true, emits.length > 0
103
118
  assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0]
104
119
  end
120
+
121
+ def test_emit_regexp
122
+ d = create_driver regexp_config
123
+
124
+ d.run do
125
+ sleep 2
126
+ end
127
+
128
+ emits = d.emits
129
+ assert_equal true, emits.length > 0
130
+ assert_equal ["regex_tag", @test_time, {"message"=>"hello"}], emits[0]
131
+ assert_equal @test_time, emits[0][1]
132
+ end
105
133
  end
@@ -78,6 +78,12 @@ class ForwardOutputTest < Test::Unit::TestCase
78
78
  assert_equal true, d.instance.nodes.first.conf.dns_round_robin
79
79
  end
80
80
 
81
+ def test_configure_no_server
82
+ assert_raise(Fluent::ConfigError, 'forward output plugin requires at least one <server> is required') do
83
+ create_driver('')
84
+ end
85
+ end
86
+
81
87
  def test_phi_failure_detector
82
88
  d = create_driver(CONFIG + %[phi_failure_detector false \n phi_threshold 0])
83
89
  node = d.instance.nodes.first
@@ -13,6 +13,10 @@ def gen_msgpack(time)
13
13
  {'tagger' => 'tag1', 'datetime' => time, 'k1' => 'ok'}.to_msgpack
14
14
  end
15
15
 
16
+ def gen_raw_string(time)
17
+ "#{time} hello"
18
+ end
19
+
16
20
  time = ARGV.first
17
21
  time = Integer(time) rescue time
18
22
 
@@ -23,4 +27,6 @@ when 1
23
27
  puts gen_json(time)
24
28
  when 2
25
29
  print gen_msgpack(time)
30
+ when 3
31
+ print gen_raw_string(time)
26
32
  end
@@ -48,11 +48,33 @@ module FormatterTest
48
48
  end
49
49
  end
50
50
 
51
+ class BaseFormatterTestWithTestDriver < ::Test::Unit::TestCase
52
+ include FormatterTest
53
+
54
+ def create_driver(conf={})
55
+ formatter = Fluent::Test::FormatterTestDriver.new(Formatter).configure(conf)
56
+ end
57
+
58
+ def test_call
59
+ d = create_driver
60
+ assert_raise NotImplementedError do
61
+ d.format('tag', Engine.now, {})
62
+ end
63
+ end
64
+
65
+ def test_call_with_string_literal_configure
66
+ d = create_driver('')
67
+ assert_raise NotImplementedError do
68
+ d.format('tag', Engine.now, {})
69
+ end
70
+ end
71
+ end
72
+
51
73
  class OutFileFormatterTest < ::Test::Unit::TestCase
52
74
  include FormatterTest
53
75
 
54
76
  def setup
55
- @formatter = TextFormatter::TEMPLATE_REGISTRY.lookup('out_file').call
77
+ @formatter = Fluent::Test::FormatterTestDriver.new('out_file')
56
78
  @time = Engine.now
57
79
  end
58
80
 
@@ -87,13 +109,24 @@ module FormatterTest
87
109
 
88
110
  assert_equal("#{Yajl.dump(record)}\n", formatted)
89
111
  end
112
+
113
+ def test_format_without_time_and_tag_against_string_literal_configure
114
+ @formatter.configure(%[
115
+ utc true
116
+ output_tag false
117
+ output_time false
118
+ ])
119
+ formatted = @formatter.format('tag', @time, record)
120
+
121
+ assert_equal("#{Yajl.dump(record)}\n", formatted)
122
+ end
90
123
  end
91
124
 
92
125
  class JsonFormatterTest < ::Test::Unit::TestCase
93
126
  include FormatterTest
94
127
 
95
128
  def setup
96
- @formatter = TextFormatter::JSONFormatter.new
129
+ @formatter = Fluent::Test::FormatterTestDriver.new(TextFormatter::JSONFormatter)
97
130
  @time = Engine.now
98
131
  end
99
132
 
@@ -39,6 +39,31 @@ module ParserTest
39
39
  end
40
40
  end
41
41
 
42
+ class BaseParserTestWithTestDriver < ::Test::Unit::TestCase
43
+ include ParserTest
44
+
45
+ def create_driver(conf={})
46
+ Fluent::Test::ParserTestDriver.new(Fluent::Parser).configure(conf)
47
+ end
48
+
49
+ def test_init
50
+ d = create_driver
51
+ assert_true d.instance.estimate_current_event
52
+ end
53
+
54
+ def test_configure_against_string_literal
55
+ d = create_driver('keep_time_key true')
56
+ assert_true d.instance.keep_time_key
57
+ end
58
+
59
+ def test_parse
60
+ d = create_driver
61
+ assert_raise NotImplementedError do
62
+ d.parse('')
63
+ end
64
+ end
65
+ end
66
+
42
67
  class TimeParserTest < ::Test::Unit::TestCase
43
68
  include ParserTest
44
69
 
@@ -94,19 +119,19 @@ module ParserTest
94
119
  def test_parse_with_configure
95
120
  # Specify conf by configure method instaed of intializer
96
121
  regexp = Regexp.new(%q!^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$!)
97
- parser = TextParser::RegexpParser.new(regexp)
122
+ parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, regexp)
98
123
  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')
99
124
  internal_test_case(parser)
100
- assert_equal(regexp, parser.patterns['format'])
101
- assert_equal("%d/%b/%Y:%H:%M:%S %z", parser.patterns['time_format'])
125
+ assert_equal(regexp, parser.instance.patterns['format'])
126
+ assert_equal("%d/%b/%Y:%H:%M:%S %z", parser.instance.patterns['time_format'])
102
127
  end
103
128
 
104
129
  def test_parse_with_typed_and_name_separator
105
- 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'=>'|'))
130
+ 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'=>'|'))
106
131
  end
107
132
 
108
133
  def test_parse_with_time_key
109
- parser = TextParser::RegexpParser.new(/(?<logtime>[^\]]*)/)
134
+ parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, /(?<logtime>[^\]]*)/)
110
135
  parser.configure(
111
136
  'time_format'=>"%Y-%m-%d %H:%M:%S %z",
112
137
  'time_key'=>'logtime',
@@ -131,10 +156,9 @@ module ParserTest
131
156
  assert_equal 34, record["age"]
132
157
  }
133
158
 
134
- parser2 = TextParser::RegexpParser.new(Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
135
- parser2.configure('types'=>'name:string,user:string,age:bool')
136
- parser2.time_default_current = false
137
-
159
+ parser2 = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser, Regexp.new(%q!^(?<name>[^ ]*) (?<user>[^ ]*) (?<age>\d*)$!))
160
+ parser2.configure('types'=>'name:string,user:string,age:integer')
161
+ parser2.instance.estimate_current_event = false
138
162
  [parser2.parse(text), parser2.parse(text) { |time, record| return time, record}].each { |time, record|
139
163
  assert_equal "tagomori_satoshi", record["name"]
140
164
  assert_equal "tagomoris", record["user"]
@@ -145,7 +169,7 @@ module ParserTest
145
169
  end
146
170
 
147
171
  def test_parse_with_keep_time_key
148
- parser = TextParser::RegexpParser.new(
172
+ parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser,
149
173
  Regexp.new(%q!(?<time>.*)!),
150
174
  'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
151
175
  'keep_time_key'=>'true',
@@ -157,7 +181,7 @@ module ParserTest
157
181
  end
158
182
 
159
183
  def test_parse_with_keep_time_key_with_typecast
160
- parser = TextParser::RegexpParser.new(
184
+ parser = Fluent::Test::ParserTestDriver.new(TextParser::RegexpParser,
161
185
  Regexp.new(%q!(?<time>.*)!),
162
186
  'time_format'=>"%d/%b/%Y:%H:%M:%S %z",
163
187
  'keep_time_key'=>'true',
@@ -281,7 +305,7 @@ module ParserTest
281
305
  include ParserTest
282
306
 
283
307
  def setup
284
- @parser = TextParser::TEMPLATE_REGISTRY.lookup('syslog').call
308
+ @parser = Fluent::Test::ParserTestDriver.new('syslog')
285
309
  @expected = {
286
310
  'host' => '192.168.0.1',
287
311
  'ident' => 'fluentd',
@@ -296,8 +320,8 @@ module ParserTest
296
320
  assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
297
321
  assert_equal(@expected, record)
298
322
  }
299
- assert_equal(TextParser::SyslogParser::REGEXP, @parser.patterns['format'])
300
- assert_equal("%b %d %H:%M:%S", @parser.patterns['time_format'])
323
+ assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
324
+ assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
301
325
  end
302
326
 
303
327
  def test_parse_with_time_format
@@ -306,7 +330,7 @@ module ParserTest
306
330
  assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
307
331
  assert_equal(@expected, record)
308
332
  }
309
- assert_equal('%b %d %M:%S:%H', @parser.patterns['time_format'])
333
+ assert_equal('%b %d %M:%S:%H', @parser.instance.patterns['time_format'])
310
334
  end
311
335
 
312
336
  def test_parse_with_priority
@@ -315,8 +339,8 @@ module ParserTest
315
339
  assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
316
340
  assert_equal(@expected.merge('pri' => 6), record)
317
341
  }
318
- assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, @parser.patterns['format'])
319
- assert_equal("%b %d %H:%M:%S", @parser.patterns['time_format'])
342
+ assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, @parser.instance.patterns['format'])
343
+ assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
320
344
  end
321
345
 
322
346
  def test_parse_without_colon
@@ -325,8 +349,8 @@ module ParserTest
325
349
  assert_equal(str2time('Feb 28 12:00:00', '%b %d %H:%M:%S'), time)
326
350
  assert_equal(@expected, record)
327
351
  }
328
- assert_equal(TextParser::SyslogParser::REGEXP, @parser.patterns['format'])
329
- assert_equal("%b %d %H:%M:%S", @parser.patterns['time_format'])
352
+ assert_equal(TextParser::SyslogParser::REGEXP, @parser.instance.patterns['format'])
353
+ assert_equal("%b %d %H:%M:%S", @parser.instance.patterns['time_format'])
330
354
  end
331
355
 
332
356
  def test_parse_with_keep_time_key
@@ -0,0 +1,47 @@
1
+ require_relative 'helper'
2
+ require 'fluent/test'
3
+ require 'fluent/event'
4
+ require 'stringio'
5
+ require 'msgpack'
6
+
7
+ module FluentProcessTest
8
+ class DelayedForwarderTest < Test::Unit::TestCase
9
+ include Fluent
10
+
11
+ test 'run and emit' do
12
+ io = StringIO.new
13
+ fwd = Fluent::DetachProcessManager::DelayedForwarder.new(io, 0.001)
14
+
15
+ num_events_per_tag = 5000
16
+ num_tags = 20
17
+
18
+ now = Time.now.to_i
19
+ record = {'key' => 'value'}
20
+ (num_tags * num_events_per_tag).times do |i|
21
+ tag = "foo.bar#{i % num_tags}"
22
+ fwd.emit(tag, OneEventStream.new(now, record))
23
+ end
24
+ sleep 0.5
25
+
26
+ io.pos = 0
27
+
28
+ tags = {}
29
+ MessagePack::Unpacker.new(io).each do |tag_and_msgpacks|
30
+ tag, ms = *tag_and_msgpacks
31
+ tags[tag] ||= ''
32
+ tags[tag] << ms
33
+ end
34
+
35
+ assert_equal(num_tags, tags.size)
36
+ num_tags.times do |i|
37
+ tag = "foo.bar#{i % num_tags}"
38
+ ms = tags[tag]
39
+ count = 0
40
+ MessagePack::Unpacker.new(StringIO.new(ms)).each do |x|
41
+ count += 1
42
+ end
43
+ assert_equal(num_events_per_tag, count)
44
+ end
45
+ end
46
+ end
47
+ end
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.12.17
4
+ version: 0.12.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -380,8 +380,10 @@ files:
380
380
  - lib/fluent/test.rb
381
381
  - lib/fluent/test/base.rb
382
382
  - lib/fluent/test/filter_test.rb
383
+ - lib/fluent/test/formatter_test.rb
383
384
  - lib/fluent/test/input_test.rb
384
385
  - lib/fluent/test/output_test.rb
386
+ - lib/fluent/test/parser_test.rb
385
387
  - lib/fluent/timezone.rb
386
388
  - lib/fluent/version.rb
387
389
  - test/config/assertions.rb
@@ -444,6 +446,7 @@ files:
444
446
  - test/test_output.rb
445
447
  - test/test_parser.rb
446
448
  - test/test_plugin_classes.rb
449
+ - test/test_process.rb
447
450
  - test/test_root_agent.rb
448
451
  homepage: http://fluentd.org/
449
452
  licenses:
@@ -465,7 +468,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
465
468
  version: '0'
466
469
  requirements: []
467
470
  rubyforge_project:
468
- rubygems_version: 2.4.5.1
471
+ rubygems_version: 2.2.2
469
472
  signing_key:
470
473
  specification_version: 4
471
474
  summary: Fluentd event collector
@@ -530,4 +533,5 @@ test_files:
530
533
  - test/test_output.rb
531
534
  - test/test_parser.rb
532
535
  - test/test_plugin_classes.rb
536
+ - test/test_process.rb
533
537
  - test/test_root_agent.rb