Skip to content

Commit

Permalink
Prevent new tag from being overwritten
Browse files Browse the repository at this point in the history
Resolves #4374
  • Loading branch information
glinton committed Jul 5, 2018
1 parent bf076da commit 2e724d8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/processors/regex/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const sampleConfig = `
# key = "request"
# ## All the power of the Go regular expressions available here
# ## For example, named subgroups
# pattern = "^/api(?P<method>/[\\w/]+)\\S*"
# pattern = "^/api(?P<method>/[\\w/]+)\\S*"
# replacement = "${method}"
# ## If result_key is present, a new field will be created
# ## instead of changing existing field
Expand Down Expand Up @@ -67,15 +67,21 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric {
for _, metric := range in {
for _, converter := range r.Tags {
if value, ok := metric.GetTag(converter.Key); ok {
metric.AddTag(r.convert(converter, value))
k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddTag(k, v)
}
}
}

for _, converter := range r.Fields {
if value, ok := metric.GetField(converter.Key); ok {
switch value := value.(type) {
case string:
metric.AddField(r.convert(converter, value))
k, v := r.convert(converter, value)
if k != "" && v != "" {
metric.AddField(r.convert(converter, value))
}
}
}
}
Expand Down

0 comments on commit 2e724d8

Please sign in to comment.