fluentd 1.12.4-x86-mingw32 → 1.13.3-x86-mingw32

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
  4. data/.github/workflows/linux-test.yaml +1 -1
  5. data/.github/workflows/windows-test.yaml +14 -3
  6. data/.gitlab-ci.yml +0 -22
  7. data/CHANGELOG.md +129 -0
  8. data/CONTRIBUTING.md +2 -2
  9. data/MAINTAINERS.md +1 -1
  10. data/README.md +3 -3
  11. data/bin/fluentd +8 -1
  12. data/example/counter.conf +1 -1
  13. data/example/v0_12_filter.conf +2 -2
  14. data/fluentd.gemspec +1 -1
  15. data/lib/fluent/command/cat.rb +19 -3
  16. data/lib/fluent/command/fluentd.rb +1 -2
  17. data/lib/fluent/command/plugin_generator.rb +15 -5
  18. data/lib/fluent/config.rb +1 -1
  19. data/lib/fluent/config/section.rb +5 -0
  20. data/lib/fluent/config/types.rb +15 -0
  21. data/lib/fluent/config/v1_parser.rb +3 -2
  22. data/lib/fluent/env.rb +2 -1
  23. data/lib/fluent/log.rb +1 -0
  24. data/lib/fluent/oj_options.rb +62 -0
  25. data/lib/fluent/plugin/file_wrapper.rb +35 -4
  26. data/lib/fluent/plugin/formatter.rb +1 -0
  27. data/lib/fluent/plugin/formatter_json.rb +9 -7
  28. data/lib/fluent/plugin/in_http.rb +10 -0
  29. data/lib/fluent/plugin/in_tail.rb +159 -41
  30. data/lib/fluent/plugin/in_tail/position_file.rb +20 -18
  31. data/lib/fluent/plugin/out_forward.rb +14 -33
  32. data/lib/fluent/plugin/parser_json.rb +2 -3
  33. data/lib/fluent/plugin/service_discovery.rb +0 -15
  34. data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
  35. data/lib/fluent/plugin_helper/service_discovery.rb +39 -1
  36. data/lib/fluent/plugin_helper/service_discovery/manager.rb +11 -5
  37. data/lib/fluent/supervisor.rb +15 -0
  38. data/lib/fluent/system_config.rb +14 -0
  39. data/lib/fluent/test/driver/storage.rb +30 -0
  40. data/lib/fluent/version.rb +1 -1
  41. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  42. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  43. data/test/command/test_cat.rb +99 -0
  44. data/test/command/test_plugin_generator.rb +2 -1
  45. data/test/config/test_section.rb +9 -0
  46. data/test/config/test_system_config.rb +46 -0
  47. data/test/config/test_types.rb +7 -0
  48. data/test/plugin/in_tail/test_io_handler.rb +4 -4
  49. data/test/plugin/in_tail/test_position_file.rb +23 -5
  50. data/test/plugin/test_file_wrapper.rb +22 -1
  51. data/test/plugin/test_in_forward.rb +59 -83
  52. data/test/plugin/test_in_http.rb +58 -40
  53. data/test/plugin/test_in_syslog.rb +66 -56
  54. data/test/plugin/test_in_tail.rb +341 -1
  55. data/test/plugin/test_in_tcp.rb +45 -32
  56. data/test/plugin/test_in_udp.rb +47 -33
  57. data/test/plugin/test_out_forward.rb +114 -95
  58. data/test/plugin/test_out_stream.rb +18 -8
  59. data/test/plugin_helper/http_server/test_route.rb +1 -1
  60. data/test/plugin_helper/test_child_process.rb +1 -1
  61. data/test/plugin_helper/test_http_server_helper.rb +33 -26
  62. data/test/plugin_helper/test_server.rb +137 -138
  63. data/test/plugin_helper/test_service_discovery.rb +74 -14
  64. data/test/plugin_helper/test_socket.rb +16 -9
  65. data/test/test_config.rb +2 -1
  66. data/test/test_event_time.rb +2 -2
  67. data/test/test_oj_options.rb +55 -0
  68. data/test/test_supervisor.rb +35 -0
  69. metadata +15 -7
  70. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  71. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '1.12.4'
19
+ VERSION = '1.13.3'
20
20
 
21
21
  end
