Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor deprecation log event_api.tags.illegal #16545

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for the refactoring is, came with an idea to widely use obsoleted_version with other deprecation params (such as http.*). Change LGTM!

One thing I would like to clarify: merging against 8.x would make sense since event_api.tags.illegal will be removed from main (with this PR), how do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this PR to merge to main because the way of handling deprecation warning in clamp.rb is benefit for the future deprecation not limit to 8.x


# 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