Documentation ¶
Overview ¶
Package rpcmetrics implements an Observer that can be used to emit RPC metrics.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 Metrics ¶
type Metrics struct { // Requests is a counter of the total number of successes + failures. Requests metrics.Counter `metric:"requests"` // Success is a counter of the total number of successes. Success metrics.Counter `metric:"success"` // Failures is a counter of the number of times any failure has been observed. Failures metrics.Counter `metric:"failures"` // RequestLatencyMs is a histogram of the latency of requests in milliseconds. RequestLatencyMs metrics.Timer `metric:"request_latency_ms"` // HTTPStatusCode2xx is a counter of the total number of requests with HTTP status code 200-299 HTTPStatusCode2xx metrics.Counter `metric:"http_status_code_2xx"` // HTTPStatusCode3xx is a counter of the total number of requests with HTTP status code 300-399 HTTPStatusCode3xx metrics.Counter `metric:"http_status_code_3xx"` // HTTPStatusCode4xx is a counter of the total number of requests with HTTP status code 400-499 HTTPStatusCode4xx metrics.Counter `metric:"http_status_code_4xx"` // HTTPStatusCode5xx is a counter of the total number of requests with HTTP status code 500-599 HTTPStatusCode5xx metrics.Counter `metric:"http_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 ¶
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: %d\n", c["requests|endpoint=test"]) fmt.Printf("success: %d\n", c["success|endpoint=test"]) fmt.Printf("errors: %d\n", c["errors|endpoint=test"])
Output: requests: 1 success: 1 errors: 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 SafeCharacterSet ¶
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 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