diff --git a/.chloggen/stanza-reader-encoding.yaml b/.chloggen/stanza-reader-encoding.yaml new file mode 100644 index 000000000000..369c6a9784e4 --- /dev/null +++ b/.chloggen/stanza-reader-encoding.yaml @@ -0,0 +1,12 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/stanza + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "`readerFactory` and `Reader` use `helper.Encoding` directly, no longer depends on `helper.Splitter`" + +# One or more tracking issues related to the change +issues: [14593] + diff --git a/pkg/stanza/fileconsumer/config.go b/pkg/stanza/fileconsumer/config.go index cfe5bdad5039..f26013c9046b 100644 --- a/pkg/stanza/fileconsumer/config.go +++ b/pkg/stanza/fileconsumer/config.go @@ -128,6 +128,7 @@ func (c Config) Build(logger *zap.SugaredLogger, emit EmitFunc) (*Manager, error }, fromBeginning: startAtBeginning, splitterConfig: c.Splitter, + encodingConfig: c.Splitter.EncodingConfig, }, finder: c.Finder, roller: newRoller(), diff --git a/pkg/stanza/fileconsumer/reader.go b/pkg/stanza/fileconsumer/reader.go index 58fa8d904ad1..5a8f85037ace 100644 --- a/pkg/stanza/fileconsumer/reader.go +++ b/pkg/stanza/fileconsumer/reader.go @@ -35,6 +35,7 @@ type Reader struct { *zap.SugaredLogger `json:"-"` // json tag excludes embedded fields from storage *readerConfig splitter *helper.Splitter + encoding helper.Encoding Fingerprint *Fingerprint Offset int64 @@ -78,7 +79,7 @@ func (r *Reader) ReadToEnd(ctx context.Context) { break } - token, err := r.splitter.Encoding.Decode(scanner.Bytes()) + token, err := r.encoding.Decode(scanner.Bytes()) if err != nil { r.Errorw("decode: %w", zap.Error(err)) } else { diff --git a/pkg/stanza/fileconsumer/reader_factory.go b/pkg/stanza/fileconsumer/reader_factory.go index 7d48248df9a1..8b44f1552cdf 100644 --- a/pkg/stanza/fileconsumer/reader_factory.go +++ b/pkg/stanza/fileconsumer/reader_factory.go @@ -27,6 +27,7 @@ type readerFactory struct { readerConfig *readerConfig fromBeginning bool splitterConfig helper.SplitterConfig + encodingConfig helper.EncodingConfig } func (f *readerFactory) newReader(file *os.File, fp *Fingerprint) (*Reader, error) { @@ -101,6 +102,12 @@ func (b *readerBuilder) build() (r *Reader, err error) { } } + enc, err := b.encodingConfig.Build() + if err != nil { + return + } + r.encoding = enc + if b.file != nil { r.file = b.file r.SugaredLogger = b.SugaredLogger.With("path", b.file.Name())