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 { // 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 ¶
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 := u.NewFactory(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 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