From 5d4c275d54ee7e339a369065722c9b2cd85092a9 Mon Sep 17 00:00:00 2001 From: Xuo Guoto Date: Sun, 9 May 2021 13:27:30 +0530 Subject: [PATCH] fix: supporting of nested fields Backported from https://github.com/influxdata/influxdb-plugin-fluent/pull/8 --- lib/fluent/plugin/out_influxdb.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fluent/plugin/out_influxdb.rb b/lib/fluent/plugin/out_influxdb.rb index 9aed2a4..b6f1751 100644 --- a/lib/fluent/plugin/out_influxdb.rb +++ b/lib/fluent/plugin/out_influxdb.rb @@ -138,14 +138,7 @@ def write(chunk) values = {} tags = {} record.each_pair do |k, v| - if (@auto_tags && v.is_a?(String)) || @tag_keys.include?(k) - # If the tag value is not nil, empty, or a space, add the tag - if v.to_s.strip != '' - tags[k] = v - end - else - values[k] = v - end + _parse_field(k, v, tags, values) end end if @sequence_tag @@ -204,6 +197,21 @@ def write(chunk) end end + def _parse_field(k, v, tags, values) + if (@auto_tags && v.is_a?(String)) || @tag_keys.include?(k) + # If the tag value is not nil, empty, or a space, add the tag + if v.to_s.strip != '' + tags[k] = v + end + elsif v.is_a?(Hash) + v.each_pair do |nested_k, nested_v| + _parse_field("#{k}.#{nested_k}", nested_v, tags, values) + end + else + values[k] = v + end + end + def time_precise_lambda() case @time_precision.to_sym when :h then