fangli / fluent-plugin-influxdb

A buffered output plugin for fluentd and InfluxDB
MIT License
111 stars 65 forks source link

Skip records with empty values #65

Closed Jimilian closed 7 years ago

Jimilian commented 7 years ago

In this PR I address issue that happens then somebody tries to push record without any value. In this case plugin prints in logs that it doesn't make any sense to push something like that to InfluxDB and continue to work.

According official documentation:

Fields are a required piece of InfluxDB’s data structure - you cannot have data in InfluxDB without fields.

https://docs.influxdata.com/influxdb/v1.1/concepts/key_concepts/

So, if user doesn't provide any value he receives something like:

  2016-11-28 13:29:40 +0000 [warn]: before_shutdown failed error="{\"error\":\"partial write:\\nunable to parse 'db_name,tag1=tag_value1,tag2=tag_value2  TIME': invalid field format\"}\n"
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/client/http.rb:84:in `resolve_error'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/client/http.rb:35:in `block in post'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/client/http.rb:53:in `connect_with_retry'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/client/http.rb:26:in `post'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/query/core.rb:62:in `write'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/influxdb-0.3.0/lib/influxdb/query/core.rb:48:in `write_points'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluent-plugin-influxdb-0.2.7/lib/fluent/plugin/out_influxdb.rb:158:in `write'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/buffer.rb:345:in `write_chunk'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/buffer.rb:324:in `pop'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/plugin/buf_memory.rb:94:in `block in before_shutdown'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/plugin/buf_memory.rb:90:in `before_shutdown'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/output.rb:404:in `before_shutdown'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/output.rb:160:in `block in run'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/output.rb:159:in `synchronise'
  2016-11-28 13:29:40 +0000 [warn]: /opt/td-agent/embedded/lib/ruby/gems/2.1.0/gems/fluentd-0.12.20/lib/fluent/output.rb:159:in `run'

After that fluentd tries to retry... fails... try again... and queue is blocked for some time.

repeatedly commented 7 years ago

Why this happens? This plugin checks empty value in format > https://github.com/fangli/fluent-plugin-influxdb/blob/93cf8c2421f58067af19441832b88178d7f5b9ee/lib/fluent/plugin/out_influxdb.rb#L93

Jimilian commented 7 years ago

record itself contains values, but there is no values in terms of InfluxDB - only tags. I.e. we push something like ["key1": "v1", "key2": "v2"], key1 is tag and key2 is not - everything is ok, but if key1 and key2 are both marked like tag influxdb doesn't accept such record.