Compare commits

..

4 Commits

Author SHA1 Message Date
Daniel Nelson
a14b3218cf Update changelog
(cherry picked from commit 25ceb7f5a7)
2018-07-06 16:17:09 -07:00
Alexander Shepelin
63d07f4272 Don't set values when pattern doesn't match in regex processor (#4396)
(cherry picked from commit 35d2f90d6c)
2018-07-06 16:17:08 -07:00
Daniel Nelson
858335b1c4 Update changelog
(cherry picked from commit a0ece79191)
2018-07-05 14:41:01 -07:00
Greg
9b489a43eb Use 'localhost' as default 'server' tag in zookeeper input (#4387)
(cherry picked from commit a82b4fbd96)
2018-07-05 14:40:45 -07:00
6 changed files with 48 additions and 6 deletions

View File

@@ -1,3 +1,10 @@
## v1.7.2 [unreleased]
### Bugfixes
- [#4381](https://github.com/influxdata/telegraf/issues/4381): Use localhost as default server tag in zookeeper input.
- [#4374](https://github.com/influxdata/telegraf/issues/4374): Don't set values when pattern doesn't match in regex processor.
## v1.7.1 [2018-07-03]
### Bugfixes

View File

@@ -0,0 +1,17 @@
version: '3'
services:
zoo:
image: zookeeper
telegraf:
image: glinton/scratch
volumes:
- ./telegraf.conf:/telegraf.conf
- ../../../../telegraf:/telegraf
depends_on:
- zoo
entrypoint:
- /telegraf
- --config
- /telegraf.conf
network_mode: service:zoo

View File

@@ -0,0 +1,9 @@
[agent]
interval="1s"
flush_interval="1s"
[[inputs.zookeeper]]
servers = [":2181"]
[[outputs.file]]
files = ["stdout"]

View File

@@ -158,8 +158,14 @@ func (z *Zookeeper) gatherServer(ctx context.Context, address string, acc telegr
}
}
}
srv := "localhost"
if service[0] != "" {
srv = service[0]
}
tags := map[string]string{
"server": service[0],
"server": srv,
"port": service[1],
"state": zookeeper_state,
}

View File

@@ -67,7 +67,9 @@ 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))
if key, newValue := r.convert(converter, value); newValue != "" {
metric.AddTag(key, newValue)
}
}
}
@@ -75,7 +77,9 @@ func (r *Regex) Apply(in ...telegraf.Metric) []telegraf.Metric {
if value, ok := metric.GetField(converter.Key); ok {
switch value := value.(type) {
case string:
metric.AddField(r.convert(converter, value))
if key, newValue := r.convert(converter, value); newValue != "" {
metric.AddField(key, newValue)
}
}
}
}

View File

@@ -222,7 +222,7 @@ func TestNoMatches(t *testing.T) {
},
},
{
message: "Should emit empty string when result_key given but regex doesn't match",
message: "Should not emit new tag/field when result_key given but regex doesn't match",
converter: converter{
Key: "request",
Pattern: "not_match",
@@ -230,8 +230,7 @@ func TestNoMatches(t *testing.T) {
ResultKey: "new_field",
},
expectedFields: map[string]interface{}{
"request": "/users/42/",
"new_field": "",
"request": "/users/42/",
},
},
}