tally

package module
v0.0.0-...-6146420 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2021 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package tally implements a MetricsHandler backed by github.com/uber-go/tally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetricsHandler

func NewMetricsHandler(scope tally.Scope) client.MetricsHandler

NewMetricsHandler returns a MetricsHandler that is backed by the given Tally scope.

Default metrics are Prometheus compatible but default separator (.) should be replaced with some other character:

opts := tally.ScopeOptions{
	Separator: "_",
}
scope, _ := tally.NewRootScope(opts, time.Second)

If you have custom metrics make sure they are compatible with Prometheus or create tally scope with sanitizer options set:

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,
	}
)
opts := tally.ScopeOptions{
	SanitizeOptions: &sanitizeOptions,
	Separator: "_",
}
scope, _ := tally.NewRootScope(opts, time.Second)

func ScopeFromHandler

func ScopeFromHandler(handler client.MetricsHandler) tally.Scope

ScopeFromHandler returns the underlying scope of the handler. Callers may need to check workflow.IsReplaying(ctx) to avoid recording metrics during replay. If this handler was not created via this package, tally.NoopScope is returned.

Raw use of the scope is discouraged but may be used for Histograms or other advanced features. This scope does not skip metrics during replay like the metrics handler does. Therefore the caller should check replay state, for example:

scope := tally.NoopScope
if !workflow.IsReplaying(ctx) {
	scope = ScopeFromHandler(workflow.GetMetricsHandler(ctx))
}
scope.Histogram("my_histogram", nil).RecordDuration(5 * time.Second)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL