Closed NW-MLakin closed 3 years ago
So, I finally found a bit of consistency in controlling the file output frequency using timekey
, but it's pretty weird.
After testing a bunch of different timekey values, I noticed that it always writes out 11 files per timekey period. With a timekey of 60s, it creates 11 files per minute. At 120s it creates about 5-6 files per minute, at 240s 2-3 files per minute. I changed the timekey to 660, and as expected it now creates one file per minute. The server is continuously receiving logs every second, but the number and size of incoming logs varies throughout the day, yet it consistently creates 1 file per minute (11 per timekey).
One file per minute is my desired setting, and this technically achieves that, but it's pretty gross. Also, having the timekey larger than 60 causes the %M variable to represent the current minute of the timekey (0, 11, 22, etc.), instead of the actual current minute from the system clock, so I can't really use it in path or s3_object_key_format.
Am I the only one seeing this?
Here is the config I am using:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match stuff.**>
@type rewrite_tag_filter
<rule>
key message
pattern /.*/
tag something
</rule>
</match>
<match something>
@type s3
s3_bucket s3-bucket-name
s3_region region-name
path something/${host}
s3_object_key_format %{path}/%Y/%m/%d/%H-%M_%{hms_slice}.%{file_extension}
check_object false
<buffer time,host>
@type file
timekey 660
path /var/log/fluentd/something/
</buffer>
<format>
@type json
</format>
<inject>
time_key log_time
time_type string
time_format %Y-%m-%dT%H:%M:%S
utc true
</inject>
</match>
I have tried various different settings, and none of them has changed the observed behavior:
We are also witnessing this weirdness. We are using timekey 5m
, which means that it sent ~2 files per minute to S3 (11 per timekey
).
Because of this, it also appeared to be accumulating a backlog of un-flushed buffer files due to output to S3 happening at a lower rate than logs are generated, which, over time, leads to exhaustion of open file descriptors ulimit.
It seems that, if there are more than 11 buffer files created, no matter the timekey
, it would always lead to this backog, as it, apparently, cannot send more than 11 files per timekey
to S3.
Why 11, were does it come from, is it possible to adjust or configure it?
These other issues here might be because of the same reason: #339, #315, #237
It appears, that the issue is not with this S3 plugin, but rather the way Fluentd output buffer is configured.
The 11 comes from here: https://github.com/fluent/fluentd/blob/8dd83461d8f34317d6e0de189beeb6bcff01481d/lib/fluent/plugin/output.rb#L1354-L1365
Essentially, it takes the minimum of timekey
and timekey_wait
, and divides it by 11 for some reason. If the resulting number is less than flush_thread_interval
(default is 1.0
) it substitutes this min value with that of flush_thread_interval
, and uses that as the interval for flush. So a timekey 5m
would mean the previously mentioned one flush every 30sec.
When time
is specified as one of the chunk keys, the solution could be to configure flush_mode
to something else than the default lazy
, or set timekey_wait
to something lower than timekey
to help it flush logs faster than they are generated.
https://docs.fluentd.org/configuration/buffer-section#flushing-parameters
This issue has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 30 days
This issue was automatically closed because of stale in 30 days
It seems that the buffer timekey is not used at all to determine the frequency to write files to s3, as the fluentd documentation states:
The README in this repo does seem to indicate that it writes logs as it receives them, but there isn't any mention of how to control how frequently logs are written to S3:
I have tried using every combination of timekey, flush_interval, and chunk limits on both file and memory buffers, changing time_slice_format, and every other setting I could think of, and there seems to be no way to change the frequency of writing out files to S3. I even updated from 4.0.0 to 4.0.1 as there was some "timekey optimization" done in the release notes, which didn't help.
Is there a recommended method to receive a constant stream of logs and write them out to s3 at specific intervals, such as to create only one file per minute?