Conversation
🤖 GitHub commentsJust comment with:
|
|
This pull request does not have a backport label. Could you fix it @andsel? 🙏
|
…nything while the Ruby implementation did as a side effect, the test was updated to retrieve the value instead of relaying on set that return a value
ed8a6f2 to
4bacccb
Compare
💚 Build Succeeded
History
cc @andsel |
| context "when given '10mb'" do | ||
| it "returns 10485760" do | ||
| expect(subject.set("10mb")).to be == 10485760 | ||
| subject.set("10mb") |
There was a problem hiding this comment.
Note for reviewer
in Ruby implementation the set method also return the result of the last statement, so this make it implicitly to return the set value. In Java it return void, and to avoid changing all the Java Setting hierarchy to update the set method to return a value I've updated the test code. Also I don't like to return a value in a mutator method like set, a setter is a setter and shouldn't return a value.
There was a problem hiding this comment.
Pull request overview
This pull request migrates the Ruby Setting::Bytes class to Java as BytesSetting, completing the migration started in PR #18679 which moved the ByteValue utility class. The migration maintains backward compatibility by importing the Java class into the Ruby namespace, allowing existing Ruby code to use the new Java implementation transparently.
Changes:
- Implemented
BytesSettingclass in Java with support for string values with byte units and numeric values - Added comprehensive test coverage in
BytesSettingTest.javaincluding edge cases for BigInteger values - Enhanced
ByteValue.parse()to handle non-parseable numeric strings with appropriate error handling - Updated all references from
Setting::BytestoSetting::BytesSettingin Ruby code - Adapted Ruby specs to work with the new Java implementation
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
logstash-core/src/main/java/org/logstash/settings/BytesSetting.java |
New Java implementation of the bytes setting class with coercion and validation logic |
logstash-core/src/test/java/org/logstash/settings/BytesSettingTest.java |
Comprehensive test suite covering string/numeric defaults, validation, and edge cases |
logstash-core/src/main/java/org/logstash/util/ByteValue.java |
Added error handling for non-parseable numbers with try-catch block |
logstash-core/src/test/java/org/logstash/util/ByteValueTest.java |
Added test for non-parseable number handling |
logstash-core/lib/logstash/settings.rb |
Removed Ruby Bytes class and added java_import for BytesSetting |
logstash-core/lib/logstash/environment.rb |
Updated references from Setting::Bytes to Setting::BytesSetting |
logstash-core/spec/logstash/queue_factory_spec.rb |
Updated references from Setting::Bytes to Setting::BytesSetting |
logstash-core/spec/logstash/settings/bytes_spec.rb |
Adapted test to call value() after set() to work with Java implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public BytesSetting(String name, String defaultValue) { | ||
| super(name, coerceToNumber(defaultValue), true, BytesSetting::isValid); | ||
| } | ||
|
|
||
| public BytesSetting(String name, Number defaultValue) { | ||
| super(name, defaultValue, true, BytesSetting::isValid); | ||
| } | ||
|
|
||
| // Constructor for testing with strict parameter | ||
| public BytesSetting(String name, String defaultValue, boolean strict) { | ||
| super(name, coerceToNumber(defaultValue), strict, BytesSetting::isValid); |
There was a problem hiding this comment.
The constructors at lines 31-32 and 40-41 pre-coerce the defaultValue by calling coerceToNumber(defaultValue) before passing it to super(). However, the parent Coercible class will call coerce() again on this value when strict is true (see Coercible.java line 31). This results in unnecessary double-coercion and is inconsistent with the pattern used by other settings like IntegerSetting and NumericSetting, which pass the raw value to super() and let the parent handle coercion. Consider changing these constructors to pass the raw String or Number value directly to super(), similar to how IntegerSetting is implemented.
There was a problem hiding this comment.
This is partially true because this class extends Coercible<Number> if we pass the defaultValue straight to the super constructor we need to have common root between Number and String which is Object, and it's too loose. This class can accept String and Number and coerce those.
When coerce converts the string to Number and that's passed to the super constructor, in case strict is true the second coercion is just a passthrough because the input is already a Number.
| assertThat(thrownException.getMessage(), containsString("Unknown bytes value '100xyz'")); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Added this test case because wasn't covered before.
| when ::Numeric | ||
| value | ||
| when ::String | ||
| LogStash::Util::ByteValue.parse(value) |
There was a problem hiding this comment.
I think this was the only place where we used require "logstash/util/byte_value" in this file but it is loaded here and not anywhere else (needed in persisted_queue_config_validator.rb). Could potentially move the require there, but its probably not that big of a deal. Up to you!
Release notes
[rn:skip]
What does this PR do?
Moves the Ruby setting class
Bytessetting to Java. It covers the test in unit test while keeping and adapting the originalbytes_spec.rbtest suite to prove it still works on Ruby code.Why is it important/What is the impact to the user?
N/A
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
How to test this PR locally
To test locally change the default value of a setting that uses it (for example:
queue.page_capacity), start Logstash and verify the change is reflected to the filesystem:Update
logstash.ymlto configure a different path for PQ:Run Logstas a simple pipeline:
bin/logstash -e "input{generator {message => 'Hello world'}} output{sink{}}"Verify
/tmp/logstash/data/queue/maincontains PQ page files of the desired size.Related issues