Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable metric sanitization when using prometheus reporter #1852

Merged
merged 4 commits into from May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 16 additions & 14 deletions common/service/config/metrics.go
Expand Up @@ -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
Expand Down Expand Up @@ -132,9 +133,10 @@ func (c *Metrics) newPrometheusScope(logger log.Logger) tally.Scope {
logger.Fatal("error creating prometheus reporter", tag.Error(err))
}
scopeOpts := tally.ScopeOptions{
Tags: c.Tags,
CachedReporter: reporter,
Separator: prometheus.DefaultSeparator,
Tags: c.Tags,
CachedReporter: reporter,
Separator: prometheus.DefaultSeparator,
SanitizeOptions: &sanitizeOptions,
}
scope, _ := tally.NewRootScope(scopeOpts, time.Second)
return scope
Expand Down