Skip to content

Commit 877dba7

Browse files
kaisechengmashhurs
authored andcommitted
add deprecation log for --event_api.tags.illegal (#16507)
- move `--event_api.tags.illegal` from option to deprecated_option - add deprecation log when the flag is explicitly used relates: #16356 Co-authored-by: Mashhur <99575341+mashhurs@users.noreply.github.com> (cherry picked from commit a4eddb8)
1 parent e854ac7 commit 877dba7

4 files changed

Lines changed: 44 additions & 6 deletions

File tree

logstash-core/lib/logstash/patches/clamp.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ def define_deprecated_writer_for(option, opts, &block)
7979
new_flag = opts[:new_flag]
8080
new_value = opts.fetch(:new_value, value)
8181
passthrough = opts.fetch(:passthrough, false)
82+
deprecated_msg = opts[:deprecated_msg]
8283

83-
LogStash::DeprecationMessage.instance << "DEPRECATION WARNING: The flag #{option.switches} has been deprecated, please use \"--#{new_flag}=#{new_value}\" instead."
84+
LogStash::DeprecationMessage.instance <<
85+
if new_flag
86+
"DEPRECATION WARNING: The flag #{option.switches} has been deprecated, please use \"--#{new_flag}=#{new_value}\" instead."
87+
elsif deprecated_msg
88+
deprecated_msg
89+
else
90+
"DEPRECATION WARNING: The flag #{option.switches} has been deprecated and may be removed in a future release."
91+
end
8492

8593
if passthrough
8694
LogStash::SETTINGS.set(option.attribute_name, value)

logstash-core/lib/logstash/runner.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ class LogStash::Runner < Clamp::StrictCommand
9292
:default => LogStash::SETTINGS.get_default("config.field_reference.escape_style"),
9393
:attribute_name => "config.field_reference.escape_style"
9494

95-
option ["--event_api.tags.illegal"], "STRING",
96-
I18n.t("logstash.runner.flag.event_api.tags.illegal"),
97-
:default => LogStash::SETTINGS.get_default("event_api.tags.illegal"),
98-
:attribute_name => "event_api.tags.illegal"
9995

10096
# Module settings
10197
option ["--modules"], "MODULES",
@@ -267,6 +263,12 @@ class LogStash::Runner < Clamp::StrictCommand
267263
I18n.t("logstash.runner.flag.http_port"),
268264
:new_flag => "api.http.port", :passthrough => true # use settings to disambiguate
269265

266+
deprecated_option ["--event_api.tags.illegal"], "STRING",
267+
I18n.t("logstash.runner.flag.event_api.tags.illegal"),
268+
:default => LogStash::SETTINGS.get_default("event_api.tags.illegal"),
269+
:attribute_name => "event_api.tags.illegal", :passthrough => true,
270+
:deprecated_msg => I18n.t("logstash.runner.tags-illegal-deprecated")
271+
270272
# We configure the registry and load any plugin that can register hooks
271273
# with logstash, this needs to be done before any operation.
272274
SYSTEM_SETTINGS = LogStash::SETTINGS.clone

logstash-core/locales/en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ en:
139139
configtest-flag-information: |-
140140
You may be interested in the '--configtest' flag which you can use to validate
141141
logstash's configuration before you choose to restart a running system.
142+
tags-illegal-deprecated: >-
143+
The flag '--event_api.tags.illegal' is deprecated and will be removed in version 9.
142144
tags-illegal-warning: >-
143145
Setting `event_api.tags.illegal` to `warn` allows illegal values in the reserved `tags` field, which may crash pipeline unexpectedly.
144-
This flag value is deprecated and may be removed in a future release.
146+
This flag is deprecated and will be removed in version 9.
145147
# YAML named reference to the logstash.runner.configuration
146148
# so we can later alias it from logstash.agent.configuration
147149
configuration: &runner_configuration

logstash-core/spec/logstash/runner_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,32 @@
380380
end
381381
end
382382

383+
context "event_api.tags.illegal" do
384+
let(:runner_deprecation_logger_stub) { double("DeprecationLogger(Runner)").as_null_object }
385+
let(:args) { ["--event_api.tags.illegal", "warn", "-e", pipeline_string] }
386+
before(:each) { allow(runner).to receive(:deprecation_logger).and_return(runner_deprecation_logger_stub) }
387+
DEPRECATED_MSG="The flag '--event_api.tags.illegal' is deprecated and will be removed in version 9"
388+
389+
it "gives deprecation message when setting to `warn`" do
390+
expect(runner_deprecation_logger_stub).to receive(:deprecated)
391+
.with(a_string_including "This flag is deprecated and will be removed in version 9")
392+
.with(a_string_including DEPRECATED_MSG)
393+
subject.run("bin/logstash", args)
394+
end
395+
396+
it "gives deprecation message when setting to `rename`" do
397+
expect(runner_deprecation_logger_stub).to receive(:deprecated)
398+
.with(a_string_including DEPRECATED_MSG)
399+
subject.run("bin/logstash", args)
400+
end
401+
402+
it "does not give deprecation message when unset" do
403+
expect(runner_deprecation_logger_stub).not_to receive(:deprecated)
404+
.with(a_string_including DEPRECATED_MSG)
405+
subject.run("bin/logstash", ["-e", pipeline_string])
406+
end
407+
end
408+
383409
context "when :pipeline_workers is not defined by the user" do
384410
it "should not pass the value to the pipeline" do
385411
expect(LogStash::Agent).to receive(:new) do |settings|

0 commit comments

Comments
 (0)