Skip to content

High CPU Usage with elasticsearch plugin when ES is not reachable (or API failed) #3027

@williamzhao87

Description

@williamzhao87

Describe the bug
When ES is down, FluentD CPU climbs to 50-70% usage, due to fluentd-plugin-elasticsearch failing to connect to ES and crashing Fluentd worker

To Reproduce
Change ES_HOST DNS to an invalid address, so that requests to it will fail.

Expected behavior
FluentD worker should not be crashing when failing to connect to ElasticSearch and raising CPU usage to high levels.

Your Environment
FluentD v1.7.3 running in CentOS 7 Docker container on Linux (t3.medium EC2 instance)
Elasticsearch v6.3.1
Fluent-plugin-elasticsearch v3.5.2

Your Configuration

fluent.conf:
        <source>
          @type  forward
          @id    input1
          port  24224
        </source>

        <source>
          @type http_heartbeat
          port 8642
        </source>

        <filter docker.*.*>
          @type concat
          key log
          stream_identity_key container_id
          multiline_start_regexp /^\d{4}-\d{1,2}-\d{1,2}|^127.0.0.1|^{\"level\"/
          flush_mode interval
          flush_interval 10
          timeout_label @processdata
        </filter>

        <label @processdata>
          <match **>
            @type stdout
          </match>
        </label>

        <filter docker.*.*>
          @type parser
          key_name log
          <parse>
            @type json
            json_parser json
            time_key time
            time_type unixtime
            keep_time_key true
          </parse>
          replace_invalid_sequence true
          reserve_data true # this preserves unparsable log lines
          emit_invalid_record_to_error false # In case of unparsable log lines keep the error log clean
          reserve_time # the time was already parsed in the source, we don't want to overwrite it with current time.
        </filter>

        <filter docker.*.*>
          @type record_transformer
          enable_ruby true
          <record>
            formatted_time \${Time.at(record['time'].to_i/1000, record['time'].to_i%1000*1000).utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ')}
            stack_name \"#{ENV['STACK_NAME']}\"
            log_level \${record['level'] == 10 ? 'trace' : record['level'] == 20 ? 'debug' : record['level'] == 30 ? 'info' : record['level'] == 40 ? 'warn' : record['level'] == 50 ? 'error' : 'fatal'}
          </record>
          remove_keys time,pid,v
        </filter>

        <match docker.*.*>
          @type copy
          <store ignore_error>
            @type elasticsearch
            @log_level debug
            host \"#{ENV['ES_HOST'] || 'es-logs'}\"
            port \"#{ENV['ES_PORT'] || 9200}\"
            logstash_prefix \"#{ENV['ES_LOGSTASH_PREFIX'] || 'logstash'}\"
            logstash_format true
            validate_client_version false
            type_name _doc
            request_timeout 15s
            sniffer_class_name 'Fluent::Plugin::ElasticsearchSimpleSniffer'
            reload_connections false
            reconnect_on_error true
            reload_on_failure true
            reload_after 100
            time_key formatted_time
            <buffer>
              @type file
              flush_mode interval
              flush_thread_count 4
              flush_interval 5s
              chunk_limit_size 8MB
              retry_wait 5
              retry_max_times 10
              retry_forever false
              retry_timeout 1h
              retry_type exponential_backoff
              overflow_action drop_oldest_chunk
              disable_chunk_backup true
              path /var/log/fluentd/buffer
            </buffer>
          </store>

          <store>
            @type file
            @id   output1
            path         /fluentd/log/\${tag[1]}/\${tag[2]}.%Y%m%d_%H
            append       true
            <buffer tag,time>
              @type memory
              flush_mode interval
              flush_interval 1s
              timekey 1h
              overflow_action drop_oldest_chunk
              disable_chunk_backup true
              retry_wait 5
              retry_max_times 10
              retry_forever false
              retry_timeout 1h
              retry_type exponential_backoff
            </buffer>
            <format>
              @type single_value
              message_key log
            </format>
            time_key formatted_time
          </store>
        </match>" >> /mnt/fluent.conf

Your Error Log

Repeated error below (in a constant loop):
2020-06-05 13:56:55 +0000 [info]: Worker 0 finished unexpectedly with status 1
2020-06-05 13:56:56 +0000 [info]: gem 'fluent-plugin-concat' version '2.4.0'
2020-06-05 13:56:56 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '3.5.2'
2020-06-05 13:56:56 +0000 [info]: gem 'fluent-plugin-http-heartbeat' version '0.0.5'
2020-06-05 13:56:56 +0000 [info]: gem 'fluentd' version '1.7.3'
2020-06-05 13:56:56 +0000 [info]: adding match in @processdata pattern="**" type="stdout"
2020-06-05 13:56:56 +0000 [info]: adding filter pattern="docker.*.*" type="concat"
2020-06-05 13:56:56 +0000 [info]: adding filter pattern="docker.*.*" type="parser"
2020-06-05 13:56:56 +0000 [info]: adding filter pattern="docker.*.*" type="record_transformer"
2020-06-05 13:56:56 +0000 [info]: adding match pattern="docker.*.*" type="copy"
2020-06-05 13:56:56 +0000 [error]: #0 unexpected error error_class=NameError error="uninitialized constant Faraday::Error::ConnectionFailed\nDid you mean?  Faraday::ConnectionFailed"
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-6.3.1/lib/elasticsearch/transport/transport/http/faraday.rb:46:in `host_unreachable_exceptions'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/elasticsearch_index_template.rb:36:in `rescue in retry_operate'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/elasticsearch_index_template.rb:34:in `retry_operate'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/out_elasticsearch.rb:244:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:164:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:74:in `block in configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:63:in `each'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:63:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/out_copy.rb:36:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:164:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:130:in `add_match'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:72:in `block in configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:64:in `each'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:64:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:150:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/engine.rb:131:in `configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/engine.rb:96:in `run_configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:804:in `run_configure'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:550:in `block in run_worker'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:733:in `main_process'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/supervisor.rb:546:in `run_worker'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/command/fluentd.rb:320:in `<top (required)>'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/bin/fluentd:8:in `<top (required)>'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby//2.3.1/bin/fluentd:23:in `load'
  2020-06-05 13:56:56 +0000 [error]: #0 /ruby//2.3.1/bin/fluentd:23:in `<main>'
2020-06-05 13:56:56 +0000 [info]: Worker 0 finished unexpectedly with status 1
2020-06-05 13:56:57 +0000 [info]: gem 'fluent-plugin-concat' version '2.4.0'
2020-06-05 13:56:57 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '3.5.2'
2020-06-05 13:56:57 +0000 [info]: gem 'fluent-plugin-http-heartbeat' version '0.0.5'
2020-06-05 13:56:57 +0000 [info]: gem 'fluentd' version '1.7.3'
2020-06-05 13:56:57 +0000 [info]: adding match in @processdata pattern="**" type="stdout"
2020-06-05 13:56:57 +0000 [info]: adding filter pattern="docker.*.*" type="concat"
2020-06-05 13:56:57 +0000 [info]: adding filter pattern="docker.*.*" type="parser"
2020-06-05 13:56:57 +0000 [info]: adding filter pattern="docker.*.*" type="record_transformer"
2020-06-05 13:56:57 +0000 [info]: adding match pattern="docker.*.*" type="copy"
2020-06-05 13:56:57 +0000 [error]: #0 unexpected error error_class=NameError error="uninitialized constant Faraday::Error::ConnectionFailed\nDid you mean?  Faraday::ConnectionFailed"
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/elasticsearch-transport-6.3.1/lib/elasticsearch/transport/transport/http/faraday.rb:46:in `host_unreachable_exceptions'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/elasticsearch_index_template.rb:36:in `rescue in retry_operate'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/elasticsearch_index_template.rb:34:in `retry_operate'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluent-plugin-elasticsearch-3.5.2/lib/fluent/plugin/out_elasticsearch.rb:244:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:164:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:74:in `block in configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:63:in `each'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/multi_output.rb:63:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin/out_copy.rb:36:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/plugin.rb:164:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:130:in `add_match'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:72:in `block in configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:64:in `each'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/agent.rb:64:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/root_agent.rb:150:in `configure'
  2020-06-05 13:56:57 +0000 [error]: #0 /ruby/2.3.1/lib/ruby/gems/2.3.0/gems/fluentd-1.7.3/lib/fluent/engine.rb:131:in `configure'

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions