Skip to content

Commit

Permalink
refactor log for event_api.tags.illegal (#16545)
Browse files Browse the repository at this point in the history
- add `obsoleted_version` and remove `deprecated_msg` from `deprecated_option` for consistent warning message

(cherry picked from commit 8cd0fa8)
  • Loading branch information
kaisecheng authored and logstashmachine committed Oct 11, 2024
1 parent a1f4633 commit ac79c07
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
15 changes: 6 additions & 9 deletions logstash-core/lib/logstash/patches/clamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,13 @@ 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]
obsoleted_version = opts[:obsoleted_version]

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
dmsg = "DEPRECATION WARNING: The flag #{option.switches} has been deprecated"
dmsg += obsoleted_version.nil? ? " and may be removed in a future release" : " and will be removed in version #{obsoleted_version}"
dmsg += new_flag.nil? ? ".": ", please use \"--#{new_flag}=#{new_value}\" instead."

LogStash::DeprecationMessage.instance << dmsg

if passthrough
LogStash::SETTINGS.set(option.attribute_name, value)
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class LogStash::Runner < Clamp::StrictCommand
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")
:obsoleted_version => "9"

# We configure the registry and load any plugin that can register hooks
# with logstash, this needs to be done before any operation.
Expand Down
2 changes: 0 additions & 2 deletions logstash-core/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ 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 is deprecated and will be removed in version 9.
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/spec/logstash/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
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"
DEPRECATED_MSG="The flag [\"--event_api.tags.illegal\"] has been 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)
Expand Down

0 comments on commit ac79c07

Please sign in to comment.