rpcmetrics

package
v2.11.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

An Observer that can be used to emit RPC metrics

It can be attached to the tracer during tracer construction. See ExampleObserver function in observer_test.go.

Documentation

Overview

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

Index

Examples

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{'/'},
		&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 succesful 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.

Example
metricsFactory := metrics.NewLocalFactory(0)
metricsObserver := NewObserver(
	metricsFactory,
	DefaultNameNormalizer,
)
tracer, closer := jaeger.NewTracer(
	"serviceName",
	jaeger.NewConstSampler(true),
	jaeger.NewInMemoryReporter(),
	jaeger.TracerOptions.Observer(metricsObserver),
)
defer closer.Close()

span := tracer.StartSpan("test", ext.SpanKindRPCServer)
span.Finish()

c, _ := metricsFactory.Snapshot()
fmt.Printf("requests (success): %d\n", c["requests|endpoint=test|error=false"])
fmt.Printf("requests (failure): %d\n", c["requests|endpoint=test|error=true"])
Output:

requests (success): 1
requests (failure): 0

func NewObserver

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

NewObserver creates a new observer that can emit RPC metrics.

func (*Observer) OnStartSpan

func (o *Observer) OnStartSpan(
	operationName string,
	options opentracing.StartSpanOptions,
) jaeger.SpanObserver

OnStartSpan creates a new Observer for the span.

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.

type SpanKind

type SpanKind int

SpanKind identifies the span as inboud, outbound, or internal

const (
	// Local span kind
	Local SpanKind = iota
	// Inbound span kind
	Inbound
	// Outbound span kind
	Outbound
)

type SpanObserver

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

SpanObserver collects RPC metrics

func NewSpanObserver

func NewSpanObserver(
	metricsByEndpoint *MetricsByEndpoint,
	operationName string,
	options opentracing.StartSpanOptions,
) *SpanObserver

NewSpanObserver creates a new SpanObserver that can emit RPC metrics.

func (*SpanObserver) OnFinish

func (so *SpanObserver) OnFinish(options opentracing.FinishOptions)

OnFinish emits the RPC metrics. It only has an effect when operation name is not blank, and the span kind is an RPC server.

func (*SpanObserver) OnSetOperationName

func (so *SpanObserver) OnSetOperationName(operationName string)

OnSetOperationName records new operation name.

func (*SpanObserver) OnSetTag

func (so *SpanObserver) OnSetTag(key string, value interface{})

OnSetTag implements SpanObserver

Jump to

Keyboard shortcuts

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