@@ -0,0 +1,40 @@
1
+ <%= preamble %>
2
+
3
+ require "fluent/plugin/storage"
4
+
5
+ module Fluent
6
+ module Plugin
7
+ class <%= class_name %> < Fluent::Plugin::Storage
8
+ Fluent::Plugin.register_storage("<%= plugin_name %>", self)
9
+
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ def configure(conf)
15
+ super
16
+ end
17
+
18
+ def load
19
+ end
20
+
21
+ def save
22
+ end
23
+
24
+ def get(key)
25
+ end
26
+
27
+ def fetch(key, defval)
28
+ end
29
+
30
+ def put(key, value)
31
+ end
32
+
33
+ def delete(key)
34
+ end
35
+
36
+ def update(key, &block)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require "helper"
2
+ require "fluent/plugin/<%= plugin_filename %>"
3
+
4
+ class <%= class_name %>Test < Test::Unit::TestCase
5
+ setup do
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ test "failure" do
10
+ flunk
11
+ end
12
+
13
+ private
14
+
15
+ def create_driver(conf)
16
+ Fluent::Test::Driver::Storage.new(Fluent::Plugin::<%= class_name %>).configure(conf)
17
+ end
18
+ end
@@ -0,0 +1,99 @@
1
+ require_relative '../helper'
2
+
3
+ require 'test-unit'
4
+ require 'open3'
5
+ require 'fluent/plugin/output'
6
+ require 'fluent/plugin/in_forward'
7
+ require 'fluent/plugin/out_secondary_file'
8
+ require 'fluent/test/driver/output'
9
+ require 'fluent/test/driver/input'
10
+
11
+ class TestFluentCat < ::Test::Unit::TestCase
12
+ def setup
13
+ Fluent::Test.setup
14
+ FileUtils.mkdir_p(TMP_DIR)
15
+ @record = { 'key' => 'value' }
16
+ @time = event_time
17
+ @es = Fluent::OneEventStream.new(@time, @record)
18
+ @primary = create_primary
19
+ metadata = @primary.buffer.new_metadata
20
+ @chunk = create_chunk(@primary, metadata, @es)
21
+ @port = unused_port
22
+ end
23
+
24
+ def teardown
25
+ FileUtils.rm_rf(TMP_DIR)
26
+ @port = nil
27
+ end
28
+
29
+ TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluent_cat#{ENV['TEST_ENV_NUMBER']}")
30
+ FLUENT_CAT_COMMAND = File.expand_path(File.dirname(__FILE__) + "/../../bin/fluent-cat")
31
+
32
+ def config
33
+ %[
34
+ port #{@port}
35
+ bind 127.0.0.1
36
+ ]
37
+ end
38
+
39
+ SECONDARY_CONFIG = %[
40
+ directory #{TMP_DIR}
41
+ ]
42
+
43
+ class DummyOutput < Fluent::Plugin::Output
44
+ def write(chunk); end
45
+ end
46
+
47
+ def create_driver(conf=config)
48
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ForwardInput).configure(conf)
49
+ end
50
+
51
+ def create_primary(buffer_cofig = config_element('buffer'))
52
+ DummyOutput.new.configure(config_element('ROOT','',{}, [buffer_cofig]))
53
+ end
54
+
55
+ def create_secondary_driver(conf=SECONDARY_CONFIG)
56
+ c = Fluent::Test::Driver::Output.new(Fluent::Plugin::SecondaryFileOutput)
57
+ c.instance.acts_as_secondary(@primary)
58
+ c.configure(conf)
59
+ end
60
+
61
+ def create_chunk(primary, metadata, es)
62
+ primary.buffer.generate_chunk(metadata).tap do |c|
63
+ c.concat(es.to_msgpack_stream, es.size)
64
+ c.commit
65
+ end
66
+ end
67
+
68
+ sub_test_case "json" do
69
+ def test_cat_json
70
+ d = create_driver
71
+ d.run(expect_records: 1) do
72
+ Open3.pipeline_w("ruby #{FLUENT_CAT_COMMAND} --port #{@port} json") do |stdin|
73
+ stdin.puts('{"key":"value"}')
74
+ stdin.close
75
+ end
76
+ end
77
+ event = d.events.first
78
+ assert_equal([1, "json", @record],
79
+ [d.events.size, event.first, event.last])
80
+ end
81
+ end
82
+
83
+ sub_test_case "msgpack" do
84
+ def test_cat_secondary_file
85
+ d = create_secondary_driver
86
+ path = d.instance.write(@chunk)
87
+ d = create_driver
88
+ d.run(expect_records: 1) do
89
+ Open3.pipeline_w("ruby #{FLUENT_CAT_COMMAND} --port #{@port} --format msgpack secondary") do |stdin|
90
+ stdin.write(File.read(path))
91
+ stdin.close
92
+ end
93
+ end
94
+ event = d.events.first
95
+ assert_equal([1, "secondary", @record],
96
+ [d.events.size, event.first, event.last])
97
+ end
98
+ end
99
+ end
@@ -29,7 +29,8 @@ class TestFluentPluginGenerator < Test::Unit::TestCase
29
29
  output: ["output", "out"],
