目录
Shizuo Fujita

time: fix TimeFormatter returning nil for the Unix epoch (#5420)

Which issue(s) this PR fixes: Fixes #

What this PR does / why we need it: TimeFormatter caches the last two formatted timestamps in two slots, and an empty slot was marked by its key being 0. But 0 is a valid timestamp, so the epoch matched an empty slot and its nil string was returned as a cache hit:

Fluent::TimeFormatter.new(nil, false, nil).format(0)  #=> nil

format_with_subsec compares slots with EventTime.eq?, which falls back to EventTime#== and compares seconds alone, so there the whole first second of the epoch is affected:

fmt = Fluent::TimeFormatter.new("%Y%m%d %H%M%S.%N", false, nil)
fmt.format(Fluent::EventTime.new(0, 123456789))  #=> nil

The fix is to mark an empty slot by its cached string being nil rather than by its key. format_nocache always returns a String, so a filled slot can never be mistaken for an empty one. Every other timestamp behaves exactly as before, since key 0 could never have matched it.

Impact is small, and I don’t think this is urgent. A slot keeps the key 0 only until it is written, so a formatter self-heals once it has formatted two distinct timestamps, within a second of the first record. The exception is a stream whose timestamps are all the epoch: the early return never fills a slot, and out_file then writes every line with an empty time column. That is reachable via time_type unixtime, which parses with value.to_i and turns an empty or non-numeric time_key into EventTime.new(0), but such a pipeline is misconfigured anyway. The reason to fix it is simply that nil is never a correct result.

Docs Changes:

Release Note:

  • time: fix TimeFormatter returning nil for the Unix epoch

Signed-off-by: Shizuo Fujita fujita@clear-code.com

1天前7217次提交

Fluentd: Open-Source Log Collector

Test Test with Ruby head CII Best Practices OpenSSF Scorecard Backport Pull Requests

Fluentd collects events from various data sources and writes them to files, RDBMS, NoSQL, IaaS, SaaS, Hadoop and so on. Fluentd helps you unify your logging infrastructure (Learn more about the Unified Logging Layer).

Quick Start

$ gem install fluentd
$ fluentd -s conf
$ fluentd -c conf/fluent.conf &
$ echo '{"json":"message"}' | fluent-cat debug.test

Development

Branch

Prerequisites

  • Ruby 3.2 or later
  • git

git should be in PATH. On Windows, you can use Github for Windows and GitShell for easy setup.

Install dependent gems

Use bundler:

$ gem install bundler
$ bundle install --path vendor/bundle

Run test

$ bundle exec rake test

You can run specified test via TEST environment variable:

$ bundle exec rake test TEST=test/test_specified_path.rb
$ bundle exec rake test TEST=test/test_*.rb

More Information

Security

A third party security audit was performed by Cure53, you can see the full report here.

See SECURITY to contact us about vulnerability.

Contributors:

Patches contributed by great developers.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号