Revert regex processor to allow empty values
This commit is contained in:
parent
a7fb1c280f
commit
71a93ed6b1
|
@ -68,7 +68,7 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric {
|
||||||
for _, converter := range r.Tags {
|
for _, converter := range r.Tags {
|
||||||
if value, ok := metric.GetTag(converter.Key); ok {
|
if value, ok := metric.GetTag(converter.Key); ok {
|
||||||
k, v := r.convert(converter, value)
|
k, v := r.convert(converter, value)
|
||||||
if k != "" && v != "" {
|
if k != "" {
|
||||||
metric.AddTag(k, v)
|
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 {
|
if value, ok := metric.GetField(converter.Key); ok {
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
k, v := r.convert(converter, value)
|
k, _ := r.convert(converter, value)
|
||||||
if k != "" && v != "" {
|
if k != "" {
|
||||||
metric.AddField(r.convert(converter, value))
|
metric.AddField(r.convert(converter, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
converter: converter{
|
||||||
Key: "request",
|
Key: "request",
|
||||||
Pattern: "not_match",
|
Pattern: "not_match",
|
||||||
|
@ -231,6 +231,7 @@ func TestNoMatches(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedFields: map[string]interface{}{
|
expectedFields: map[string]interface{}{
|
||||||
"request": "/users/42/",
|
"request": "/users/42/",
|
||||||
|
"new_field": "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue