fluentd 1.8.1 → 1.9.0.rc1

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 +2 -17
  3. data/CHANGELOG.md +23 -0
  4. data/Gemfile +1 -4
  5. data/README.md +2 -2
  6. data/fluentd.gemspec +2 -3
  7. data/lib/fluent/command/plugin_generator.rb +1 -1
  8. data/lib/fluent/config.rb +19 -0
  9. data/lib/fluent/config/literal_parser.rb +13 -8
  10. data/lib/fluent/engine.rb +60 -9
  11. data/lib/fluent/plugin/base.rb +5 -0
  12. data/lib/fluent/plugin/buf_file.rb +10 -6
  13. data/lib/fluent/plugin/buf_file_single.rb +10 -6
  14. data/lib/fluent/plugin/buffer.rb +35 -19
  15. data/lib/fluent/plugin/in_http.rb +9 -9
  16. data/lib/fluent/plugin/in_tail.rb +8 -6
  17. data/lib/fluent/plugin/out_http.rb +2 -2
  18. data/lib/fluent/plugin/output.rb +1 -1
  19. data/lib/fluent/plugin/parser.rb +6 -0
  20. data/lib/fluent/plugin_helper/http_server.rb +0 -1
  21. data/lib/fluent/plugin_helper/record_accessor.rb +0 -8
  22. data/lib/fluent/plugin_helper/server.rb +1 -16
  23. data/lib/fluent/plugin_id.rb +9 -4
  24. data/lib/fluent/static_config_analysis.rb +194 -0
  25. data/lib/fluent/supervisor.rb +101 -26
  26. data/lib/fluent/test/driver/base.rb +4 -3
  27. data/lib/fluent/variable_store.rb +40 -0
  28. data/lib/fluent/version.rb +1 -1
  29. data/test/config/test_system_config.rb +4 -4
  30. data/test/plugin/test_in_http.rb +35 -3
  31. data/test/plugin/test_out_http.rb +8 -2
  32. data/test/plugin/test_output.rb +3 -3
  33. data/test/plugin/test_output_as_buffered_secondary.rb +2 -2
  34. data/test/test_config.rb +27 -5
  35. data/test/test_engine.rb +203 -0
  36. data/test/test_output.rb +2 -2
  37. data/test/test_static_config_analysis.rb +177 -0
  38. data/test/test_supervisor.rb +4 -77
  39. data/test/test_variable_store.rb +65 -0
  40. metadata +15 -21
@@ -116,7 +116,7 @@ module FluentOutputTest
116
116
  end
117
117
  end
118
118
 
