Skip to content

Implement advanced java exception handling using liblognorm error callback#18

Open
Tiihott wants to merge 19 commits into
teragrep:mainfrom
Tiihott:jna_issue_16_fix
Open

Implement advanced java exception handling using liblognorm error callback#18
Tiihott wants to merge 19 commits into
teragrep:mainfrom
Tiihott:jna_issue_16_fix

Conversation

@Tiihott
Copy link
Copy Markdown
Contributor

@Tiihott Tiihott commented Jan 28, 2025

Includes:

Also includes commits from PR #14. Rebase may be needed in this PR after they have been merged to main.
New commits are cf2b6e6 and later.

@Tiihott Tiihott requested a review from 51-code January 28, 2025 11:23
@Tiihott Tiihott self-assigned this Jan 28, 2025
Copy link
Copy Markdown

@51-code 51-code left a comment

Choose a reason for hiding this comment

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

Left some comments about tests.

Comment thread src/test/java/com/teragrep/rsm_01/LognormFactoryTest.java Outdated
Comment thread src/test/java/com/teragrep/rsm_01/LognormFactoryTest.java Outdated
@Tiihott Tiihott requested a review from 51-code January 29, 2025 08:09
Copy link
Copy Markdown

@51-code 51-code left a comment

Choose a reason for hiding this comment

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

LGTM

@Tiihott
Copy link
Copy Markdown
Contributor Author

Tiihott commented Jan 29, 2025

Noticed an error in liblognorm documentations on how the pure json format should be constructed.
Remade json sample rulebases with the proper format on commit 23d2d2c

@Tiihott Tiihott requested a review from 51-code January 29, 2025 13:35
Copy link
Copy Markdown

@51-code 51-code left a comment

Choose a reason for hiding this comment

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

New changes look good.

@Tiihott
Copy link
Copy Markdown
Contributor Author

Tiihott commented Feb 17, 2025

Rebased to main

@Tiihott
Copy link
Copy Markdown
Contributor Author

Tiihott commented Feb 17, 2025

Added exception test for partially invalid rulebase.

@Tiihott
Copy link
Copy Markdown
Contributor Author

Tiihott commented Feb 21, 2025

Rebased to main


@Override
public void invoke(Pointer cookie, String msg, int length) {
LOGGER.debug("liblognorm: {}", msg);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use "<{}>", msg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in commit 9e0e25d

@Override
public void invoke(Pointer cookie, String msg, int length) {
errors.add(msg);
LOGGER.error("liblognorm error: {}", msg);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use "<{}>", msg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in commit 9e0e25d

* Method for throwing any received liblognorm error messages as java exception.
*/
public void throwOccurredErrors() {
if (!errors.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should thrown errors be cleared or are they always so fatal that the object instance is invalid after some occured?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The rulebase loading method for liblognorm will not return error codes when the rulebase has errors in it, instead it will generate error messages and return 0 indicating that the loading of the rulebase was successful.
By implementing the check for error messages those rulebase errors can be caught as java exceptions.

In my opinion the errors should be handled using fail fast, making the object instance invalid if they occur.

Copy link
Copy Markdown
Contributor Author

@Tiihott Tiihott Feb 28, 2025

Choose a reason for hiding this comment

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

Here is an example of how the errors can completely break the rulebase while no error codes are returned by liblognorm during normalization.

Message to normalize:

Amount: 1234

Partially invalid rulebase with a typo on last line:

version=2
rule=:%all:rest%
ruletag:Amount: %N:number%

Normalization result with the invalid rulebase is:

{ "all": "Amount: 1234" }

But with a valid rulebase:

version=2
rule=:%all:rest%
rule=tag:Amount: %N:number%

The normalization result is:

{ "N": "1234", "event.tags": [ "tag" ] }

The normalization results are completely different for the same message.

@Tiihott Tiihott requested a review from kortemik February 24, 2025 09:50
@ronja-ui ronja-ui removed the review label Apr 7, 2025
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.

Implement advanced java exception handling for liblognorm ln_loadSamples() method

4 participants