30
30
  filter: ["filter", "filter"],
31
31
  parser: ["parser", "parser"],
32
- formatter: ["formatter", "formatter"])
32
+ formatter: ["formatter", "formatter"],
33
+ storage: ["storage", "storage"])
33
34
  test "generate plugin" do |(type, part)|
34
35
  generator = FluentPluginGenerator.new([type, "fake"])
35
36
  stub_git_process(generator)
@@ -1,5 +1,6 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/config/section'
3
+ require 'pp'
3
4
 
4
5
  module Fluent::Config
5
6
  class TestSection < ::Test::Unit::TestCase
@@ -176,6 +177,14 @@ module Fluent::Config
176
177
  s1 = Fluent::Config::Section.new(h1)
177
178
  assert_equal(expected, s1.respond_to?(method))
178
179
  end
180
+
181
+ test '#pretty_print' do
182
+ q = PP.new
183
+ h1 = {name: "s1", klass: "A"}
184
+ s1 = Fluent::Config::Section.new(h1)
185
+ s1.pretty_print(q)
186
+ assert_equal s1.inspect, q.output
187
+ end
179
188
  end
180
189
  end
181
190
  end
@@ -143,5 +143,51 @@ module Fluent::Config
143
143
  sc.overwrite_variables(**s.for_system_config)
144
144
  assert_equal(level, sc.log_level)
145
145
  end
146
+
147
+ sub_test_case "log rotation" do
148
+ data('daily' => "daily",
149
+ 'weekly' => 'weekly',
150
+ 'monthly' => 'monthly')
151
+ test "symbols for rotate_age" do |age|
152
+ conf = parse_text(<<-EOS)
153
+ <system>
154
+ <log>
155
+ rotate_age #{age}
156
+ </log>
157
+ </system>
158
+ EOS
159
+ sc = Fluent::SystemConfig.new(conf)
160
+ assert_equal(age.to_sym, sc.log.rotate_age)
161
+ end
162
+
163
+ test "numeric number for rotate age" do
164
+ conf = parse_text(<<-EOS)
165
+ <system>
166
+ <log>
167
+ rotate_age 3
168
+ </log>
169
+ </system>
170
+ EOS
171
+ s = FakeSupervisor.new
172
+ sc = Fluent::SystemConfig.new(conf)
173
+ assert_equal(3, sc.log.rotate_age)
174
+ end
175
+
176
+ data(h: ['100', 100],
177
+ k: ['1k', 1024],
178
+ m: ['1m', 1024 * 1024],
179
+ g: ['1g', 1024 * 1024 * 1024])
180
+ test "numeric and SI prefix for rotate_size" do |(label, size)|
181
+ conf = parse_text(<<-EOS)
182
+ <system>
183
+ <log>
184
+ rotate_size #{label}
185
+ </log>
186
+ </system>
187
+ EOS
188
+ sc = Fluent::SystemConfig.new(conf)
189
+ assert_equal(size, sc.log.rotate_size)
190
+ end
191
+ end
146
192
  end
147
193
  end
@@ -180,6 +180,13 @@ class TestConfigTypes < ::Test::Unit::TestCase
180
180
  assert_equal Encoding::UTF_8, actual.encoding
181
181
  end
182
182
 
183
+ data('starts_with_semicolon' => [:conor, ':conor'],
184
+ 'simple_string' => [:conor, 'conor'],
185
+ 'empty_string' => [nil, ''])
186
+ test 'symbol' do |(expected, val)|
187
+ assert_equal Config::SYMBOL_TYPE.call(val, {}), expected
188
+ end
189
+
183
190
  data("val" => [:val, 'val'],
184
191
  "v" => [:v, 'v'],
185
192
  "value" => [:value, 'value'])
@@ -30,7 +30,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  returned_lines = ''
33
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, log: $log, open_on_every_update: false) do |lines, _watcher|
33
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
34
34
  returned_lines << lines.join
35
35
  true
36
36
  end
@@ -62,7 +62,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
62
62
  end
63
63
 
64
64
  returned_lines = ''
65
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, log: $log, open_on_every_update: true) do |lines, _watcher|
65
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: true) do |lines, _watcher|
66
66
  returned_lines << lines.join
67
67
  true
68
68
  end
@@ -93,7 +93,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
93
93
  end
94
94
 
95
95
  returned_lines = []
96
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, log: $log, open_on_every_update: false) do |lines, _watcher|
96
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
97
97
  returned_lines << lines.dup
98
98
  true
99
99
  end
@@ -119,7 +119,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
119
119
  end
120
120
 
