fluentd icon indicating copy to clipboard operation
fluentd copied to clipboard

NoMethodError error="undefined method `[]' for nil:NilClass" location="(eval):1:in `expand_param'"

Open agoloAbbas opened this issue 5 years ago • 3 comments

Describe the bug parsing logs with parser plugin using gork plugin is not working

To Reproduce setup fleuntd with config mentioned below

Expected behavior expecting logs to show up parsed based on pattern configured

Your Environment

  • Fluentd or td-agent version: fluentd --version or td-agent --version
fluentd --version
fluentd 1.12.0
  • Operating system: cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • Kernel version: uname -r
4.14.193-149.317.amzn2.x86_64

Your Configuration

  <label @FLUENT_LOG>
    <match fluent.*>
      @type stdout
    </match>
  </label>
  <source>
    @id fluentd-containers.log
    @type tail
    path "/var/log/containers/*.log"
    pos_file "/var/log/containers.log.pos"
    tag "raw.kubernetes.*"
    read_from_head true
    <parse>
      @type "multi_format"
      unmatched_lines
      <pattern>
        format json
        time_key "time"
        time_format "%Y-%m-%dT%H:%M:%S.%NZ"
        keep_time_key true
        time_type string
      </pattern>
      <pattern>
        format /^(?<time>.+) (?<stream>stdout|stderr) [^ ]* (?<log>.*)$/
        time_format "%Y-%m-%dT%H:%M:%S.%N%:z"
        keep_time_key true
        expression ^(?<time>.+) (?<stream>stdout|stderr) [^ ]* (?<log>.*)$
        ignorecase false
        multiline false
      </pattern>
    </parse>
  </source>
  <match raw.kubernetes.**>
    @id raw.kubernetes
    @type detect_exceptions
    remove_tag_prefix "raw"
    message "log"
    stream "stream"
    multiline_flush_interval 5
    max_bytes 500000
    max_lines 1000
  </match>
  <filter **>
    @id filter_concat
    @type concat
    key "message"
    multiline_end_regexp "/\\n$/"
    separator ""
    timeout_label "@NORMAL"
    flush_interval 5
  </filter>
  <filter kubernetes.**>
    @id filter_kubernetes_metadata
    @type kubernetes_metadata
  </filter>
  <filter kubernetes.**>
    @id filter_parser
    @type parser
    key_name "log"
    reserve_time true
    reserve_data true
    remove_key_name_field true
    inject_key_prefix "json."
    <parse>
      @type "multi_format"
      <pattern>
        format json
      </pattern>
      <pattern>
        format none
      </pattern>
    </parse>
  </filter>
  <filter kubernetes.**>
    @id drop_unused_logs
    @type grep
    <or>
      <exclude>
        key "$[\"json\"][\"level\"]"
        pattern 20|DEBUG
      </exclude>
      <exclude>
        key "$[\"kubernetes\"][\"container_name\"]"
        pattern redirector|filebeat
      </exclude>
      <exclude>
        key "$[\"kubernetes\"][\"labels\"][\"release\"]"
        pattern jaeger
      </exclude>
      <exclude>
        key "$[\"kubernetes\"][\"labels\"][\"telepresence\"]"
        pattern .+
      </exclude>
    </or>
  </filter>
  <filter kubernetes.**>
    @type record_transformer
    enable_ruby
    <record>
      kubernetes.labels.release ${record["kubernetes"]["labels"]["app_kubernetes_io/instance"] || record["kubernetes"]["labels"]["release"] || record["kubernetes"]["labels"]["app"]}
    </record>
  </filter>
  <filter kubernetes.**.mongodb**>
    @id mongo_parser
    @type parser
    key_name "json.message"
    remove_key_name_field true
    replace_invalid_sequence true
    inject_key_prefix "custom."
    enable_ruby
    <parse>
      @type "grok"
      grok_failure_key "grokfailure"
      <grok>
        pattern "%{TIMESTAMP_ISO8601:timestamp} %{WORD:mongo.loglevel} %{DATA:mongo.conn_type} %{GREEDYDATA:message}"
      </grok>
    </parse>
  </filter>
  <source>
    @id forward
    @type forward
  </source>
  <source>
    @id prometheus
    @type prometheus
  </source>
  <source>
    @id monitor_agent
    @type monitor_agent
  </source>
  <source>
    @id prometheus_monitor
    @type prometheus_monitor
    <labels>
      host ${hostname}
    </labels>
  </source>
  <source>
    @id prometheus_output_monitor
    @type prometheus_output_monitor
    <labels>
      host ${hostname}
    </labels>
  </source>
  <source>
    @id prometheus_tail_monitor
    @type prometheus_tail_monitor
    <labels>
      host ${hostname}
    </labels>
  </source>
  <match **>
    @type relabel
    @label @NORMAL
  </match>
  <label @NORMAL>
    <match **>
      @id elasticsearch
      @type elasticsearch_dynamic
      @log_level "info"
      include_tag_key true
      hosts "elasticsearch-master:9200"
      path ""
      scheme http
      ssl_verify true
      ssl_version TLSv1_2
      type_name "_doc"
      logstash_format true
      logstash_dateformat "%Y.%m.%d"
      logstash_prefix "efk-r1-${record[\'kubernetes\'][\'labels\'][\'release\'] || record[\'kubernetes\'][\'labels\'][\'app_kubernetes_io/instance\'] || record[\'kubernetes\'][\'labels\'][\'app\'] ||\'NotIncludedInHelmReleases\'}"
      logstash_prefix_separator "-"
      log_es_400_reason false
      reconnect_on_error true
      reload_on_failure false
      reload_connections false
      request_timeout 5s
      suppress_type_name true
      <buffer>
        @type "file"
        path "/var/log/fluentd-buffers/kubernetes.system.buffer"
        flush_mode interval
        retry_type exponential_backoff
        flush_thread_count 2
        flush_interval 5s
        retry_forever true
        retry_max_interval 30
        chunk_limit_size 2M
        queue_limit_length 8
        overflow_action block
      </buffer>
    </match>
  </label>
  <system>
    root_dir "/tmp/fluentd-buffers/"
  </system>
