Compile regexp once in zookeeper input (#5969)

This commit is contained in:
Oleg Kovalov 2019-06-07 21:25:55 +02:00 committed by Daniel Nelson
parent d31f1735d9
commit eeb036911f
1 changed files with 3 additions and 3 deletions

View File

@ -17,6 +17,8 @@ import (
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
) )
var zookeeperFormatRE = regexp.MustCompile(`^zk_(\w+)\s+([\w\.\-]+)`)
// Zookeeper is a zookeeper plugin // Zookeeper is a zookeeper plugin
type Zookeeper struct { type Zookeeper struct {
Servers []string Servers []string
@ -136,9 +138,7 @@ func (z *Zookeeper) gatherServer(ctx context.Context, address string, acc telegr
fields := make(map[string]interface{}) fields := make(map[string]interface{})
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
parts := zookeeperFormatRE.FindStringSubmatch(string(line))
re := regexp.MustCompile(`^zk_(\w+)\s+([\w\.\-]+)`)
parts := re.FindStringSubmatch(string(line))
if len(parts) != 3 { if len(parts) != 3 {
return fmt.Errorf("unexpected line in mntr response: %q", line) return fmt.Errorf("unexpected line in mntr response: %q", line)