121
121
  returned_lines = []
122
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, log: $log, open_on_every_update: false) do |lines, _watcher|
122
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
123
123
  returned_lines << lines.dup
124
124
  true
125
125
  end
@@ -48,7 +48,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
48
48
  sub_test_case '#try_compact' do
49
49
  test 'compact invalid and convert 32 bit inode value' do
50
50
  write_data(@file, TEST_CONTENT)
51
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
51
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).try_compact
52
52
 
53
53
  @file.seek(0)
54
54
  lines = @file.readlines
@@ -62,7 +62,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
62
62
  valid_path\t0000000000000002\t0000000000000001
63
63
  valid_path\t0000000000000003\t0000000000000004
64
64
  EOF
65
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
65
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).try_compact
66
66
 
67
67
  @file.seek(0)
68
68
  lines = @file.readlines
@@ -71,7 +71,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
71
71
 
72
72
  test 'does not change when the file is changed' do
73
73
  write_data(@file, TEST_CONTENT)
74
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
74
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log})
75
75
 
76
76
  mock.proxy(pf).fetch_compacted_entries do |r|
77
77
  @file.write("unwatched\t#{UNWATCHED_STR}\t0000000000000000\n")
@@ -86,7 +86,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
86
86
  end
87
87
 
88
88
  test 'update seek position of remained position entry' do
89
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
89
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log})
90
90
  target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('path1', -1)
91
91
  target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', -1)
92
92
  target_info3 = Fluent::Plugin::TailInput::TargetInfo.new('path3', -1)
@@ -115,6 +115,24 @@ class IntailPositionFileTest < Test::Unit::TestCase
115
115
  assert_equal "path3\t#{UNWATCHED_STR}\t0000000000000000\n", lines[1]
116
116
  assert_equal 2, lines.size
117
117
  end
118
+
119
+ test 'should ignore initial existing files on follow_inode' do
120
+ write_data(@file, TEST_CONTENT)
121
+ pos_file = Fluent::Plugin::TailInput::PositionFile.load(@file, true, {}, **{logger: $log})
122
+ @file.seek(0)
123
+ assert_equal([], @file.readlines)
124
+
125
+ @file.seek(0)
126
+ write_data(@file, TEST_CONTENT)
127
+ pos_file.try_compact
128
+
129
+ @file.seek(0)
130
+ assert_equal([
131
+ "valid_path\t0000000000000002\t0000000000000001\n",
132
+ "inode23bit\t0000000000000000\t0000000000000000\n",
133
+ ],
134
+ @file.readlines)
135
+ end
118
136
  end
119
137
 
120
138
  sub_test_case '#load' do
@@ -134,7 +152,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
134
152
  valid_path\t0000000000000002\t0000000000000001
135
153
  valid_path\t0000000000000003\t0000000000000004
136
154
  EOF
137
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).load
155
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).load
138
156
 
139
157
  @file.seek(0)
140
158
  lines = @file.readlines
@@ -58,6 +58,15 @@ class FileWrapperTest < Test::Unit::TestCase
58
58
  assert_equal("#<Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt>",
59
59
  Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").inspect)
60
60
  end
61
+
62
+ data('0' => [false, 0],
63
+ '9999' => [false, 9999],
64
+ '10000' => [true, 10000],
65
+ '10001' => [true, 10001])
66
+ test 'wsaerr?' do |data|
67
+ expected, code = data
68
+ assert_equal(expected, Fluent::Win32Error.new(code).wsaerr?)
69
+ end
61
70
  end
62
71
 
63
72
  sub_test_case 'WindowsFile exceptions' do
@@ -87,12 +96,24 @@ class FileWrapperTest < Test::Unit::TestCase
87
96
  end
88
97
  end
89
98
 
99
+ test 'Errno::ENOENT raised on DeletePending' do
100
+ path = "#{TMP_DIR}/deletepending.txt"
101
+ file = Fluent::WindowsFile.new(path, mode='w')
102
+ File.delete(path)
103
+ assert_raise(Errno::ENOENT) do
104
+ file.stat
105
+ ensure
106
+ file.close if file
107
+ end
108
+ end
109
+
90
110
  test 'ERROR_SHARING_VIOLATION raised' do
91
111
  begin
92
112
  path = "#{TMP_DIR}/test_windows_file.txt"
93
113
  file1 = file2 = nil
94
114
  file1 = File.open(path, "wb")
95
- assert_raise(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)) do
115
+ win32err = Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)
116
+ assert_raise(Errno::EACCES.new(win32err.message)) do
96
117
  file2 = Fluent::WindowsFile.new(path, 'r', FILE_SHARE_READ)
97
118
  ensure
98
119
  file2.close if file2
