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

onClose callback for LogWatch #6876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

onClose callback for LogWatch #6876

wants to merge 1 commit into from

Conversation

Chr031
Copy link

@Chr031 Chr031 commented Feb 11, 2025

Description

Fixes #6880

This feature implements a listener on the closing event of the LogWatch class.
Currently, when a LogWatch is instantiated, and when the underlying stream is closed, the log processing stops and the underlying output stream received no more events without been inform that a dead end has been reach.
With the onClose action I added, when the stream processing ends, (with an error or not), the information can be forwarded and a post processing can be easily started.

Due to some timeouts, I was loosing the log stream and could not reconnect in a smooth way. I did not see any easy way to be informed of this event and thus decided to implement it.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@shawkins
Copy link
Contributor

For better tracking, and probably some discussion, this will need an issue created.

I did not see any easy way to be informed of this event and thus decided to implement it.

I think that is the case when you pass in an OutputStream.

If you instead just get the InputStream off of the LogWatch, you will see an exception or -1 when attempting to read past when it is done.

@Chr031
Copy link
Author

Chr031 commented Feb 12, 2025 via email

@shawkins
Copy link
Contributor

it implies the use for every LogWatch of a separated thread.

There is still another thread involved - see the usage of the SerialExecutor - it's from the client's thread pool so it scales better.

Ideally even when supplying what to write into, it could be non-blocking: #4154

This means also that you fall into blocking methods, and cannot easily scale if you want to follow many logs.

Yes, that is an issue unless you are using virtual threads.

The blocking nature of the InputStream is just a wrapper around the underlying non-blocking support - we just never came to a concensus on what to expose as a non-blocking api.

An old draft of some possible ideas that wouldn't bring in additional dependencies: #5119

Let me know if you also need some unit tests. I didn’t implement any.

Ideally there should be one, and please still open an issue - that will also need referenced in the changelog.

* this exception will be passed as parameter, null otherwise
* @param onCloseAction
*/
void onClose(Consumer<Throwable> onCloseAction);
Copy link
Contributor

@shawkins shawkins Feb 12, 2025

Choose a reason for hiding this comment

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

I would prefer

CompletionStage<Throwable> getDone()

And leave it up to the caller how to use that, rather than accepting / tracking a single consumer.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, why not this pattern.
I will still prefer the onClose name for the function.

CompletionStage<Throwable> onClose()
or
CompletionStage<Throwable> streamEnds()

could be acceptable from your point of view ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, the method name can be whatever makes the most sense to you.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@Chr031
Copy link
Author

Chr031 commented Feb 12, 2025

I just created an issue : #6880

@Chr031 Chr031 force-pushed the dev branch 2 times, most recently from b924512 to 2ffb5a1 Compare February 12, 2025 21:47
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
57.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@Chr031 Chr031 force-pushed the dev branch 2 times, most recently from 097fced to 5f9533a Compare February 20, 2025 19:56
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.

LogWatch interface doesn't give information on close stream event
2 participants