</ROOT>

Your Error Log

2021-01-26 17:25:03 +0000 [warn]: fluent/log.rb:350:warn: dump an error event: error_class=NoMethodError error="undefined method `[]' for nil:NilClass" location="(eval):1:in `expand_param'" tag="kubernetes.var.log.containers.mongodb-mongodb-replicaset-2_default_mongodb-replicaset-a468a27347c37a8f9d63f4b0af702d6879b70678822c17a96c0a06c2fed8402a.log" time=2021-01-26 17:25:03.211186228 +0000 record={"custom.timestamp"=>"2021-01-26T17:25:02.188+0000", "custom.mongo.loglevel"=>"I", "custom.mongo.conn_type"=>"NETWORK", "custom.message"=>" [conn2810246] end connection 127.0.0.1:52030 (113 connections now open)"}
2021-01-26 17:25:03.977018320 +0000 fluent.warn: {"error":"#<NoMethodError: undefined method `[]' for nil:NilClass>","location":"(eval):1:in `expand_param'","tag":"kubernetes.var.log.containers.mongodb-mongodb-replicaset-2_default_mongodb-replicaset-a468a27347c37a8f9d63f4b0af702d6879b70678822c17a96c0a06c2fed8402a.log","time":1611681903,"record":{"custom.timestamp":"2021-01-26T17:25:02.188+0000","custom.mongo.loglevel":"I","custom.mongo.conn_type":"NETWORK","custom.message":" [conn2810247] end connection 127.0.0.1:52032 (114 connections now open)"},"message":"dump an error event: error_class=NoMethodError error=\"undefined method `[]' for nil:NilClass\" location=\"(eval):1:in `expand_param'\" tag=\"kubernetes.var.log.containers.mongodb-mongodb-replicaset-2_default_mongodb-replicaset-a468a27347c37a8f9d63f4b0af702d6879b70678822c17a96c0a06c2fed8402a.log\" time=2021-01-26 17:25:03.210638263 +0000 record={\"custom.timestamp\"=>\"2021-01-26T17:25:02.188+0000\", \"custom.mongo.loglevel\"=>\"I\", \"custom.mongo.conn_type\"=>\"NETWORK\", \"custom.message\"=>\" [conn2810247] end connection 127.0.0.1:52032 (114 connections now open)\"}"}

--

Additional context

agoloAbbas avatar Jan 26 '21 17:01 agoloAbbas

@agoloAbbas

Thank you for reporting the issue, Could you help us to provide minimized reproducible steps? (small log and reduced match pattern is appreciated for making it reproducible)

kenhys avatar Jan 28 '21 06:01 kenhys

Maybe, this is not fluentd core issue because expand_param is executed in elasticsearch_dynamic. Please post it on fluent-plugin-elasticsearch repository with log example. The problem happens by the mismatch between actual record and your configuration.

repeatedly avatar Jan 29 '21 01:01 repeatedly

Same issue here. The only difference is that I'm using "@type elasticsearch"

mokhos avatar Mar 30 '22 09:03 mokhos