Enable metric sanitization when using prometheus reporter
Add sanitize options in tally while creating prometheus metric reporter..
@@ -33,31 +33,32 @@ import (
statsdreporter "github.com/uber/cadence/common/metrics/tally/statsd"
)
-/*
-// N.B - if we ever need a sanitizer these can be used to create M3 and prom
-// compatible metrics. Keeping this around for emergencies, but ideally we
-// ensure our base metrics are emitted correctly.
-// tally sanitizer options that satisfy both Prometheus and M3 restrictions
+// tally sanitizer options that satisfy both Prometheus and M3 restrictions.
+// This will rename metrics at the tally emission level, so metrics name we
+// use maybe different from what gets emitted. In the current implementation
+// it will replace - and . with _
+// We should still ensure that the base metrics are prometheus compatible,
+// but this is necessary as the same prom client initialization is used by
+// our system workflows.
var (
- _safeCharacters = []rune{'_'}
+ safeCharacters = []rune{'_'}
- _sanitizeOptions = tally.SanitizeOptions{
+ sanitizeOptions = tally.SanitizeOptions{
NameCharacters: tally.ValidCharacters{
Ranges: tally.AlphanumericRange,
- Characters: _safeCharacters,
+ Characters: safeCharacters,
},
KeyCharacters: tally.ValidCharacters{
Ranges: tally.AlphanumericRange,
- Characters: _safeCharacters,
+ Characters: safeCharacters,
},
ValueCharacters: tally.ValidCharacters{
Ranges: tally.AlphanumericRange,
- Characters: _safeCharacters,
+ Characters: safeCharacters,
},
ReplacementCharacter: tally.DefaultReplacementCharacter,
}
)
-*/
// NewScope builds a new tally scope
// for this metrics configuration
@@ -135,6 +136,7 @@ func (c *Metrics) newPrometheusScope(logger log.Logger) tally.Scope {
Tags: c.Tags,
CachedReporter: reporter,
Separator: prometheus.DefaultSeparator,
+ SanitizeOptions: &sanitizeOptions,
}
scope, _ := tally.NewRootScope(scopeOpts, time.Second)
return scope
