From 71a93ed6b19fc876d4994110222b176a40f2d5ec Mon Sep 17 00:00:00 2001 From: Greg Linton Date: Thu, 5 Jul 2018 18:02:05 -0600 Subject: [PATCH] Revert regex processor to allow empty values --- plugins/processors/regex/regex.go | 6 +++--- plugins/processors/regex/regex_test.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/processors/regex/regex.go b/plugins/processors/regex/regex.go index a25f33e72..9112ddd2d 100644 --- a/plugins/processors/regex/regex.go +++ b/plugins/processors/regex/regex.go @@ -68,7 +68,7 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric { for _, converter := range r.Tags { if value, ok := metric.GetTag(converter.Key); ok { k, v := r.convert(converter, value) - if k != "" && v != "" { + if k != "" { metric.AddTag(k, v) } } @@ -78,8 +78,8 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric { if value, ok := metric.GetField(converter.Key); ok { switch value := value.(type) { case string: - k, v := r.convert(converter, value) - if k != "" && v != "" { + k, _ := r.convert(converter, value) + if k != "" { metric.AddField(r.convert(converter, value)) } } diff --git a/plugins/processors/regex/regex_test.go b/plugins/processors/regex/regex_test.go index 723754cad..e7c15e5aa 100644 --- a/plugins/processors/regex/regex_test.go +++ b/plugins/processors/regex/regex_test.go @@ -222,7 +222,7 @@ func TestNoMatches(t *testing.T) { }, }, { - message: "Shouldn't emit empty string when result_key given but regex doesn't match", + message: "Should emit empty string when result_key given but regex doesn't match", converter: converter{ Key: "request", Pattern: "not_match", @@ -230,7 +230,8 @@ func TestNoMatches(t *testing.T) { ResultKey: "new_field", }, expectedFields: map[string]interface{}{ - "request": "/users/42/", + "request": "/users/42/", + "new_field": "", }, }, }