@@ -18,52 +18,55 @@ class ForwardInputTest < Test::Unit::TestCase
18
18
  Fluent::Test.setup
19
19
  @responses = [] # for testing responses after sending data
20
20
  @d = nil
21
+ @port = unused_port
21
22
  end
22
23
 
23
24
  def teardown
24
25
  @d.instance_shutdown if @d
26
+ @port = nil
25
27
  end
26
28
 
27
- PORT = unused_port
28
-
29
29
  SHARED_KEY = 'foobar1'
30
30
  USER_NAME = 'tagomoris'
31
31
  USER_PASSWORD = 'fluentd'
32
32
 
33
- CONFIG = %[
34
- port #{PORT}
35
- bind 127.0.0.1
36
- ]
33
+ def base_config
34
+ %[
35
+ port #{@port}
36
+ bind 127.0.0.1
37
+ ]
38
+ end
37
39
  LOCALHOST_HOSTNAME_GETTER = ->(){sock = UDPSocket.new(::Socket::AF_INET); sock.do_not_reverse_lookup = false; sock.connect("127.0.0.1", 2048); sock.peeraddr[2] }
38
40
  LOCALHOST_HOSTNAME = LOCALHOST_HOSTNAME_GETTER.call
39
41
  DUMMY_SOCK = Struct.new(:remote_host, :remote_addr, :remote_port).new(LOCALHOST_HOSTNAME, "127.0.0.1", 0)
40
- CONFIG_AUTH = %[
41
- port #{PORT}
42
- bind 127.0.0.1
43
- <security>
44
- self_hostname localhost
45
- shared_key foobar1
46
- user_auth true
47
- <user>
48
- username #{USER_NAME}
49
- password #{USER_PASSWORD}
50
- </user>
51
- <client>
52
- network 127.0.0.0/8
53
- shared_key #{SHARED_KEY}
54
- users ["#{USER_NAME}"]
55
- </client>
56
- </security>
57
- ]
58
-
59
- def create_driver(conf=CONFIG)
42
+
43
+ def config_auth
44
+ base_config + %[
45
+ <security>
46
+ self_hostname localhost
47
+ shared_key foobar1
48
+ user_auth true
49
+ <user>
50
+ username #{USER_NAME}
51
+ password #{USER_PASSWORD}
52
+ </user>
53
+ <client>
54
+ network 127.0.0.0/8
55
+ shared_key #{SHARED_KEY}
56
+ users ["#{USER_NAME}"]
57
+ </client>
58
+ </security>
59
+ ]
60
+ end
61
+
62
+ def create_driver(conf=base_config)
60
63
  Fluent::Test::Driver::Input.new(Fluent::Plugin::ForwardInput).configure(conf)
61
64
  end
62
65
 
63
66
  sub_test_case '#configure' do
64
67
  test 'simple' do
65
68
  @d = d = create_driver
66
- assert_equal PORT, d.instance.port
69
+ assert_equal @port, d.instance.port
67
70
  assert_equal '127.0.0.1', d.instance.bind
68
71
  assert_equal 0, d.instance.linger_timeout
69
72
  assert_equal 0.5, d.instance.blocking_timeout
@@ -71,8 +74,8 @@ class ForwardInputTest < Test::Unit::TestCase
71
74
  end
72
75
 
73
76
  test 'auth' do
74
- @d = d = create_driver(CONFIG_AUTH)
75
- assert_equal PORT, d.instance.port
77
+ @d = d = create_driver(config_auth)
78
+ assert_equal @port, d.instance.port
76
79
  assert_equal '127.0.0.1', d.instance.bind
77
80
  assert_equal 0, d.instance.linger_timeout
78
81
  assert !d.instance.backlog
@@ -86,17 +89,17 @@ class ForwardInputTest < Test::Unit::TestCase
86
89
  add_tag_prefix: "add_tag_prefix")
87
90
  test 'tag parameters' do |data|
88
91
  assert_raise(Fluent::ConfigError.new("'#{data}' parameter must not be empty")) {
89
- create_driver(CONFIG + "#{data} ''")
92
+ create_driver(base_config + "#{data} ''")
90
93
  }
91
94
  end
92
95
 
93
96
  test 'send_keepalive_packet is disabled by default' do
94
- @d = d = create_driver(CONFIG_AUTH)
97
+ @d = d = create_driver(config_auth)
95
98
  assert_false d.instance.send_keepalive_packet
96
99
  end
97
100
 
98
101
  test 'send_keepalive_packet can be enabled' do
