Skip to content

Commit

Permalink
add deprecation log for --event_api.tags.illegal (#16507) (#16515)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
(cherry picked from commit a4eddb8)

Co-authored-by: kaisecheng <[email protected]>
  • Loading branch information
github-actions[bot] and kaisecheng authored Oct 8, 2024
1 parent e854ac7 commit c2c62fd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
10 changes: 9 additions & 1 deletion logstash-core/lib/logstash/patches/clamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ def define_deprecated_writer_for(option, opts, &block)
new_flag = opts[:new_flag]
new_value = opts.fetch(:new_value, value)
passthrough = opts.fetch(:passthrough, false)
deprecated_msg = opts[:deprecated_msg]

LogStash::DeprecationMessage.instance << "DEPRECATION WARNING: The flag #{option.switches} has been deprecated, please use \"--#{new_flag}=#{new_value}\" instead."
LogStash::DeprecationMessage.instance <<
if new_flag
"DEPRECATION WARNING: The flag #{option.switches} has been deprecated, please use \"--#{new_flag}=#{new_value}\" instead."
elsif deprecated_msg
deprecated_msg
else
"DEPRECATION WARNING: The flag #{option.switches} has been deprecated and may be removed in a future release."
end

if passthrough
LogStash::SETTINGS.set(option.attribute_name, value)
Expand Down
10 changes: 6 additions & 4 deletions logstash-core/lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class LogStash::Runner < Clamp::StrictCommand
:default => LogStash::SETTINGS.get_default("config.field_reference.escape_style"),
:attribute_name => "config.field_reference.escape_style"

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

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

deprecated_option ["--event_api.tags.illegal"], "STRING",
I18n.t("logstash.runner.flag.event_api.tags.illegal"),
:default => LogStash::SETTINGS.get_default("event_api.tags.illegal"),
:attribute_name => "event_api.tags.illegal", :passthrough => true,
:deprecated_msg => I18n.t("logstash.runner.tags-illegal-deprecated")

# We configure the registry and load any plugin that can register hooks
# with logstash, this needs to be done before any operation.
SYSTEM_SETTINGS = LogStash::SETTINGS.clone
Expand Down
4 changes: 3 additions & 1 deletion logstash-core/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ en:
configtest-flag-information: |-
You may be interested in the '--configtest' flag which you can use to validate
logstash's configuration before you choose to restart a running system.
tags-illegal-deprecated: >-
The flag '--event_api.tags.illegal' is deprecated and will be removed in version 9.
tags-illegal-warning: >-
Setting `event_api.tags.illegal` to `warn` allows illegal values in the reserved `tags` field, which may crash pipeline unexpectedly.
This flag value is deprecated and may be removed in a future release.
This flag is deprecated and will be removed in version 9.
# YAML named reference to the logstash.runner.configuration
# so we can later alias it from logstash.agent.configuration
configuration: &runner_configuration
Expand Down
26 changes: 26 additions & 0 deletions logstash-core/spec/logstash/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,32 @@
end
end

context "event_api.tags.illegal" do
let(:runner_deprecation_logger_stub) { double("DeprecationLogger(Runner)").as_null_object }
let(:args) { ["--event_api.tags.illegal", "warn", "-e", pipeline_string] }
before(:each) { allow(runner).to receive(:deprecation_logger).and_return(runner_deprecation_logger_stub) }
DEPRECATED_MSG="The flag '--event_api.tags.illegal' is deprecated and will be removed in version 9"

it "gives deprecation message when setting to `warn`" do
expect(runner_deprecation_logger_stub).to receive(:deprecated)
.with(a_string_including "This flag is deprecated and will be removed in version 9")
.with(a_string_including DEPRECATED_MSG)
subject.run("bin/logstash", args)
end

it "gives deprecation message when setting to `rename`" do
expect(runner_deprecation_logger_stub).to receive(:deprecated)
.with(a_string_including DEPRECATED_MSG)
subject.run("bin/logstash", args)
end

it "does not give deprecation message when unset" do
expect(runner_deprecation_logger_stub).not_to receive(:deprecated)
.with(a_string_including DEPRECATED_MSG)
subject.run("bin/logstash", ["-e", pipeline_string])
end
end

context "when :pipeline_workers is not defined by the user" do
it "should not pass the value to the pipeline" do
expect(LogStash::Agent).to receive(:new) do |settings|
Expand Down

0 comments on commit c2c62fd

Please sign in to comment.