Skip to content

[fix][functions] Fix Java Function instance LogAppender missing logs - #17471

Merged
codelipenghui merged 1 commit into
apache:masterfrom
cbornet:fix-log-topic
Sep 8, 2022
Merged

codelipenghui merged 1 commit into
apache:masterfrom
cbornet:fix-log-topic

Conversation

@cbornet

@cbornet cbornet commented Sep 5, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #15392

Motivation

When using a log-topic in Functions, an appender is added to all loggers to send the logs with the Pulsar client.
To prevent sending logs from the framework, the LogAppender is added before the function processing (JavaInstance::handleMessage) and removed just after.
This is a problem because since #15188, the logs are sent asynchronously and sometimes we remove the appender before the log is processed by the LogAppender.
And this is the reason why we see flakyness in testJavaLoggingFunction because me miss some logs.
This is also a problem when using an async Function that returns CompletableFuture where the execution of the Function will be done async and probably when the appender is removed.
I had a look and the framework only sends error logs. It may even be interesting to get these logs to debug Functions.
So this change is about removing this dynamic add/delete of the appender (which probably also has some effect on perf) and add it once and for all.

Modifications

Remove calls to addLogTopicHandler and removeLogTopicHandler and call setupLogTopicAppender during the setup.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as testJavaLoggingFunction.

Does this pull request potentially affect one of the following parts:

no

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

Documentation

Check the box below or label this PR directly.

Need to update docs?

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    fix

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@cbornet cbornet changed the title Fix flaky testJavaLoggingFunction [fix][functions] Fix flaky testJavaLoggingFunction Sep 5, 2022
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Sep 5, 2022
@eolivelli

eolivelli commented Sep 5, 2022 •

Copy link
Copy Markdown
Contributor

@merlimat @codelipenghui @Technoboy- @cbornet @lhotari I think that it is safer to revert #15188 at least for Pulsar 2.11

I agree with this patch but we have to fix 2.11 as priority

@eolivelli eolivelli added type/bug The PR fixed a bug or issue reported a bug area/function release/blocker Indicate the PR or issue that should block the release until it gets resolved labels Sep 5, 2022
@eolivelli eolivelli added this to the 2.11.0 milestone Sep 5, 2022
@cbornet cbornet changed the title [fix][functions] Fix flaky testJavaLoggingFunction [fix][functions] Fix Java Function instance LogAppender missing logs Sep 5, 2022
The logs are sent asynchronously to the appender using AsyncLoggerContextSelector.
So there's a possibility that we remove the appender before we get in the LogAppender processing.
This change activates the LogAppender once and for all.
Fix apache#15392
@codelipenghui
codelipenghui merged commit 74ac221 into apache:master Sep 8, 2022
@cbornet
cbornet deleted the fix-log-topic branch September 8, 2022 08:58
@tisonkun

tisonkun commented Sep 8, 2022

Copy link
Copy Markdown
Member

Cool!

@merlimat

merlimat commented Jun 5, 2023

Copy link
Copy Markdown
Contributor

@cbornet I'm just realizing that the async-loggers PR was reverted. After this change, could #15188 be added again?

@cbornet

cbornet commented Jun 8, 2023

Copy link
Copy Markdown
Contributor Author

Yes, I think we can add it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/function cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs release/blocker Indicate the PR or issue that should block the release until it gets resolved type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: PulsarFunctionsJavaThreadTest.testJavaLoggingFunction

7 participants