diff --git a/lib/fluent/plugin/out_influxdb.rb b/lib/fluent/plugin/out_influxdb.rb index 1534399..5f86a51 100644 --- a/lib/fluent/plugin/out_influxdb.rb +++ b/lib/fluent/plugin/out_influxdb.rb @@ -44,6 +44,8 @@ class Fluent::Plugin::InfluxdbOutput < Fluent::Plugin::Output desc: "Enable/Disable auto-tagging behaviour which makes strings tags." config_param :tag_keys, :array, default: [], desc: "The names of the keys to use as influxDB tags." + config_param :tag_keys_field, :string, default: nil, + desc: "The name of the fields where influxdb key names are stored" config_param :sequence_tag, :string, default: nil, desc: <<-DESC The name of the tag whose value is incremented for the consecutive simultaneous @@ -145,6 +147,10 @@ def write(chunk) end end end + if !@tag_keys_field.nil? && record.include?(tag_keys_field) + tags.update(record[tag_keys_field]) + values.delete(tag_keys_field) + end if @sequence_tag if @prev_timestamp == timestamp @seq += 1 diff --git a/test/plugin/test_out_influxdb.rb b/test/plugin/test_out_influxdb.rb index 9b66fde..45669e7 100644 --- a/test/plugin/test_out_influxdb.rb +++ b/test/plugin/test_out_influxdb.rb @@ -169,6 +169,35 @@ def test_write_with_measurement ], driver.instance.influxdb.points) end + def test_empty_tag_keys_field + config_with_tags = %Q( + #{CONFIG} + tag_keys_field b + ) + + driver = create_driver(config_with_tags) + + time = event_time("2011-01-02 13:14:15 UTC") + driver.run(default_tag: 'input.influxdb') do + driver.feed(time, {'b' => {'a' => "2"}, 'c' => '2'}) + end + + assert_equal([ + [ + [ + { + timestamp: 1293974055, + series: 'input.influxdb', + values: {'c' => "2"}, + tags: {'a' => "2"} + }, + ], + nil, + nil + ] + ], driver.instance.influxdb.points) + end + def test_empty_tag_keys config_with_tags = %Q( #{CONFIG}