99
- @d = d = create_driver(CONFIG_AUTH + %[
102
+ @d = d = create_driver(config_auth + %[
100
103
  send_keepalive_packet true
101
104
  ])
102
105
  assert_true d.instance.send_keepalive_packet
@@ -104,7 +107,7 @@ class ForwardInputTest < Test::Unit::TestCase
104
107
 
105
108
  test 'both send_keepalive_packet and deny_keepalive cannot be enabled' do
106
109
  assert_raise(Fluent::ConfigError.new("both 'send_keepalive_packet' and 'deny_keepalive' cannot be set to true")) do
107
- create_driver(CONFIG_AUTH + %[
110
+ create_driver(config_auth + %[
108
111
  send_keepalive_packet true
109
112
  deny_keepalive true
110
113
  ])
@@ -173,7 +176,7 @@ class ForwardInputTest < Test::Unit::TestCase
173
176
  end
174
177
 
175
178
  test 'skip_invalid_event' do
176
- @d = d = create_driver(CONFIG + "skip_invalid_event true")
179
+ @d = d = create_driver(base_config + "skip_invalid_event true")
177
180
 
178
181
  time = event_time("2011-01-02 13:14:15 UTC")
179
182
 
@@ -243,20 +246,18 @@ class ForwardInputTest < Test::Unit::TestCase
243
246
 
244
247
  sub_test_case 'forward' do
245
248
  data(tcp: {
246
- config: CONFIG,
247
249
  options: {
248
250
  auth: false
249
251
  }
250
252
  },
251
253
  auth: {
252
- config: CONFIG_AUTH,
253
254
  options: {
254
255
  auth: true
255
256
  }
256
257
  })
257
258
  test 'plain' do |data|
258
- config = data[:config]
259
259
  options = data[:options]
260
+ config = options[:auth] ? config_auth : base_config
260
261
  @d = d = create_driver(config)
261
262
 
262
263
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -285,7 +286,7 @@ class ForwardInputTest < Test::Unit::TestCase
285
286
  result: "new_prefix.tag1"
286
287
  })
287
288
  test 'tag parameters' do |data|
288
- @d = create_driver(CONFIG + data[:param])
289
+ @d = create_driver(base_config + data[:param])
289
290
  time = event_time("2011-01-02 13:14:15 UTC")
290
291
  options = {auth: false}
291
292
 
@@ -305,20 +306,18 @@ class ForwardInputTest < Test::Unit::TestCase
305
306
  end
306
307
 
307
308
  data(tcp: {
308
- config: CONFIG,
309
309
  options: {
310
310
  auth: false
311
311
  }
312
312
  },
313
313
  auth: {
314
- config: CONFIG_AUTH,
315
314
  options: {
316
315
  auth: true
317
316
  }
318
317
  })
319
318
  test 'time_as_integer' do |data|
320
- config = data[:config]
321
319
  options = data[:options]
320
+ config = options[:auth] ? config_auth : base_config
322
321
  @d = d = create_driver(config)
323
322
 
324
323
  time_i = event_time("2011-01-02 13:14:15 UTC")
@@ -340,20 +339,18 @@ class ForwardInputTest < Test::Unit::TestCase
340
339
  end
341
340
 
342
341
  data(tcp: {
343
- config: CONFIG,
344
342
  options: {
345
343
  auth: false
346
344
  }
347
345
  },
348
346
  auth: {
349
- config: CONFIG_AUTH,
350
347
  options: {
351
348
  auth: true
352
349
  }
353
350
  })
354
351
  test 'skip_invalid_event' do |data|
355
- config = data[:config]
356
352
  options = data[:options]
353
+ config = options[:auth] ? config_auth : base_config
357
354
  @d = d = create_driver(config + "skip_invalid_event true")
358
355
 
359
356
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -380,20 +377,18 @@ class ForwardInputTest < Test::Unit::TestCase
380
377
 
381
378
  sub_test_case 'packed forward' do
382
379
  data(tcp: {
383
- config: CONFIG,
384
380
  options: {
385
381
  auth: false
386
382
  }
387
383
  },
388
384
  auth: {
389
- config: CONFIG_AUTH,
390
385
  options: {
391
386
  auth: true
392
387
  }
393
388
  })
394
389
  test 'plain' do |data|
395
- config = data[:config]
396
390
  options = data[:options]
391
+ config = options[:auth] ? config_auth : base_config
397
392
  @d = d = create_driver(config)
398
393
 
399
394
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -422,7 +417,7 @@ class ForwardInputTest < Test::Unit::TestCase
422
417
  result: "new_prefix.tag1"
423
418
  })
424
419
  test 'tag parameters' do |data|
425
- @d = create_driver(CONFIG + data[:param])
420
+ @d = create_driver(base_config + data[:param])
426
421
  time = event_time("2011-01-02 13:14:15 UTC")
