change to NewStreamParser to accept larger inputs from scanner #8892
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.
Description
Whilst creating an external processor plugin, I was utilising the shim to provide the reading from stdin and writing to stdout:
When running the processor plugin I was seeing that the processor was being terminated and restarted with the error message in telegraf's stderr:
However, when I moved the plugin away from using the shim for the processor's stdin and stdout management to that of what is in the example listed on https://github.com/influxdata/telegraf/tree/master/plugins/processors/execd which is using
parser := influx.NewStreamParser(os.Stdin)
in afor {
loop; I did not encounter the error.Looking at the code for the shim's processor it is using:
scanner := bufio.NewScanner(s.stdin)
This has a default buffer of 64k. Outputting the Err() on the scanner reported
bufio.scanner token too long
. I was hitting the max default buffer size of 64k for the Scanner.The reason for hitting this 64k limit is that I was taking the "string" (data_type:value) from a kinesis stream and sending it to the processor for manipulation. On occasions the data from kinesis was larger than the 64k; and the Scanner reported the token too long which propagated up to the processor process exiting and being restarted.
PR Change
Moved the processor's shim from the
bufio.NewScanner
to that of theinflux.NewStreamParser(os.Stdin)
from the example. Moving to that I had no issues with the processor exiting.I'm unsure if there's a reason for using the bufio.NewScanner in the shim vs the using the influx StreamParser.
I added a test to cover this larger than the 64k buffer. The test hangs on the old code that uses the scanner (I didn't into the test code to look into the why for the hang on the old code).