samples-go
samples-go copied to clipboard
Update metrics sample with newer Prometheus suggestions
Describe the solution you'd like
When https://github.com/temporalio/sdk-go/pull/756 is released, apply this:
diff --git a/metrics/worker/main.go b/metrics/worker/main.go
index c1dc254..e3dde80 100644
--- a/metrics/worker/main.go
+++ b/metrics/worker/main.go
@@ -53,35 +53,12 @@ func newPrometheusScope(c prometheus.Configuration) tally.Scope {
scopeOpts := tally.ScopeOptions{
CachedReporter: reporter,
Separator: prometheus.DefaultSeparator,
- SanitizeOptions: &sanitizeOptions,
+ SanitizeOptions: &sdktally.PrometheusSanitizeOptions,
Prefix: "temporal_samples",
}
scope, _ := tally.NewRootScope(scopeOpts, time.Second)
+ scope = sdktally.NewPrometheusNamingScope(scope)
log.Println("prometheus metrics scope created")
return scope
}
-
-// tally sanitizer options that satisfy Prometheus 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 _
-var (
- safeCharacters = []rune{'_'}
-
- sanitizeOptions = tally.SanitizeOptions{
- NameCharacters: tally.ValidCharacters{
- Ranges: tally.AlphanumericRange,
- Characters: safeCharacters,
- },
- KeyCharacters: tally.ValidCharacters{
- Ranges: tally.AlphanumericRange,
- Characters: safeCharacters,
- },
- ValueCharacters: tally.ValidCharacters{
- Ranges: tally.AlphanumericRange,
- Characters: safeCharacters,
- },
- ReplacementCharacter: tally.DefaultReplacementCharacter,
- }
-)