119
- mock(d.instance.log).warn("secondary type should be same with primary one",
119
+ mock(d.instance.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
120
120
  { primary: d.instance.class.to_s, secondary: "Fluent::Plugin::Test2Output" })
121
121
  d.configure(CONFIG + %[
122
122
  <secondary>
@@ -132,7 +132,7 @@ module FluentOutputTest
132
132
  # ObjectBufferedOutput doesn't implement `custom_filter`
133
133
  d = Fluent::Test::BufferedOutputTestDriver.new(Fluent::ObjectBufferedOutput)
134
134
 
135
- mock(d.instance.log).warn("secondary type should be same with primary one",
135
+ mock(d.instance.log).warn("Use different plugin for secondary. Check the plugin works with primary like secondary_file",
136
136
  { primary: d.instance.class.to_s, secondary: "Fluent::Plugin::Test2Output" }).never
137
137
  d.configure(CONFIG + %[
138
138
  <secondary>
@@ -0,0 +1,177 @@
1
+ require_relative 'helper'
2
+
3
+ require 'fluent/config'
4
+ require 'fluent/static_config_analysis'
5
+ require 'fluent/plugin/out_forward'
6
+ require 'fluent/plugin/out_stdout'
7
+ require 'fluent/plugin/out_exec'
8
+ require 'fluent/plugin/in_forward'
9
+ require 'fluent/plugin/in_dummy'
10
+ require 'fluent/plugin/filter_grep'
11
+ require 'fluent/plugin/filter_stdout'
12
+ require 'fluent/plugin/filter_parser'
13
+
14
+ class StaticConfigAnalysisTest < ::Test::Unit::TestCase
15
+ sub_test_case '.call' do
16
+ test 'returns outputs, inputs and filters' do
17
+ conf_data = <<-CONF
18
+ <source>
19
+ @type forward
20
+ </source>
21
+ <filter>
22
+ @type grep
23
+ </filter>
24
+ <match>
25
+ @type forward
26
+ </match>
27
+ CONF
28
+
29
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
30
+ ret = Fluent::StaticConfigAnalysis.call(c)
31
+ assert_equal 1, ret.outputs.size
32
+ assert_kind_of Fluent::Plugin::ForwardOutput, ret.outputs[0].plugin
33
+ assert_equal 1, ret.inputs.size
34
+ assert_kind_of Fluent::Plugin::ForwardInput, ret.inputs[0].plugin
35
+ assert_equal 1, ret.filters.size
36
+ assert_kind_of Fluent::Plugin::GrepFilter, ret.filters[0].plugin
37
+ assert_empty ret.labels
38
+
39
+ assert_equal [Fluent::Plugin::ForwardOutput, Fluent::Plugin::ForwardInput, Fluent::Plugin::GrepFilter], ret.all_plugins.map(&:class)
40
+ end
41
+
42
+ test 'returns wrapped element with worker and label section' do
43
+ conf_data = <<-CONF
44
+ <source>
45
+ @type forward
46
+ </source>
47
+ <filter>
48
+ @type grep
49
+ </filter>
50
+ <match>
51
+ @type forward
52
+ </match>
53
+ <worker 0>
54
+ <source>
55
+ @type dummy
56
+ </source>
57
+ <filter>
58
+ @type parser
59
+ </filter>
60
+ <match>
61
+ @type exec
62
+ </match>
63
+ </worker>
64
+ <label @test>
65
+ <filter>
66
+ @type stdout
67
+ </filter>
68
+ <match>
69
+ @type stdout
70
+ </match>
71
+ </label>
72
+ CONF
73
+
74
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
75
+ ret = Fluent::StaticConfigAnalysis.call(c)
76
+ assert_equal [Fluent::Plugin::ExecOutput, Fluent::Plugin::StdoutOutput, Fluent::Plugin::ForwardOutput], ret.outputs.map(&:plugin).map(&:class)
77
+ assert_equal [Fluent::Plugin::DummyInput, Fluent::Plugin::ForwardInput], ret.inputs.map(&:plugin).map(&:class)
78
+ assert_equal [Fluent::Plugin::ParserFilter, Fluent::Plugin::StdoutFilter, Fluent::Plugin::GrepFilter], ret.filters.map(&:plugin).map(&:class)
79
+ assert_equal 1, ret.labels.size
80
+ assert_equal '@test', ret.labels[0].name
81
+ end
82
+
83
+ sub_test_case 'raises config error' do
84
+ data(
85
+ 'empty' => ['', 'Missing worker id on <worker> directive'],
86
+ 'invalid number' => ['a', 'worker id should be integer: a'],
87
+ 'worker id is negative' => ['-1', 'worker id should be integer: -1'],
88
+ 'min worker id is less than 0' => ['-1-1', 'worker id should be integer: -1-1'],
89
+ 'max worker id is less than 0' => ['1--1', 'worker id -1 specified by <worker> directive is not allowed. Available worker id is between 0 and 1'],
90
+ 'min worker id is greater than workers' => ['0-2', 'worker id 2 specified by <worker> directive is not allowed. Available worker id is between 0 and 1'],
91
+ 'max worker is less than min worker' => ['1-0', "greater first_worker_id<1> than last_worker_id<0> specified by <worker> directive is not allowed. Available multi worker assign syntax is <smaller_worker_id>-<greater_worker_id>"],
92
+ )
93
+ test 'when worker number is invalid' do |v|
94
+ val, msg = v
95
+ conf_data = <<-CONF
96
+ <worker #{val}>
97
+ </worker>
98
+ CONF
99
+
100
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
101
+ assert_raise(Fluent::ConfigError.new(msg)) do
102
+ Fluent::StaticConfigAnalysis.call(c, workers: 2)
103
+ end
104
+ end
105
+
106
+ test 'when worker number is duplicated' do
107
+ conf_data = <<-CONF
108
+ <worker 0-1>
109
+ </worker>
110
+ <worker 0-1>
111
+ </worker>
112
+ CONF
113
+
114
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
115
+ assert_raise(Fluent::ConfigError.new("specified worker_id<0> collisions is detected on <worker> directive. Available worker id(s): []")) do
116
+ Fluent::StaticConfigAnalysis.call(c, workers: 2)
117
+ end
118
+ end
119
+
120
+ test 'duplicated label exits' do
121
+ conf_data = <<-CONF
122
+ <label @dup>
123
+ </label>
124
+ <label @dup>
125
+ </label>
126
+ CONF
127
+
128
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
129
+ assert_raise(Fluent::ConfigError.new('Section <label @dup> appears twice')) do
130
+ Fluent::StaticConfigAnalysis.call(c, workers: 2)
131
+ end
132
+ end
133
+
134
+ test 'empty label' do
135
+ conf_data = <<-CONF
136
+ <label>
137
+ </label>
138
+ CONF
139
+
140
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
141
+ assert_raise(Fluent::ConfigError.new('Missing symbol argument on <label> directive')) do
142
+ Fluent::StaticConfigAnalysis.call(c, workers: 2)
143
+ end
144
+ end
145
+
146
+ data(
147
+ 'in filter' => 'filter',
148
+ 'in source' => 'source',
149
+ 'in match' => 'match',
150
+ )
151
+ test 'when @type is missing' do |name|
152
+ conf_data = <<-CONF
153
+ <#{name}>
154
+ @type
155
+ </#{name}>
156
+ CONF
157
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
158
+ assert_raise(Fluent::ConfigError.new("Missing '@type' parameter on <#{name}> directive")) do
159
+ Fluent::StaticConfigAnalysis.call(c)
160
+ end
161
+ end
162
+
163
+ test 'when worker has worker section' do
164
+ conf_data = <<-CONF
165
+ <worker 0>
166
+ <worker 0>
167
+ </worker>
168
+ </worker>
169
+ CONF
170
+ c = Fluent::Config.parse(conf_data, '(test)', '(test_dir)', true)
171
+ assert_raise(Fluent::ConfigError.new("<worker> section cannot have <worker> directive")) do
172
+ Fluent::StaticConfigAnalysis.call(c)
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -30,81 +30,6 @@ class SupervisorTest < ::Test::Unit::TestCase
30
30
  File.open(path, "w") {|f| f.write data }
31
31
  end
32
32
 
33
- def test_read_config
34
- create_info_dummy_logger
35
-
36
- tmp_dir = "#{TMP_DIR}/dir/test_read_config.conf"
37
- conf_str = %[
38
- <source>
39
- @type forward
40
- @id forward_input
41
- </source>
42
- <match debug.**>
43
- @type stdout
44
- @id stdout_output
45
- </match>
46
- ]
47
- write_config tmp_dir, conf_str
48
- opts = Fluent::Supervisor.default_options
49
- sv = Fluent::Supervisor.new(opts)
50
-
51
- use_v1_config = {}
52
- use_v1_config['use_v1_config'] = true
53
-
54
- sv.instance_variable_set(:@config_path, tmp_dir)
55
- sv.instance_variable_set(:@use_v1_config, use_v1_config)
56
-
57
- conf = sv.__send__(:read_config)
58
- elem = conf.elements.find { |e| e.name == 'source' }
59
- assert_equal "forward", elem['@type']
60
- assert_equal "forward_input", elem['@id']
61
-
62
- elem = conf.elements.find { |e| e.name == 'match' }
63
- assert_equal "debug.**", elem.arg
64
- assert_equal "stdout", elem['@type']
65
- assert_equal "stdout_output", elem['@id']
66
-
67
- $log.out.reset
68
- end
69
-
70
- def test_read_config_with_multibyte_string
71
- tmp_path = "#{TMP_DIR}/dir/test_multibyte_config.conf"
72
- conf_str = %[
73
- <source>
74
- @type forward
75
- @id forward_input
76
- @label @INPUT
77
- </source>
78
- <label @INPUT>
79
- <filter>
80
- @type record_transformer
81
- <record>
82
- message こんにちは. ${record["name"]} has made a order of ${record["item"]} just now.
83
- </record>
84
- </filter>
85
- <match>
86
- @type stdout
87
- </match>
88
- </label>
89
- ]
90
- FileUtils.mkdir_p(File.dirname(tmp_path))
91
- File.open(tmp_path, "w:utf-8") {|file| file.write(conf_str) }
92
-
93
- opts = Fluent::Supervisor.default_options
94
- sv = Fluent::Supervisor.new(opts)
95
-
96
- use_v1_config = {}
97
- use_v1_config['use_v1_config'] = true
98
-
99
- sv.instance_variable_set(:@config_path, tmp_path)
100
- sv.instance_variable_set(:@use_v1_config, use_v1_config)
101
-
102
- conf = sv.__send__(:read_config)
103
- label = conf.elements.detect {|e| e.name == "label" }
104
- filter = label.elements.detect {|e| e.name == "filter" }
105
- record_transformer = filter.elements.detect {|e| e.name = "record_transformer" }
106
- assert_equal(Encoding::UTF_8, record_transformer["message"].encoding)
107
- end
108
33
 
109
34
  def test_system_config
110
35
  opts = Fluent::Supervisor.default_options
@@ -409,6 +334,8 @@ class SupervisorTest < ::Test::Unit::TestCase
409
334
  end
410
335
 
411
336
  def test_inline_config
337
+ omit 'this feature is deprecated. see https://github.com/fluent/fluentd/issues/2711'
338
+
412
339
  opts = Fluent::Supervisor.default_options
413
340
  opts[:inline_config] = '-'
414
341
  sv = Fluent::Supervisor.new(opts)
@@ -416,7 +343,7 @@ class SupervisorTest < ::Test::Unit::TestCase
416
343
 
417
344
  inline_config = '<match *>\n@type stdout\n</match>'
418
345
  stub(STDIN).read { inline_config }
419
- stub(sv).read_config # to skip
346
+ stub(Fluent::Config).build # to skip
420
347
  stub(sv).build_system_config { Fluent::SystemConfig.new } # to skip
421
348
 
422
349
  sv.configure
@@ -428,7 +355,7 @@ class SupervisorTest < ::Test::Unit::TestCase
428
355
  sv = Fluent::Supervisor.new(opts)
429
356
 
430
357
  c = Fluent::Config::Element.new('system', '', { 'log_level' => 'error' }, [])
431
- stub(sv).read_config { config_element('ROOT', '', {}, [c]) }
358
+ stub(Fluent::Config).build { config_element('ROOT', '', {}, [c]) }
432
359
 
433
360
  sv.configure
434
361
  assert_equal Fluent::Log::LEVEL_ERROR, $log.level
@@ -0,0 +1,65 @@
1
+ require_relative 'helper'
2
+ require 'fluent/variable_store'
3
+
4
+ class VariableStoreTest < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ Fluent::VariableStore.try_to_reset do
10
+ # nothing
11
+ end
12
+ end
13
+
14
+ sub_test_case '#fetch_or_build' do
15
+ test 'fetch same object when the same key is passed' do
16
+ c1 = Fluent::VariableStore.fetch_or_build(:test)
17
+ c2 = Fluent::VariableStore.fetch_or_build(:test)
18
+
19
+ assert_equal c1, c2
20
+ assert_equal c1.object_id, c2.object_id
21
+
22
+ c3 = Fluent::VariableStore.fetch_or_build(:test2)
23
+ assert_not_equal c1.object_id, c3.object_id
24
+ end
25
+
26
+ test 'can be passed a default value' do
27
+ c1 = Fluent::VariableStore.fetch_or_build(:test, default_value: Set.new)
28
+ c2 = Fluent::VariableStore.fetch_or_build(:test)
29
+
30
+ assert_kind_of Set, c1
31
+ assert_equal c1, c2
32
+ assert_equal c1.object_id, c2.object_id
33
+ end
34
+ end
35
+
36
+ sub_test_case '#try_to_reset' do
37
+ test 'reset all values' do
38
+ c1 = Fluent::VariableStore.fetch_or_build(:test)
39
+ c1[:k1] = 1
40
+ assert_equal 1, c1[:k1]
41
+
42
+ Fluent::VariableStore.try_to_reset do
43
+ # nothing
44
+ end
45
+
46
+ c1 = Fluent::VariableStore.fetch_or_build(:test)
47
+ assert_nil c1[:k1]
48
+ end
49
+
50
+ test 'rollback resetting if error raised' do
51
+ c1 = Fluent::VariableStore.fetch_or_build(:test)
52
+ c1[:k1] = 1
53
+ assert_equal 1, c1[:k1]
54
+
55
+ assert_raise(RuntimeError.new('pass')) do
56
+ Fluent::VariableStore.try_to_reset do
57
+ raise 'pass'
58
+ end
59
+ end
60
+
61
+ c1 = Fluent::VariableStore.fetch_or_build(:test)
62
+ assert_equal 1, c1[:k1]
63
+ end
64
+ end
65
+ 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: 1.8.1
4
+ version: 1.9.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-26 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -172,34 +172,20 @@ dependencies:
172
172
  - - "<"
173
173
  - !ruby/object:Gem::Version
174
174
  version: 1.0.0
175
- - !ruby/object:Gem::Dependency
176
- name: dig_rb
177
- requirement: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - "~>"
180
- - !ruby/object:Gem::Version
181
- version: 1.0.0
182
- type: :runtime
183
- prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- requirements:
186
- - - "~>"
187
- - !ruby/object:Gem::Version
188
- version: 1.0.0
189
175
  - !ruby/object:Gem::Dependency
190
176
  name: rake
191
177
  requirement: !ruby/object:Gem::Requirement
192
178
  requirements:
193
179
  - - "~>"
194
180
  - !ruby/object:Gem::Version
195
- version: '11.0'
181
+ version: '12.0'
196
182
  type: :development
197
183
  prerelease: false
198
184
  version_requirements: !ruby/object:Gem::Requirement
199
185
  requirements:
200
186
  - - "~>"
201
187
  - !ruby/object:Gem::Version
202
- version: '11.0'
188
+ version: '12.0'
203
189
  - !ruby/object:Gem::Dependency
204
190
  name: flexmock
205
191
  requirement: !ruby/object:Gem::Requirement
@@ -597,6 +583,7 @@ files:
597
583
  - lib/fluent/registry.rb
598
584
  - lib/fluent/root_agent.rb
599
585
  - lib/fluent/rpc.rb
586
+ - lib/fluent/static_config_analysis.rb
600
587
  - lib/fluent/supervisor.rb
601
588
  - lib/fluent/system_config.rb
602
589
  - lib/fluent/test.rb
@@ -623,6 +610,7 @@ files:
623
610
  - lib/fluent/time.rb
624
611
  - lib/fluent/timezone.rb
625
612
  - lib/fluent/unique_id.rb
613
+ - lib/fluent/variable_store.rb
626
614
  - lib/fluent/version.rb
627
615
  - lib/fluent/winsvc.rb
628
616
  - templates/new_gem/Gemfile
@@ -800,6 +788,7 @@ files:
800
788
  - test/test_clock.rb
801
789
  - test/test_config.rb
802
790
  - test/test_configdsl.rb
791
+ - test/test_engine.rb
803
792
  - test/test_event.rb
804
793
  - test/test_event_router.rb
805
794
  - test/test_event_time.rb
@@ -818,11 +807,13 @@ files:
818
807
  - test/test_plugin_id.rb
819
808
  - test/test_process.rb
820
809
  - test/test_root_agent.rb
810
+ - test/test_static_config_analysis.rb
821
811
  - test/test_supervisor.rb
822
812
  - test/test_test_drivers.rb
823
813
  - test/test_time_formatter.rb
824
814
  - test/test_time_parser.rb
825
815
  - test/test_unique_id.rb
816
+ - test/test_variable_store.rb
826
817
  homepage: https://www.fluentd.org/
827
818
  licenses:
828
819
  - Apache-2.0
@@ -835,12 +826,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
835
826
  requirements:
836
827
  - - ">="
837
828
  - !ruby/object:Gem::Version
838
- version: '2.1'
829
+ version: '2.4'
839
830
  required_rubygems_version: !ruby/object:Gem::Requirement
840
831
  requirements:
841
- - - ">="
832
+ - - ">"
842
833
  - !ruby/object:Gem::Version
843
- version: '0'
834
+ version: 1.3.1
844
835
  requirements: []
845
836
  rubygems_version: 3.0.3
846
837
  signing_key:
@@ -1004,6 +995,7 @@ test_files:
1004
995
  - test/test_clock.rb
1005
996
  - test/test_config.rb
1006
997
  - test/test_configdsl.rb
998
+ - test/test_engine.rb
1007
999
  - test/test_event.rb
1008
1000
  - test/test_event_router.rb
1009
1001
  - test/test_event_time.rb
@@ -1022,8 +1014,10 @@ test_files:
1022
1014
  - test/test_plugin_id.rb
1023
1015
  - test/test_process.rb
1024
1016
  - test/test_root_agent.rb
1017
+ - test/test_static_config_analysis.rb
1025
1018
  - test/test_supervisor.rb
1026
1019
  - test/test_test_drivers.rb
1027
1020
  - test/test_time_formatter.rb
1028
1021
  - test/test_time_parser.rb
1029
1022
  - test/test_unique_id.rb
1023
+ - test/test_variable_store.rb