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

Reimplement LogStash::Numeric setting in Java #17127

Merged

Conversation

andsel
Copy link
Contributor

@andsel andsel commented Feb 20, 2025

Release notes

[rn:skip]

What does this PR do?

Reimplements LogStash::Setting::Numeric Ruby setting class into the org.logstash.settings.NumericSetting and exposes it through java_import as LogStash::Setting::NumericSetting.
Updates the rspec tests:

  • verifies java.lang.IllegalArgumentException instead of ArgumentError is thrown because the kind of exception thrown by Java code, during verification.

Why is it important/What is the impact to the user?

As a developer I want use Java classes to shape the configuration settings.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

How to test this PR locally

Update a numeric settings like pipeline.batch.delay to a value that's not the default, start Logstash and verify that the setting value is used, for example check with

curl -XGET 'localhost:9600/_node/pipelines?pretty'

Related issues

@andsel andsel self-assigned this Feb 20, 2025
@andsel andsel force-pushed the feature/numeric_setting_to_java_revisited branch from 540bc2a to 1cccfab Compare February 20, 2025 13:47
@andsel andsel changed the title Converted Numeric Ruby setting class to Java Reimplement LogStash::Numeric setting in Java Feb 26, 2025
@andsel andsel marked this pull request as ready for review February 26, 2025 08:15
}

@Override
public Number coerce(Object obj) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems the Ruby's version is handling nil obj values, don't we need to do the same here for null?

Copy link
Contributor Author

@andsel andsel Feb 27, 2025

Choose a reason for hiding this comment

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

From irb REPL on previous code I got:

> s.coerce(nil)
/Users/andrea/workspace/logstash_andsel/logstash-core/lib/logstash/settings.rb:430:in `coerce': Failed to coerce value to Numeric. Received  (NilClass) (ArgumentError)

so you are suggesting to add something

@Override
    public Number coerce(Object obj) {
      if (obj == null) {
        throw new IllegalArgumentException("Failed to coerce value to SettingNumeric. Received null");
      }
      ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, something like that, so we don't get a NPE (obj.toString()) instead of an IllegalArgumentException when the value is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by e82f590

Copy link

@andsel andsel requested a review from edmocosta February 27, 2025 16:30
Copy link

mergify bot commented Mar 5, 2025

This pull request does not have a backport label. Could you fix it @andsel? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • backport-8.x is the label to automatically backport to the 8.x branch.

Copy link

mergify bot commented Mar 5, 2025

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Mar 5, 2025
Copy link
Contributor

@edmocosta edmocosta left a comment

Choose a reason for hiding this comment

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

LGTM!

@andsel andsel merged commit 07a3c8e into elastic:main Mar 6, 2025
9 checks passed
mergify bot pushed a commit that referenced this pull request Mar 6, 2025
Reimplements `LogStash::Setting::Numeric` Ruby setting class into the `org.logstash.settings.NumericSetting` and exposes it through `java_import` as `LogStash::Setting::NumericSetting`.
Updates the rspec tests:
- verifies `java.lang.IllegalArgumentException` instead of `ArgumentError` is thrown because the kind of exception thrown by Java code, during verification.

(cherry picked from commit 07a3c8e)
andsel added a commit that referenced this pull request Mar 6, 2025
…#17273)

This is an automatic backport of pull request #17127 done by [Mergify](https://mergify.com).

----

* Reimplement LogStash::Numeric setting in Java (#17127)

Reimplements `LogStash::Setting::Numeric` Ruby setting class into the `org.logstash.settings.NumericSetting` and exposes it through `java_import` as `LogStash::Setting::NumericSetting`.
Updates the rspec tests:
- verifies `java.lang.IllegalArgumentException` instead of `ArgumentError` is thrown because the kind of exception thrown by Java code, during verification.

(cherry picked from commit 07a3c8e)

* Fixed reference of SettingNumeric class (on main modules were removed)

---------

Co-authored-by: Andrea Selva <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants