Skip to content

Commit

Permalink
Ensure plugin config marked :deprecated logs to deprecation logger
Browse files Browse the repository at this point in the history
Previously when the `:deprecated` modifier was used in the plugin config DSL a
log message was sent at `:warn` level ONLY to the main logger. This commit updates
that message to be routed *both* to the deprecation logger as well as the main
logger. In 9.x this will *only* go to the deprecation logger.
  • Loading branch information
donoghuc committed Jan 6, 2025
1 parent c8095ca commit 9ff63b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions logstash-core/lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ def config_init(params)
if opts && opts[:deprecated]
extra = opts[:deprecated].is_a?(String) ? opts[:deprecated] : ""
extra.gsub!("%PLUGIN%", self.class.config_name)
# Log to main logger in addition to deprecation logger, in the 9.x series
# we will remove the main logger and only use the deprecation logger
self.logger.warn("You are using a deprecated config setting " +
"#{name.inspect} set in #{self.class.config_name}. " +
"Deprecated settings will continue to work, " +
"but are scheduled for removal from logstash " +
"in the future. #{extra} If you have any questions " +
"about this, please visit the #logstash channel " +
"on freenode irc.", :name => name, :plugin => self)
self.deprecation_logger.deprecated("You are using a deprecated config setting " +
"#{name.inspect} set in #{self.class.config_name}. " +
"Deprecated settings will continue to work, " +
Expand Down
17 changes: 12 additions & 5 deletions logstash-core/spec/logstash/config/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
context "when encountering a deprecated option" do
let(:password) { "sekret" }
let(:deprecation_logger) { double("DeprecationLogger").as_null_object }
let(:main_logger) { double("logger").as_null_object }
let(:plugin_class) do
Class.new(LogStash::Filters::Base) do
include LogStash::Config::Mixin
Expand All @@ -32,16 +33,22 @@
end
end

it "should not log the password" do
instance = plugin_class.new("old_opt" => "whut", "password" => password)
allow(instance).to receive(:deprecation_logger).and_return(deprecation_logger)

it "should send deprecation to both the main logger as well as the deprecation logger and not log the password" do
expect(LogStash::Logging::Logger).to receive(:new).with(anything).and_return(main_logger)
expect(main_logger).to receive(:warn).at_least(:once) do |arg1, arg2|
message = 'You are using a deprecated config setting "old_opt" set in test_deprecated. ' \
'Deprecated settings will continue to work, but are scheduled for removal from logstash in the future. ' \
'this is old school If you have any questions about this, please visit the #logstash channel on freenode irc.'
expect(arg1).to eq(message)
expect(arg2[:plugin].to_s).to include('"password"=><password>')
end
expect(deprecation_logger).to receive(:deprecated) do |message, _|
expect(message).to include("old_opt")
expect(message).to include("this is old school")
expect(message).not_to include(password)
end

instance = plugin_class.new("old_opt" => "whut", "password" => password)
allow(instance).to receive(:deprecation_logger).and_return(deprecation_logger)
instance.send(:config_init, instance.params)
end
end
Expand Down

0 comments on commit 9ff63b4

Please sign in to comment.