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

Fix: IllegalArgument Exception in String converter #3172

Merged
merged 3 commits into from
Aug 21, 2023

Conversation

asifsmohammed
Copy link
Collaborator

@asifsmohammed asifsmohammed commented Aug 15, 2023

Description

Fix IllegalArgumentException and return object.toString

Issues Resolved

Resolves #3135

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

if (Objects.nonNull(source)) {
return source.toString();
} else {
return "";
Copy link
Member

Choose a reason for hiding this comment

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

In the case of null, we can probably handle this in the ConvertEntryTypeProcessor class. Any null value can be converted to null for the target.

Also, it should not be an empty string. It should be null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can return null string in case of null value instead of empty string. convert method is also used in translate processor.

throw new IllegalArgumentException("Unsupported type conversion");
LOG.error(EVENT, "Unable to convert {} to String", source);
if (Objects.nonNull(source)) {
return source.toString();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is really a good behavior. It could result in strange output. Say a list is provided. The user will get a string that looks like ListString@89879 or something like that.

I think this should continue to throw the exception.

We can handle the exception in the ConvertEntryTypeProcessor class to make it consistent across all types.

Perhaps by dropping the data?

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

I think the solution to this issue should be done entirely within ConvertEntryTypeProcessor. Let's continue to have the TypeConverter class throw and expect non-null.

So change ConvertEntryTypeProcessor to:

  1. Handle null conversions since the result is always null.
  2. Catch exceptions and handle these.

One item 2, the solution isn't completely clear. It should definitely log the error. But, what about the data? Does it drop the whole event or just the field? Or leave unconverted?

I tend to think we should add a user configuration to let the user decide how to handle. The most appropriate default to me seems to be to drop the data. Otherwise, we are sending garbage downstream.

Signed-off-by: Asif Sohail Mohammed <[email protected]>
@asifsmohammed
Copy link
Collaborator Author

I added tags_on_failure option which will add tags and log the failure. This change would not alter the current behavior. The key would be deleted first and then the if conversion works the key with new value will be added.

@@ -25,6 +27,9 @@ public String convert(Object source) throws IllegalArgumentException {
if (source instanceof String) {
return (String)source;
}
if (Objects.isNull(source)) {
return "null";
Copy link
Member

Choose a reason for hiding this comment

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

I think we can return null, not a string named "null".

Signed-off-by: Asif Sohail Mohammed <[email protected]>
Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for these improvements!

@dlvenable dlvenable merged commit 5a02050 into opensearch-project:main Aug 21, 2023
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Processor threads shutting down due to IllegalArgumentException thrown by StringConverter
3 participants