rpcmetrics

package
v1.61.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

README

Package rpcmetrics implements an OpenTelemetry SpanProcessor that can be used to emit RPC metrics.

This package is copied from jaeger-client-go and adapted to work with OpenTelemtery SDK.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNameNormalizer = &SimpleNameNormalizer{
	SafeSets: []SafeCharacterSet{
		&Range{From: 'a', To: 'z'},
		&Range{From: 'A', To: 'Z'},
		&Range{From: '0', To: '9'},
		&Char{'_'},
		&Char{'/'},
		&Char{'.'},
	},
	Replacement: '_',
}

DefaultNameNormalizer converts endpoint names so that they contain only characters from the safe charset [a-zA-Z0-9./_]. All other characters are replaced with '_'.

Functions

This section is empty.

Types

type Char

type Char struct {
	Val byte
}

Char implements SafeCharacterSet

func (*Char) IsSafe

func (ch *Char) IsSafe(c byte) bool

IsSafe implements SafeCharacterSet

type Metrics

type Metrics struct {
	// RequestCountSuccess is a counter of the total number of successes.
	RequestCountSuccess metrics.Counter `metric:"requests" tags:"error=false"`

	// RequestCountFailures is a counter of the number of times any failure has been observed.
	RequestCountFailures metrics.Counter `metric:"requests" tags:"error=true"`

	// RequestLatencySuccess is a latency histogram of successful requests.
	RequestLatencySuccess metrics.Timer `metric:"request_latency" tags:"error=false"`

	// RequestLatencyFailures is a latency histogram of failed requests.
	RequestLatencyFailures metrics.Timer `metric:"request_latency" tags:"error=true"`

	// HTTPStatusCode2xx is a counter of the total number of requests with HTTP status code 200-299
	HTTPStatusCode2xx metrics.Counter `metric:"http_requests" tags:"status_code=2xx"`

	// HTTPStatusCode3xx is a counter of the total number of requests with HTTP status code 300-399
	HTTPStatusCode3xx metrics.Counter `metric:"http_requests" tags:"status_code=3xx"`

	// HTTPStatusCode4xx is a counter of the total number of requests with HTTP status code 400-499
	HTTPStatusCode4xx metrics.Counter `metric:"http_requests" tags:"status_code=4xx"`

	// HTTPStatusCode5xx is a counter of the total number of requests with HTTP status code 500-599
	HTTPStatusCode5xx metrics.Counter `metric:"http_requests" tags:"status_code=5xx"`
}

Metrics is a collection of metrics for an endpoint describing throughput, success, errors, and performance.

type MetricsByEndpoint

type MetricsByEndpoint struct {
	// contains filtered or unexported fields
}

MetricsByEndpoint is a registry/cache of metrics for each unique endpoint name. Only maxNumberOfEndpoints Metrics are stored, all other endpoint names are mapped to a generic endpoint name "other".

type NameNormalizer

type NameNormalizer interface {
	Normalize(name string) string
}

NameNormalizer is used to convert the endpoint names to strings that can be safely used as tags in the metrics.

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

Observer is an observer that can emit RPC metrics.

func NewObserver

func NewObserver(metricsFactory metrics.Factory, normalizer NameNormalizer) *Observer

NewObserver creates a new observer that can emit RPC metrics.

func (*Observer) ForceFlush

func (*Observer) ForceFlush(context.Context) error

func (*Observer) OnEnd

func (o *Observer) OnEnd(sp sdktrace.ReadOnlySpan)

func (*Observer) OnStart

func (*Observer) Shutdown

func (*Observer) Shutdown(context.Context) error

type Range

type Range struct {
	From, To byte
}

Range implements SafeCharacterSet

func (*Range) IsSafe

func (r *Range) IsSafe(c byte) bool

IsSafe implements SafeCharacterSet

type SafeCharacterSet

type SafeCharacterSet interface {
	IsSafe(c byte) bool
}

SafeCharacterSet determines if the given character is "safe"

type SimpleNameNormalizer

type SimpleNameNormalizer struct {
	SafeSets    []SafeCharacterSet
	Replacement byte
}

SimpleNameNormalizer uses a set of safe character sets.

func (*SimpleNameNormalizer) Normalize

func (n *SimpleNameNormalizer) Normalize(name string) string

Normalize checks each character in the string against SafeSets, and if it's not safe substitutes it with Replacement.

Jump to

Keyboard shortcuts

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