Skip to content

fix: support human-readable sizes for fluentd-buffer-limit log option#4856

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
shouhei:fix/fluentd-buffer-limit-human-readable
Apr 22, 2026
Merged

fix: support human-readable sizes for fluentd-buffer-limit log option#4856
AkihiroSuda merged 1 commit into
containerd:mainfrom
shouhei:fix/fluentd-buffer-limit-human-readable

Conversation

@shouhei
Copy link
Copy Markdown
Contributor

@shouhei shouhei commented Apr 18, 2026

Problem

fluentd-buffer-limit currently accepts only raw integer values in nerdctl.
In Docker-compatible workflows, users may specify human-readable values such as:

... --log-opt fluentd-buffer-limit=16M ...

Fix

Use github.com/docker/go-units to parse fluentd-buffer-limit.
This allows nerdctl to accept human-readable values such as 16M and 16MiB in addition to raw byte values.

@shouhei shouhei force-pushed the fix/fluentd-buffer-limit-human-readable branch 2 times, most recently from 15c6e5c to ff70efa Compare April 18, 2026 03:30
Copy link
Copy Markdown

@utafrali utafrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core change is correct and backward-compatible: swapping strconv.Atoi for units.RAMInBytes is the right approach and the existing test suite validates the happy path. The main issues are a silent int64-to-int narrowing cast and missing error-path test coverage after the parser change.

if err != nil {
return result, fmt.Errorf("error occurs %w,invalid buffer limit (%s)", err, config[fluentdBufferLimit])
}
bufferLimit = int(parsedBufferLimit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

units.RAMInBytes returns int64, but the result is silently narrowed to int. On 32-bit platforms int is 32 bits, so any value above ~2 GiB would wrap silently without error. First check whether fluent.Config.BufferLimit actually requires int or already accepts int64 (in which case you can drop the cast entirely). If the cast is unavoidable, add an explicit bounds check:

if parsedBufferLimit > int64(math.MaxInt) {
    return result, fmt.Errorf("invalid buffer limit: value %d overflows int", parsedBufferLimit)
}
bufferLimit = int(parsedBufferLimit)

Async: false,
AsyncReconnectInterval: 0,
SubSecondPrecision: false,
RequestAck: false}, false},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test only covers the happy path. The rejection behavior has changed from strconv.Atoi to units.RAMInBytes, so add at least one wantErr: true case with an invalid value (e.g. "1X" or "not-a-size") to confirm that malformed input still returns an error after the parser swap.

Comment thread docs/command-reference.md Outdated
- :whale: `--log-opt=fluentd-address=<ADDRESS>`: The address of the `fluentd` daemon, tcp(default) and unix sockets are supported..
- :whale: `--log-opt=fluentd-async=<true|false>`: Enable async mode for fluentd. The default value is false.
- :whale: `--log-opt=fluentd-buffer-limit=<LIMIT>`: The buffer limit for fluentd. If the buffer is full, the call to record logs will fail. The default is 8192. (<https://github.com/fluent/fluent-logger-golang/tree/master#bufferlimit>)
- :whale: `--log-opt=fluentd-buffer-limit=<LIMIT>`: The buffer limit for fluentd. If the buffer is full, the call to record logs will fail. The default is 1MiB. Accepts human-readable sizes (e.g., `1k`, `1m`, `1g`) or raw byte values. (<https://github.com/fluent/fluent-logger-golang/tree/master#bufferlimit>)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples 1k, 1m, 1g use RAMInBytes (binary units), so 1m = 1,048,576 bytes, not 1,000,000. This surprises users coming from SI conventions. Consider using IEC suffixes in the examples (1KiB, 1MiB, 1GiB) or adding a short note clarifying that the binary map is used, which is consistent with how Docker documents this option.

Signed-off-by: Shouhei <shouhei.yamaguchi.be@gmail.com>
@shouhei shouhei force-pushed the fix/fluentd-buffer-limit-human-readable branch from ff70efa to ee94580 Compare April 18, 2026 05:20
@shouhei
Copy link
Copy Markdown
Contributor Author

shouhei commented Apr 18, 2026

@utafrali Thanks for the review.

I updated the PR to follow your suggestions:

  • added the explicit overflow check before converting int64 to int
  • added an invalid-value test case for fluentd-buffer-limit
  • updated the documentation examples to use IEC suffixes

Copy link
Copy Markdown
Member

@haytok haytok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@haytok haytok added this to the v2.3.0 milestone Apr 19, 2026
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 5518c89 into containerd:main Apr 22, 2026
101 of 115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants