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
Fix default codec and buffer handling in Java stdout output #10673
Conversation
@@ -20,7 +20,7 @@ | |||
public class Stdout implements Output { | |||
|
|||
public static final PluginConfigSpec<Codec> CODEC_CONFIG = | |||
PluginConfigSpec.codecSetting("codec", "java-line"); | |||
PluginConfigSpec.codecSetting("codec", "java_line"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there some test that could be written to fail without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codec name is resolved at runtime so a test for this would require Logstash to be running. I've been thinking about how to set up integration tests for Java tests for Java plugins and other Java code, but I haven't come up with anything simple, yet.
@@ -57,7 +57,7 @@ public void output(final Collection<Event> events) { | |||
do { | |||
encodeCompleted = codec.encode(e, encodeBuffer); | |||
outputStream.write(encodeBuffer.array(), encodeBuffer.position(), encodeBuffer.limit()); | |||
encodeBuffer.flip(); | |||
encodeBuffer.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there a reason why flip was used before that doesn't make sense any more? I think I'm missing some context here about what is the issue being solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a mistaken use of the Buffer
API and not noticed earlier because the default buffer size accommodates most events encountered in testing. The flip
method "flips" a buffer from write mode to read mode. In the line above, the buffer has already been read in the outputStream.write
call so it needs to be flipped back from read mode to write mode. The compact
and clear
methods do this. Because the buffer is always read in its entirety, the more efficient clear
method can be used here instead of compact
.
This behavior can be easily verified in a unit test, so I added one for it.
…for events whose encodings do not fit into the buffer.
f9a6707
to
470054c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks, @jsvd! |
…for events whose encodings do not fit into the buffer. Fixes #10673
…for events whose encodings do not fit into the buffer. Fixes #10673
…for events whose encodings do not fit into the buffer. Fixes #10673
Correctly sets the default codec to
java_line
. Fixes buffer handling for events whose encodings do not fit into the buffer.