Skip to content

Commit

Permalink
feat: return an error when using small flush bytes with compression e…
Browse files Browse the repository at this point in the history
…nabled (#111)

* feat: return an error when using small flush bytes with compression enabled

When compression is enabled the gzip writer will buffer data internally
which will cause the unerlying buffer to grow from 0 to n once compression
happens and compressed data are flushed.
Because of this, small flush bytes values are ignored and will never be hit.
The PR returns an error when using a small flush bytes value with compression
enabled.

* refactor: lower minimum to 16kb and update error message
  • Loading branch information
kruskall authored Feb 5, 2024
1 parent d06832b commit cfb8144
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func New(client *elasticsearch.Client, cfg Config) (*Appender, error) {
}
}

minFlushBytes := 16 * 1024 // 16kb
if cfg.CompressionLevel != 0 && cfg.FlushBytes < minFlushBytes {
return nil, fmt.Errorf(
"flush bytes config value (%d) is too small and will be ignored with compression enabled. Use at least %d",
cfg.FlushBytes, minFlushBytes,
)
}

ms, err := newMetrics(cfg)
if err != nil {
return nil, err
Expand Down

0 comments on commit cfb8144

Please sign in to comment.