427
422
  options = {auth: false}
428
423
 
@@ -442,20 +437,18 @@ class ForwardInputTest < Test::Unit::TestCase
442
437
  end
443
438
 
444
439
  data(tcp: {
445
- config: CONFIG,
446
440
  options: {
447
441
  auth: false
448
442
  }
449
443
  },
450
444
  auth: {
451
- config: CONFIG_AUTH,
452
445
  options: {
453
446
  auth: true
454
447
  }
455
448
  })
456
449
  test 'time_as_integer' do |data|
457
- config = data[:config]
458
450
  options = data[:options]
451
+ config = options[:auth] ? config_auth : base_config
459
452
  @d = d = create_driver(config)
460
453
 
461
454
  time_i = event_time("2011-01-02 13:14:15 UTC").to_i
@@ -476,20 +469,18 @@ class ForwardInputTest < Test::Unit::TestCase
476
469
  end
477
470
 
478
471
  data(tcp: {
479
- config: CONFIG,
480
472
  options: {
481
473
  auth: false
482
474
  }
483
475
  },
484
476
  auth: {
485
- config: CONFIG_AUTH,
486
477
  options: {
487
478
  auth: true
488
479
  }
489
480
  })
490
481
  test 'skip_invalid_event' do |data|
491
- config = data[:config]
492
482
  options = data[:options]
483
+ config = options[:auth] ? config_auth : base_config
493
484
  @d = d = create_driver(config + "skip_invalid_event true")
494
485
 
495
486
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -577,7 +568,7 @@ class ForwardInputTest < Test::Unit::TestCase
577
568
 
578
569
  sub_test_case 'warning' do
579
570
  test 'send_large_chunk_warning' do
