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

Drop event when Encoder fails to encode it before it becomes a "poison" event #649

Merged
merged 10 commits into from
Sep 30, 2021

Conversation

brenuart
Copy link
Collaborator

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.

brenuart and others added 6 commits September 14, 2021 20:58
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.
@brenuart
Copy link
Collaborator Author

@brenuart brenuart linked an issue Sep 15, 2021 that may be closed by this pull request
…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 brenuart merged commit 94a836e into main Sep 30, 2021
@brenuart brenuart deleted the gh329-tcp-onEvent branch September 30, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LogstashTcpSocketAppender may loose events in its onEvent() method
2 participants