forked from mirrors/statsd_exporter
Merge pull request #365 from glightfoot/segment-numbers
Support metric name segments starting with numbers
This commit is contained in:
commit
a8c09aaa97
2 changed files with 78 additions and 3 deletions
|
@ -28,10 +28,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])*`
|
||||
templateReplaceRE = `(\$\{?\d+\}?)`
|
||||
// The first segment of a match cannot start with a number
|
||||
statsdMetricRE = `[a-zA-Z_](-?[a-zA-Z0-9_])*`
|
||||
// The subsequent segments of a match can start with a number
|
||||
// See https://github.com/prometheus/statsd_exporter/issues/328
|
||||
statsdMetricSubsequentRE = `[a-zA-Z0-9_](-?[a-zA-Z0-9_])*`
|
||||
templateReplaceRE = `(\$\{?\d+\}?)`
|
||||
|
||||
metricLineRE = regexp.MustCompile(`^(\*\.|` + statsdMetricRE + `\.)+(\*|` + statsdMetricRE + `)$`)
|
||||
metricLineRE = regexp.MustCompile(`^(\*|` + statsdMetricRE + `)(\.\*|\.` + statsdMetricSubsequentRE + `)*$`)
|
||||
metricNameRE = regexp.MustCompile(`^([a-zA-Z_]|` + templateReplaceRE + `)([a-zA-Z0-9_]|` + templateReplaceRE + `)*$`)
|
||||
labelNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]+$`)
|
||||
)
|
||||
|
|
|
@ -355,6 +355,77 @@ mappings:
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Match metric segment with a number",
|
||||
config: `
|
||||
mappings:
|
||||
- match: test.99.myapp.*
|
||||
name: "name"
|
||||
labels:
|
||||
label: "${1}_foo"
|
||||
`,
|
||||
mappings: mappings{
|
||||
{
|
||||
statsdMetric: "test.99.myapp.create",
|
||||
name: "name",
|
||||
labels: map[string]string{
|
||||
"label": "create_foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Match metric segment starting with a number",
|
||||
config: `
|
||||
mappings:
|
||||
- match: test.99test.myapp.*
|
||||
name: "name"
|
||||
labels:
|
||||
label: "${1}_foo"
|
||||
`,
|
||||
mappings: mappings{
|
||||
{
|
||||
statsdMetric: "test.99test.myapp.create",
|
||||
name: "name",
|
||||
labels: map[string]string{
|
||||
"label": "create_foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Match metric segment with a number #328 example",
|
||||
config: `
|
||||
mappings:
|
||||
- match: kafka.server.FetcherStats.brokerHost.hostname.brokerPort.9092.clientId.ReplicaFetcherThread-0-1.BytesPerSec.1MinuteRate.gauge
|
||||
name: "example_name"
|
||||
`,
|
||||
mappings: mappings{
|
||||
{
|
||||
statsdMetric: "kafka.server.FetcherStats.brokerHost.hostname.brokerPort.9092.clientId.ReplicaFetcherThread-0-1.BytesPerSec.1MinuteRate.gauge",
|
||||
name: "example_name",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Single segment match",
|
||||
config: `
|
||||
mappings:
|
||||
- match: '*'
|
||||
name: single_segment
|
||||
labels:
|
||||
label: "${1}"
|
||||
`,
|
||||
mappings: mappings{
|
||||
{
|
||||
statsdMetric: "test",
|
||||
name: "single_segment",
|
||||
labels: map[string]string{
|
||||
"label": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: "Config with bad metric line",
|
||||
config: `---
|
||||
|
|
Loading…
Reference in a new issue