580
- @d = d = create_driver(CONFIG + %[
571
+ @d = d = create_driver(base_config + %[
581
572
  chunk_size_warn_limit 16M
582
573
  chunk_size_limit 32M
583
574
  ])
@@ -613,7 +604,7 @@ class ForwardInputTest < Test::Unit::TestCase
613
604
  end
614
605
 
615
606
  test 'send_large_chunk_only_warning' do
616
- @d = d = create_driver(CONFIG + %[
607
+ @d = d = create_driver(base_config + %[
617
608
  chunk_size_warn_limit 16M
618
609
  ])
619
610
  time = event_time("2014-04-25 13:14:15 UTC")
@@ -639,7 +630,7 @@ class ForwardInputTest < Test::Unit::TestCase
639
630
  end
640
631
 
641
632
  test 'send_large_chunk_limit' do
642
- @d = d = create_driver(CONFIG + %[
633
+ @d = d = create_driver(base_config + %[
643
634
  chunk_size_warn_limit 16M
644
635
  chunk_size_limit 32M
645
636
  ])
@@ -697,20 +688,18 @@ class ForwardInputTest < Test::Unit::TestCase
697
688
 
698
689
  sub_test_case 'respond to required ack' do
699
690
  data(tcp: {
700
- config: CONFIG,
701
691
  options: {
702
692
  auth: false
703
693
  }
704
694
  },
705
695
  auth: {
706
- config: CONFIG_AUTH,
707
696
  options: {
708
697
  auth: true
709
698
  }
710
699
  })
711
700
  test 'message' do |data|
712
- config = data[:config]
713
701
  options = data[:options]
702
+ config = options[:auth] ? config_auth : base_config
714
703
  @d = d = create_driver(config)
715
704
 
716
705
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -736,20 +725,18 @@ class ForwardInputTest < Test::Unit::TestCase
736
725
 
737
726
  # FIX: response is not pushed into @responses because IO.select has been blocked until InputForward shutdowns
738
727
  data(tcp: {
739
- config: CONFIG,
740
728
  options: {
741
729
  auth: false
742
730
  }
743
731
  },
744
732
  auth: {
745
- config: CONFIG_AUTH,
746
733
  options: {
747
734
  auth: true
748
735
  }
749
736
  })
750
737
  test 'forward' do |data|
751
- config = data[:config]
752
738
  options = data[:options]
739
+ config = options[:auth] ? config_auth : base_config
753
740
  @d = d = create_driver(config)
754
741
 
755
742
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -776,20 +763,18 @@ class ForwardInputTest < Test::Unit::TestCase
776
763
  end
777
764
 
778
765
  data(tcp: {
779
- config: CONFIG,
780
766
  options: {
781
767
  auth: false
782
768
  }
783
769
  },
784
770
  auth: {
785
- config: CONFIG_AUTH,
786
771
  options: {
787
772
  auth: true
788
773
  }
789
774
  })
790
775
  test 'packed_forward' do |data|
791
- config = data[:config]
792
776
  options = data[:options]
777
+ config = options[:auth] ? config_auth : base_config
793
778
  @d = d = create_driver(config)
794
779
 
795
780
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -817,22 +802,20 @@ class ForwardInputTest < Test::Unit::TestCase
817
802
 
818
803
  data(
819
804
  tcp: {
820
- config: CONFIG,
821
805
  options: {
822
806
  auth: false
823
807
  }
824
808
  },
825
809
  ### Auth is not supported with json
826
810
  # auth: {
827
- # config: CONFIG_AUTH,
828
811
  # options: {
829
812
  # auth: true
830
813
  # }
831
814
  # },
832
815
  )
833
816
  test 'message_json' do |data|
834
- config = data[:config]
835
817
  options = data[:options]
818
+ config = options[:auth] ? config_auth : base_config
836
819
  @d = d = create_driver(config)
837
820
 
838
821
  time_i = event_time("2011-01-02 13:14:15 UTC")
@@ -859,20 +842,18 @@ class ForwardInputTest < Test::Unit::TestCase
859
842
 
860
843
  sub_test_case 'not respond without required ack' do
861
844
  data(tcp: {
862
- config: CONFIG,
863
845
  options: {
864
846
  auth: false
865
847
  }
866
848
  },
867
849
  auth: {
868
- config: CONFIG_AUTH,
869
850
  options: {
870
851
  auth: true
871
852
  }
872
853
  })
873
854
  test 'message' do |data|
874
- config = data[:config]
875
855
  options = data[:options]
856
+ config = options[:auth] ? config_auth : base_config
876
857
  @d = d = create_driver(config)
877
858
 
878
859
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -893,20 +874,18 @@ class ForwardInputTest < Test::Unit::TestCase
893
874
  end
894
875
 
895
876
  data(tcp: {
896
- config: CONFIG,
897
877
  options: {
898
878
  auth: false
899
879
  }
900
880
  },
901
881
  auth: {
902
- config: CONFIG_AUTH,
903
882
  options: {
904
883
  auth: true
905
884
  }
906
885
  })
907
886
  test 'forward' do |data|
908
- config = data[:config]
909
887
  options = data[:options]
888
+ config = options[:auth] ? config_auth : base_config
910
889
  @d = d = create_driver(config)
911
890
 
912
891
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -929,20 +908,18 @@ class ForwardInputTest < Test::Unit::TestCase
929
908
  end
930
909
 
931
910
  data(tcp: {
932
- config: CONFIG,
933
911
  options: {
934
912
  auth: false
935
913
  }
936
914
  },
937
915
  auth: {
938
- config: CONFIG_AUTH,
939
916
  options: {
940
917
  auth: true
941
918
  }
942
919
  })
943
920
  test 'packed_forward' do |data|
944
- config = data[:config]
945
921
  options = data[:options]
922
+ config = options[:auth] ? config_auth : base_config
946
923
  @d = d = create_driver(config)
947
924
 
948
925
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -966,22 +943,21 @@ class ForwardInputTest < Test::Unit::TestCase
966
943
 
967
944
  data(
968
945
  tcp: {
969
- config: CONFIG,
970
946
  options: {
971
947
  auth: false
972
948
  }
973
949
  },
974
950
  ### Auth is not supported with json
975
951
  # auth: {
976
- # config: CONFIG_AUTH,
952
+ # config: config_auth,
977
953
  # options: {
978
954
  # auth: true
979
955
  # }
980
956
  # },
981
957
  )
982
958
  test 'message_json' do |data|
983
- config = data[:config]
984
959
  options = data[:options]
960
+ config = options[:auth] ? config_auth : base_config
985
961
  @d = d = create_driver(config)
986
962
 
987
963
  time_i = event_time("2011-01-02 13:14:15 UTC").to_i
@@ -1096,7 +1072,7 @@ class ForwardInputTest < Test::Unit::TestCase
1096
1072
  end
1097
1073
 
1098
1074
  def connect
1099
- TCPSocket.new('127.0.0.1', PORT)
1075
+ TCPSocket.new('127.0.0.1', @port)
1100
1076
  end
1101
1077
 
1102
1078
  # Data ordering is not assured:
@@ -1165,7 +1141,7 @@ class ForwardInputTest < Test::Unit::TestCase
1165
1141
  end
1166
1142
 
1167
1143
  def execute_test_with_source_hostname_key(*keys, &block)
1168
- conf = CONFIG.dup
1144
+ conf = base_config.dup
1169
1145
  if keys.include?(:hostname)
1170
1146
  conf << <<EOL
1171
1147
  source_hostname_key source_hostname