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

JSON Array splitting #77

Merged
merged 10 commits into from
Oct 16, 2024
Merged

JSON Array splitting #77

merged 10 commits into from
Oct 16, 2024

Conversation

51-code
Copy link

@51-code 51-code commented Oct 1, 2024

Adds a new splitting option: json_array. Takes HTTP requests with this kind of format:

[
{"a": 1},
{"b": 2}
]

and converts each of the JSON objects to their own syslog message and sends them forward.

Configuration had changes: payload.splitEnabled was changed to payload.splitType. Valid values are regex, json_array or none. none is the default.
payload.splitRegex was moved to payload.splitType.regex.pattern.

Regex splitting was already supported, but the design was not scalable. Therefore it was refactored as well to allow json_array to be implemented.

There was a problem with Jakarta's way of getting a JSON object as a string. It removes any whitespace from the String representation. This is okay as the content stays the same.

Tests most importantly include:

  • JsonPayloadTest for unit tests for the new functionality
  • JsonSplittingTest for end-to-end testing the functionality with actual HTTP-requests sent to the component

@51-code 51-code added assistance Extra attention, more information or help is needed enhancement New feature or request labels Oct 1, 2024
@51-code 51-code self-assigned this Oct 1, 2024
@51-code 51-code marked this pull request as ready for review October 2, 2024 10:02
@51-code 51-code requested a review from eemhu October 2, 2024 10:02
@51-code 51-code added review and removed assistance Extra attention, more information or help is needed labels Oct 2, 2024
@kortemik
Copy link
Member

kortemik commented Oct 8, 2024

@51-code please rebase

@kortemik kortemik requested a review from eemhu October 8, 2024 09:21
@51-code
Copy link
Author

51-code commented Oct 8, 2024

I'll be adding fixes to the config issues today.

@51-code
Copy link
Author

51-code commented Oct 8, 2024

Fixed the Config problems. Refactoring of all configuration in the component should be done, which is a bit out of scope for this PR. I'll create a new issue about that. Stuff left out for now is for example default configurations with a decorator object and reworking the config file / system property mix that it now has.

Now the end-to-end tests are still using System properties, so I left that possibility in the new ConversionFactory as well.

Delete PayloadConfig and include configuration in ConversionFactory that provides the correct object instead
Add secondary ctor to RegexConversion
Use Collections.singletonList in DefaultPayload, RegexConversion as final class
Add object equality test for RegexPayload
Move tests to the correct package
Move config tests from RegexPayloadTest to PayloadConfigTest and add tests for splitType
Refactor split() function in Payload
Refactor JsonPayload and RegexPayload to encapsulate Payload instead of String
Rename Payload's take() function to message()
Implement json_array splitting
Refactor Payload objects and regex splitting
Remove duplicate tests from RegexSplittingTest
Apply spotless
Move regex splitting tests to their own file, refactor the tests
Change config to allow splitting with json_array
Refactor regex splitting to a decorator
@51-code
Copy link
Author

51-code commented Oct 9, 2024

Rebased.

@51-code 51-code requested a review from eemhu October 9, 2024 07:42
@51-code 51-code requested a review from eemhu October 9, 2024 09:36
Copy link

@eemhu eemhu left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@eemhu eemhu requested a review from kortemik October 9, 2024 10:41
@51-code 51-code requested a review from kortemik October 10, 2024 12:04
@51-code 51-code requested a review from kortemik October 16, 2024 06:18
@51-code 51-code requested a review from kortemik October 16, 2024 09:42
@kortemik kortemik merged commit 0db7cd9 into teragrep:main Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants