Skip to content

Commit 74d3f72

Browse files
committed
Allow users to configure initial buffer size
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 55ca3c5 commit 74d3f72

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

.chloggen/add-initial-buffer.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/stanza
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Allow users to configure initial buffer size
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37786]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

pkg/stanza/fileconsumer/config.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func NewConfig() *Config {
5959
MaxConcurrentFiles: defaultMaxConcurrentFiles,
6060
StartAt: "end",
6161
FingerprintSize: fingerprint.DefaultSize,
62+
InitialBufferSize: scanner.DefaultBufferSize,
6263
MaxLogSize: reader.DefaultMaxLogSize,
6364
Encoding: defaultEncoding,
6465
FlushPeriod: reader.DefaultFlushPeriod,
@@ -70,13 +71,15 @@ func NewConfig() *Config {
7071

7172
// Config is the configuration of a file input operator
7273
type Config struct {
73-
matcher.Criteria `mapstructure:",squash"`
74-
attrs.Resolver `mapstructure:",squash"`
75-
PollInterval time.Duration `mapstructure:"poll_interval,omitempty"`
76-
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty"`
77-
MaxBatches int `mapstructure:"max_batches,omitempty"`
78-
StartAt string `mapstructure:"start_at,omitempty"`
79-
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty"`
74+
matcher.Criteria `mapstructure:",squash"`
75+
attrs.Resolver `mapstructure:",squash"`
76+
PollInterval time.Duration `mapstructure:"poll_interval,omitempty"`
77+
MaxConcurrentFiles int `mapstructure:"max_concurrent_files,omitempty"`
78+
MaxBatches int `mapstructure:"max_batches,omitempty"`
79+
StartAt string `mapstructure:"start_at,omitempty"`
80+
FingerprintSize helper.ByteSize `mapstructure:"fingerprint_size,omitempty"`
81+
// InitialBufferSize represents the initial size of the read buffer for headers and body.
82+
InitialBufferSize helper.ByteSize `mapstructure:"initial_buffer_size,omitempty"`
8083
MaxLogSize helper.ByteSize `mapstructure:"max_log_size,omitempty"`
8184
Encoding string `mapstructure:"encoding,omitempty"`
8285
SplitConfig split.Config `mapstructure:"multiline,omitempty"`
@@ -154,7 +157,7 @@ func (c Config) Build(set component.TelemetrySettings, emit emit.Callback, opts
154157
TelemetrySettings: set,
155158
FromBeginning: startAtBeginning,
156159
FingerprintSize: int(c.FingerprintSize),
157-
InitialBufferSize: scanner.DefaultBufferSize,
160+
InitialBufferSize: int(c.InitialBufferSize),
158161
MaxLogSize: int(c.MaxLogSize),
159162
Encoding: enc,
160163
SplitFunc: splitFunc,

pkg/stanza/fileconsumer/internal/reader/reader.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func (r *Reader) readHeader(ctx context.Context) (doneReadingFile bool) {
167167
}
168168
r.headerReader = nil
169169
r.HeaderFinalized = true
170-
r.initialBufferSize = scanner.DefaultBufferSize
171170

172171
// Reset position in file to r.Offest after the header scanner might have moved it past a content token.
173172
if _, err := r.file.Seek(r.Offset, 0); err != nil {

receiver/otlpjsonfilereceiver/file_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func testdataConfigYamlAsMap() *Config {
206206
Encoding: "utf-8",
207207
StartAt: "end",
208208
FingerprintSize: 1000,
209+
InitialBufferSize: 16 * 1024,
209210
MaxLogSize: 1024 * 1024,
210211
MaxConcurrentFiles: 1024,
211212
FlushPeriod: 500 * time.Millisecond,

0 commit comments

Comments
 (0)