Skip to content

Commit fe5843f

Browse files
committed
fluentd command: fix plugin_dirs not to overwrite default value
This option is explained as "add plugin directory". However, since v1.16.0, the behavior has changed to overwrite the default value unintentionally. (PR: #4064, commit: 41678bf). We should revert it to the original behavior. Signed-off-by: Daijiro Fukuda <[email protected]>
1 parent 501ec93 commit fe5843f

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

lib/fluent/command/fluentd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747

4848
op.on('-p', '--plugin DIR', "add plugin directory") {|s|
49-
(cmd_opts[:plugin_dirs] ||= []) << s
49+
(cmd_opts[:plugin_dirs] ||= default_opts[:plugin_dirs]) << s
5050
}
5151

5252
op.on('-I PATH', "add library path") {|s|

test/command/test_fluentd.rb

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,14 @@ def eager_read(io)
128128

129129
# ATTENTION: This stops taking logs when all `pattern_list` match or timeout,
130130
# so `patterns_not_match` can test only logs up to that point.
131+
# You can pass a block to assert something after log matching.
131132
def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout: 20, env: {})
132133
matched = false
133134
matched_wrongly = false
134-
assert_error_msg = ""
135+
error_msg_match = ""
135136
stdio_buf = ""
137+
succeeded_block = true
138+
error_msg_block = ""
136139
begin
137140
execute_command(cmdline, @tmp_dir, env) do |pid, stdout|
138141
begin
@@ -163,6 +166,13 @@ def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout:
163166
end
164167
end
165168
end
169+
170+
begin
171+
yield if block_given?
172+
rescue => e
173+
succeeded_block = false
174+
error_msg_block = "failed block execution after matching: #{e}"
175+
end
166176
ensure
167177
if SUPERVISOR_PID_PATTERN =~ stdio_buf
168178
@supervisor_pid = $1.to_i
@@ -173,19 +183,19 @@ def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout:
173183
end
174184
end
175185
rescue Timeout::Error
176-
assert_error_msg = "execution timeout"
186+
error_msg_match = "execution timeout"
177187
# https://github.com/fluent/fluentd/issues/4095
178188
# On Windows, timeout without `@supervisor_pid` means that the test is invalid,
179189
# since the supervisor process will survive without being killed correctly.
180190
flunk("Invalid test: The pid of supervisor could not be taken, which is necessary on Windows.") if Fluent.windows? && @supervisor_pid.nil?
181191
rescue => e
182-
assert_error_msg = "unexpected error in launching fluentd: #{e.inspect}"
192+
error_msg_match = "unexpected error in launching fluentd: #{e.inspect}"
183193
else
184-
assert_error_msg = "log doesn't match" unless matched
194+
error_msg_match = "log doesn't match" unless matched
185195
end
186196

187197
if patterns_not_match.empty?
188-
assert_error_msg = build_message(assert_error_msg,
198+
error_msg_match = build_message(error_msg_match,
189199
"<?>\nwas expected to include:\n<?>",
190200
stdio_buf, pattern_list)
191201
else
@@ -197,16 +207,17 @@ def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout:
197207
lines.any?{|line| line.include?(ptn) }
198208
end
199209
if matched_wrongly
200-
assert_error_msg << "\n" unless assert_error_msg.empty?
201-
assert_error_msg << "pattern exists in logs wrongly: #{ptn}"
210+
error_msg_match << "\n" unless error_msg_match.empty?
211+
error_msg_match << "pattern exists in logs wrongly: #{ptn}"
202212
end
203213
end
204-
assert_error_msg = build_message(assert_error_msg,
214+
error_msg_match = build_message(error_msg_match,
205215
"<?>\nwas expected to include:\n<?>\nand not include:\n<?>",
206216
stdio_buf, pattern_list, patterns_not_match)
207217
end
208218

209-
assert matched && !matched_wrongly, assert_error_msg
219+
assert matched && !matched_wrongly, error_msg_match
220+
assert succeeded_block, error_msg_block if block_given?
210221
end
211222

212223
def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 20)
@@ -1288,4 +1299,40 @@ def multi_workers_ready?; true; end
12881299
"[debug]")
12891300
end
12901301
end
1302+
1303+
sub_test_case "plugin option" do
1304+
test "should be the default value when not specifying" do
1305+
conf_path = create_conf_file('test.conf', <<~CONF)
1306+
<source>
1307+
@type monitor_agent
1308+
</source>
1309+
CONF
1310+
assert File.exist?(conf_path)
1311+
cmdline = create_cmdline(conf_path)
1312+
1313+
assert_log_matches(cmdline, "fluentd worker is now running") do
1314+
response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
1315+
actual_conf = JSON.parse(response)
1316+
assert_equal Fluent::Supervisor.default_options[:plugin_dirs], actual_conf["plugin_dirs"]
1317+
end
1318+
end
1319+
1320+
data(short: "-p")
1321+
data(long: "--plugin")
1322+
test "can be added by specifying the option" do |option_name|
1323+
conf_path = create_conf_file('test.conf', <<~CONF)
1324+
<source>
1325+
@type monitor_agent
1326+
</source>
1327+
CONF
1328+
assert File.exist?(conf_path)
1329+
cmdline = create_cmdline(conf_path, option_name, @tmp_dir, option_name, @tmp_dir)
1330+
1331+
assert_log_matches(cmdline, "fluentd worker is now running") do
1332+
response = Net::HTTP.get(URI.parse("http://localhost:24220/api/config.json"))
1333+
actual_conf = JSON.parse(response)
1334+
assert_equal Fluent::Supervisor.default_options[:plugin_dirs] + [@tmp_dir, @tmp_dir], actual_conf["plugin_dirs"]
1335+
end
1336+
end
1337+
end
12911338
end

0 commit comments

Comments
 (0)