From ca6723ff7880932cedf59272404c5bcf787dbeba Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Wed, 21 Aug 2019 11:13:46 +0100 Subject: [PATCH] Escape double-quotes in labels, and suppress labels with value nil Fixes #927 --- .../lib/fluent/plugin/out_loki.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fluentd/fluent-plugin-grafana-loki/lib/fluent/plugin/out_loki.rb b/fluentd/fluent-plugin-grafana-loki/lib/fluent/plugin/out_loki.rb index 1a7c2fb592274..c02426684a6c1 100644 --- a/fluentd/fluent-plugin-grafana-loki/lib/fluent/plugin/out_loki.rb +++ b/fluentd/fluent-plugin-grafana-loki/lib/fluent/plugin/out_loki.rb @@ -135,10 +135,8 @@ def labels_to_protocol(data_labels) data_labels = {} if data_labels.nil? data_labels = data_labels.merge(@extra_labels) - unless data_labels.nil? - data_labels.each do |k, v| - formatted_labels.push("#{k}=\"#{v}\"") - end + data_labels.each do |k, v| + formatted_labels.push("#{k}=\"#{v.gsub('"','\\"')}\"") if v end '{' + formatted_labels.join(',') + '}' end