Revert regex processor to allow empty values

This commit is contained in:
Greg Linton 2018-07-05 18:02:05 -06:00
parent a7fb1c280f
commit 71a93ed6b1
2 changed files with 6 additions and 5 deletions

View File

@ -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))
}
}

View File

@ -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": "",
},
},
}