[fileconsumer] Generlize emit function #24036
Merged
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.
This is part of an effort to make
fileconsumer.Reader
more testable. I'd eventually like to move that struct into its own internal package. However, there is a dependency on theEmitFunc
which is part of thefileconsumer
package. Therefore, theEmitFunc
will need to move into a separate package fromfileconsumer
.Since this will be a breaking change (Go API only), I would like to take the opportunity to replace the emit function altogether with something more generic. The current
EmitFunc
includes aFileAttributes
struct, the purpose of which is to pass along attributes describing the file from which a log is read. TheFileAttributes
struct may in turn contain aHeaderAttributes
struct describing elements parsed from the header of a file.If the emit function instead passes along all these attributes as a
map[string]any
, theReader
struct will be simpler and more testable, and dependencies between packages will be simpler as well. This PR is a proposal to make this change.There are a few complicating factors here.
Reader
's. This in turn means that theFileAttributes
struct is encoded as well. However, only theHeaderAttributes
struct is included in this encoded representation. The idea here was that these attributes need to be attached to any log read from the file, even if we are resuming after a restart or upgrade. Conversely, the other fields (file name/path, etc) are omitted from the encoding because the file may have moved. Since this PR would encode these values, we need to be sure to overwrite them when we reconstruct theReader
. This is accomplished in the reader factory by resolving the fields after copying the previously known values. A new test verified that these fields are updated appropriately.Reader
from before this change, we need to handle this during decoding. This is handled in a single block of code which can be removed in a future version. I've tested this manually.file_input
operator used theFileAttributes
struct in a specific way, but this is made redundant by the approach described in 1.Benchmarks for this change show no notable impact: