-
Notifications
You must be signed in to change notification settings - Fork 407
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
Drop event when Encoder fails to encode it before it becomes a "poison" event #649
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Motivations: (1) For the pooling to be efficient, the feature `USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING` must be disabled when creating JsonGenerator. If not, JsonGenerator creates additional buffers and re-use them per-thread. This pattern is not applicable in our case: there is no relationship between the JsonGenerator to use and the current thread. Pooling Jsongenerator instances and the creation/configuration of these instances (disabling the feature) are therefore related and should ideally be implemented close together, in the same class. (2) Pooling is required only because CompositeJsonFormatter uses Jackson under the cover (JsonGenerator must be given an OutputStream when created). The pooling logic should therefore be isolated and hidden inside the CompositeJsonFormatter itself and considered an implementation detail. This would also lead to a cleaner interface with a single `write(Event event, OutputStream out)` method. This method can be used to write an event to whatever output stream without having to care about pooling at all... (3) The current implementation creates a ReusableByteBuffer and connects the JsonGenerator to it at creation time. They are both pooled at the same time. Content is first generated in the byte buffer before it can be copied in the output stream passed as argument to the write method. This intermediate buffer somehow limits the streaming capability of the implementation. This commit now connects the JsonGenerator to a "DisconnectedOutputStream" when it is created. When the `write(event, out)` method is called, the output stream of the JsonGenerator is connected to the one passed as argument before the generator is invoked. Content produced by the generator is therefore written directly in the target output stream without requiring an intermediate buffer. It is now up to the caller to decide if it needs an intermediate buffer or not... Pooling and buffering are two separate concerns that are now handled separately. (4) The pooling logic is now handled by the `ObjectPool` class and is reused by both the ReusableByteBufferPool and the CompositeJsonFormatter.
… used by StreamingEncoder Deciding if an intermediate buffer is required or not in the constructor was not a good idea: the encoder is not yet known at this point (still null).
…n" event Wrap calls to `Encoder#write(..)` methods and drop the event if the encoder failed to encode it instead of retrying. Close the connection to remote when an IOException or RuntimeException is received while writing in the connection output stream.
@philsttr Could you please have a look at this commented section: https://github.com/logstash/logstash-logback-encoder/blob/gh329-tcp-onEvent/src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java#L547-L556 ? |
philsttr
reviewed
Sep 24, 2021
src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java
Outdated
Show resolved
Hide resolved
src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java
Outdated
Show resolved
Hide resolved
src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java
Outdated
Show resolved
Hide resolved
src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java
Show resolved
Hide resolved
…the status The default "OnConsoleStatusListener" already appends the cause's message when printing tth status on the console. Addining it in the original message will cause duplicates on the console. Those not relying on the "OnConsoleStatusLisener" should simply retrieve additional information from the status throwable if any (what they probaby already do for ErrorStatus anyway...)
brenuart
force-pushed
the
gh329-tcp-onEvent
branch
from
September 29, 2021 14:00
3c52680
to
cecbad7
Compare
philsttr
approved these changes
Sep 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: #329
Wrap calls to
Encoder#write(..)
methods and drop the event if the encoder failed to encode it instead of retrying.Close the connection to remote when an IOException or RuntimeException is received while writing in the connection output stream.