Skip to content

Commit

Permalink
Avoid to access Java DeprecatedAlias value other than Ruby's one (#16506
Browse files Browse the repository at this point in the history
)

Update Settings to_hash method to also skip Java DeprecatedAlias and not just the Ruby one.
With PR #15679 was introduced org.logstash.settings.DeprecatedAlias which mirrors the behaviour of Ruby class Setting::DeprecatedAlias. The equality check at Logstash::Settings, as descibed in #16505 (comment), is implemented comparing the maps.
The conversion of Settings to the corresponding maps filtered out the Ruby implementation of DeprecatedAlias but not the Java one.
This PR adds also the Java one to the list of filter.
  • Loading branch information
andsel authored Oct 4, 2024
1 parent 5aabeda commit 5d4825f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def set_value(setting_name, value, graceful = false)
def to_hash
hash = {}
@settings.each do |name, setting|
next if setting.kind_of? Setting::DeprecatedAlias
next if (setting.kind_of? Setting::DeprecatedAlias) || (setting.kind_of? Java::org.logstash.settings.DeprecatedAlias)
hash[name] = setting.value
end
hash
Expand Down
22 changes: 22 additions & 0 deletions logstash-core/spec/logstash/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@
end
end

describe "#to_hash" do
let(:java_deprecated_alias) { LogStash::Setting::Boolean.new("java.actual", true).with_deprecated_alias("java.deprecated") }
let(:ruby_deprecated_alias) { LogStash::Setting::PortRange.new("ruby.actual", 9600..9700).with_deprecated_alias("ruby.deprecated") }
let(:non_deprecated) { LogStash::Setting::Boolean.new("plain_setting", false) }

before :each do
subject.register(java_deprecated_alias)
subject.register(ruby_deprecated_alias)
subject.register(non_deprecated)
end

it "filter deprecated alias settings" do
generated_settings_hash = subject.to_hash

expect(generated_settings_hash).not_to have_key("java.deprecated")
expect(generated_settings_hash).not_to have_key("ruby.deprecated")
expect(generated_settings_hash).to have_key("java.actual")
expect(generated_settings_hash).to have_key("ruby.actual")
expect(generated_settings_hash).to have_key("plain_setting")
end
end

describe "#get_subset" do
let(:numeric_setting_1) { LogStash::Setting.new("num.1", Numeric, 1) }
let(:numeric_setting_2) { LogStash::Setting.new("num.2", Numeric, 2) }
Expand Down

0 comments on commit 5d4825f

Please sign in to comment.