From c2c62fdce4d96c0dde2d26cb8e55c0bc37e53128 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:40:49 +0100 Subject: [PATCH] add deprecation log for `--event_api.tags.illegal` (#16507) (#16515) - 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 a4eddb8a2a79c7e1eb7696140795580427792cb1) Co-authored-by: kaisecheng <69120390+kaisecheng@users.noreply.github.com> --- logstash-core/lib/logstash/patches/clamp.rb | 10 +++++++- logstash-core/lib/logstash/runner.rb | 10 ++++---- logstash-core/locales/en.yml | 4 +++- logstash-core/spec/logstash/runner_spec.rb | 26 +++++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/logstash-core/lib/logstash/patches/clamp.rb b/logstash-core/lib/logstash/patches/clamp.rb index 149d2f02c46..ad690d776d5 100644 --- a/logstash-core/lib/logstash/patches/clamp.rb +++ b/logstash-core/lib/logstash/patches/clamp.rb @@ -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) diff --git a/logstash-core/lib/logstash/runner.rb b/logstash-core/lib/logstash/runner.rb index 876d3e1e173..489337da96c 100644 --- a/logstash-core/lib/logstash/runner.rb +++ b/logstash-core/lib/logstash/runner.rb @@ -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", @@ -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 diff --git a/logstash-core/locales/en.yml b/logstash-core/locales/en.yml index 92dcb38eebf..9985203efb8 100644 --- a/logstash-core/locales/en.yml +++ b/logstash-core/locales/en.yml @@ -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 diff --git a/logstash-core/spec/logstash/runner_spec.rb b/logstash-core/spec/logstash/runner_spec.rb index ffcb9ef9277..cb07fde6d51 100644 --- a/logstash-core/spec/logstash/runner_spec.rb +++ b/logstash-core/spec/logstash/runner_spec.rb @@ -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|