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

[pkg/stanza] readerFactory and Reader use helper.Encoding directly #14724

Merged
12 changes: 12 additions & 0 deletions .chloggen/stanza-reader-encoding.yaml
Original file line number Diff line number Diff line change
@@ -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]

1 change: 1 addition & 0 deletions pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion pkg/stanza/fileconsumer/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/stanza/fileconsumer/reader_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand Down