Skip to content

config: parse a fractional number before a size or time unit - #5625

Merged
Watson1978 merged 2 commits into
fluent:masterfrom
lbarrosby:config-fractional-unit-values
Nov 19, 2026
Merged

Watson1978 merged 2 commits into
fluent:masterfrom
lbarrosby:config-fractional-unit-values

Conversation

@lbarrosby

@lbarrosby lbarrosby commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
None (found while reading lib/fluent/config/types.rb; no existing issue or PR about it).

What this PR does / why we need it:
Config.size_value and Config.time_value look for the unit with unanchored regexps such as /([0-9]+)s/. With a fractional value, only the digits right before the unit are captured, so the integer part is dropped without any warning:

$ bundle exec ruby -Ilib -e 'require "fluent/config/types"; p Fluent::Config.time_value("0.5s"), Fluent::Config.time_value("1.5m"), Fluent::Config.size_value("1.5k")'
5
300
5120

flush_interval 0.5s gives a 5 second flush interval, retry_wait 1.5m waits 5 minutes, chunk_limit_size 1.5m gives 5 MB. A unitless value such as 0.5 already parses as 0.5 seconds, so this mostly bites people who add the unit.

This accepts an optional decimal part before the unit (/([0-9]+(?:\.[0-9]+)?)s/, and the same for the other units). The unit is applied with Rational, so a whole result is an exact Integer (1.1h -> 3960) and any other result is a Float. Integer values with a unit suffix still produce the same integer result, so 10s, 10sec, 2m, 4G and friends are unchanged. Sizes are truncated to an Integer (1.5k -> 1536), as the size type is a byte count.

Tests: new data in the normal case tests of Config.size_value (1.5k, 0.5m, 2.5G) and Config.time_value (0.5s, 1.5m, 0.25h, 1.5d, 1.1h, 0.7d), checked with and without strict. They fail on master and pass here:

$ bundle exec ruby -Ilib -Itest test/config/test_types.rb
181 tests, 212 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications

test/config/test_configurable.rb, test_configure_proxy.rb, test_system_config.rb, test/plugin/test_buffer.rb and test_output_as_buffered_retries.rb pass too. test/config/test_config_parser.rb, test_dsl.rb and test/test_config.rb have the same failures with and without this change on my machine (include paths relative to the working directory).

Docs Changes:
fluent/fluentd-docs-gitbook#727

Release Note:
config: a fractional number before a size or time unit (0.5s, 1.5m, 1.5k) is parsed as such instead of dropping the integer part

The size and time types matched only the digits right before the unit,
so the integer part of a fractional value was dropped silently:
"0.5s" became 5 seconds, "1.5m" 5 minutes and "1.5k" 5120 bytes.
Accept a decimal number before the unit. Values without a fractional
part are parsed exactly as before and keep returning an Integer.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@Watson1978 Watson1978 added the enhancement Feature request or improve operations label Nov 10, 2026

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR and the clear description. Reading 0.5s as 5 seconds is an easy trap to fall into, and the fix makes sense.

One thing to fix before merging: unit_value uses Float arithmetic, which is not exact for many decimal inputs and can shift timekey buckets. Details and a suggestion are inline.

About compatibility: existing configurations that already use such values get a different effective value after upgrading. For example, total_limit_size 2.5g was 5 GiB and becomes 2.5 GiB. So we will ship this in the next minor release as an enhancement, not as a backport to v1.19, and call it out in the release note.

Comment thread lib/fluent/config/types.rb Resolved
Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@Watson1978 Watson1978 added this to the v1.21.0 milestone Nov 18, 2026

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. unit_value now multiplies with Rational. The new 1.1h and 0.7d cases fail on master and on e41d027, and return the exact integers 3960 and 60480 here.

I also tried two scenarios. With timekey 1.5m, this version restored and flushed a file buffer chunk written by master. In a YAML config with retry_wait 0.5s, the retries went to <secondary> as expected.

As mentioned in the first review, this goes into the next minor release, not v1.19.

@Watson1978
Watson1978 merged commit 32cb2f0 into fluent:master Nov 19, 2026
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature request or improve operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants