fluentd icon indicating copy to clipboard operation
fluentd copied to clipboard

Log loss related to file rotations

Open dmkc opened this issue 6 years ago • 2 comments

Describe the bug Loss of logs when using log file rotation and a sufficiently high volume of logs occurs.

To Reproduce

  • set a low max log size to force rotation (e.g. 10MB)
  • use * in the path
  • write a sufficiently large number of log entries (5-7k events/s in our case)

Expected behavior No log loss

Your Environment fluentd 1.11.4

cat /etc/os-release
BUILD_ID=12371.251.0
NAME="Container-Optimized OS"
KERNEL_COMMIT_ID=5d4ffd91281840f7a118143d77fbefb02e87943c
GOOGLE_CRASH_ID=Lakitu
VERSION_ID=77
BUG_REPORT_URL="https://cloud.google.com/container-optimized-os/docs/resources/support-policy#contact_us"
PRETTY_NAME="Container-Optimized OS from Google"
VERSION=77
GOOGLE_METRICS_PRODUCT_ID=26
HOME_URL="https://cloud.google.com/container-optimized-os/docs"
ID=cos

uname -r
4.19.112+

Your Configuration

<label @FLUENT_LOG>
  <match fluent.**>
    @id fluentd_internal
    @type null
  </match>
</label>

################
# inputs
################
<source>
  @type tail
  enable_stat_watcher false
  path /var/log/containers/*.log
  pos_file /var/log/fluentd/containers.log.pos
  tag kubernetes.*
  read_from_head true
  refresh_interval "#{ENV['TAIL_REFRESH_INTERVAL']}"

  <parse>
    @type json
	# keep the time key and do our own date parsing
    keep_time_key true
  </parse>
</source>

<source>
  @type forward
  port 24224
</source>

#########
# filters
#########
<filter **>
  @type record_modifier
  char_encoding utf-8
</filter>

<filter kubernetes.** mysql_slow_query.**>
  @type kubernetes_log
  statsd_endpoint "#{ENV['STATSD_ADDR']}"
  cluster "#{ENV['CLUSTER']}"
  hostname "#{ENV['HOSTNAME']}"
  location "#{ENV['KUBE_LOCATION']}"
</filter>

#########
# outputs
#########
<match kubernetes.** rails.** active-job.** dnstap.** mysql_slow_query.**>
  @type relabel
  @label @NORMAL
</match>

<label @NORMAL>
  <match kubernetes.** rails.** active-job.** dnstap.** mysql_slow_query.**>
    @id forward
    @type forward
    ignore_network_errors_at_startup true
    keepalive true
    keepalive_timeout 60s
    connect_timeout 3s
    <server>
      host "#{ENV['FLUENTD_AGGREGATOR']}"
      port 24224
    </server>

    <buffer>
      @type memory
      # path /var/log/fluentd/kubernetes.forwarder.buffer
      flush_at_shutdown true
      # Set the chunk limit conservatively to avoid exceeding the GCL limit
      # of 10MiB per write request.
      chunk_limit_size 10M
      # Cap the combined memory usage of this buffer
      total_limit_size 750M
      # use longer flush_interval to reduce CPU usage.
      # note that this is a trade-off against latency.
      flush_interval 5s
      # Never wait longer than 30 seconds between retries.
      retry_max_interval 30
      # Disable the limit on the number of retries (retry forever).
      retry_forever true
      # Use multiple threads for processing.
      flush_thread_count 4
      # Block if buffer is full and let pubsub queue up
      overflow_action block
      # Use compression in buffer
      compress gzip
    </buffer>
  </match>
</label>

Your Error Log n/a

Additional context We're running fluentd in a kubernetes DaemonSet on Google Container OS nodes. We have a forwarder and aggregator layers, and logs eventually end up in Splunk. By default in these nodes, Docker ships configured with max-file set to 10MB (https://docs.docker.com/config/containers/logging/json-file/#options), a fairly small log size. We've noticed log loss around the time of rotations and initially tried the following:

  • disabling inotify via enable_stat_watcher as mentioned in other issues here. Enabling it and using enable_watch_timer: false lead to fluentd only tracking files until the rotation happens, then not picking logs up at all, also as reported elsewhere
  • disabling gzip, parsing the time ourselves: our profiling indicated those as hot paths. We managed to up the throughput but still eventually saw loss
  • switching to in-memory buffers
  • tuning CPU and memory resource allocation
  • comparing a large number of containers per node vs. fewer (more log files to track)

I then tried producing synthetic logs using a script to reproduce the issue. The script generates random log messages uniformly distributed between 1 and MAX_LENGTH in length. MAX_FILE denotes the max-file Docker log driver config. The logs are graphed by the timestamp included by Docker so gaps indicate log loss/no messages for that timestamp. I used a rate of 5000 eps for this run:

image

You can see first that I'm able to induce log loss by increasing the max log entry length. At 12:50, as I bump the max-size, the gaps in logs go away. We suspected that length of an individual log entry might play a role but ultimately it's the write rate and subsequent frequency of log rotations that seem to be the issue, as I can reproduce the above with shorter more frequent messages.

I haven't tested hardcoding a specific filename to eliminate the wildcard * in log paths, mostly bc it won't really work for us as we include container names into the filename that are generated by k8s which are then used for tagging logs.

As a base of comparison, we've tried fluentbit. On same hardware and with a comparable config, it doesn't seem to have issues with the inotify implementation and tracks file rotations correctly showing no log loss.

dmkc avatar Nov 20 '20 21:11 dmkc

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

github-actions[bot] avatar Feb 19 '21 10:02 github-actions[bot]

This issue was automatically closed because of stale in 30 days

github-actions[bot] avatar Mar 21 '21 10:03 github-actions[bot]