From 44ae8f557c39de858cffd2be9f257a5b654d479b Mon Sep 17 00:00:00 2001 From: Matthias Rampke Date: Fri, 29 May 2020 07:45:22 +0000 Subject: [PATCH] Allow single-letter components in metric names They are valid. Fixes #256. Signed-off-by: Matthias Rampke --- pkg/mapper/mapper.go | 2 +- pkg/mapper/mapper_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index 8aac9d1..c6a31a4 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -27,7 +27,7 @@ import ( ) var ( - statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])+` + statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])*` templateReplaceRE = `(\$\{?\d+\}?)` metricLineRE = regexp.MustCompile(`^(\*\.|` + statsdMetricRE + `\.)+(\*|` + statsdMetricRE + `)$`) diff --git a/pkg/mapper/mapper_test.go b/pkg/mapper/mapper_test.go index dc8a45d..c1e43b7 100644 --- a/pkg/mapper/mapper_test.go +++ b/pkg/mapper/mapper_test.go @@ -662,6 +662,29 @@ mappings: `, configBad: true, }, + { + config: `--- +mappings: +- match: p.*.*.c.* + match_type: glob + name: issue_256 + labels: + one: $1 + two: $2 + three: $3 +`, + mappings: mappings{ + { + statsdMetric: "p.one.two.c.three", + name: "issue_256", + labels: map[string]string{ + "one": "one", + "two": "two", + "three": "three", + }, + }, + }, + }, // Example from the README. { config: `