Documentation ¶
Overview ¶
Package metric provides functions to initialize the controller specific collectors and hooks to measure metrics and update the relevant collectors.
Package metric provides functions to initialize the controller specific collectors and hooks to measure metrics and update the relevant collectors.
Index ¶
- Constants
- Variables
- func InitializeApiCollectors(r prometheus.Registerer, v prometheus.ObserverVec, ...)
- func InitializeConnectionCounters(r prometheus.Registerer, counters []prometheus.CounterVec)
- func InitializeGrpcCollectorsFromPackage(r prometheus.Registerer, v prometheus.ObserverVec, ...)
- func InitializeGrpcCollectorsFromServer(r prometheus.Registerer, v prometheus.ObserverVec, server *grpc.Server, ...)
- func NewConnectionTrackingListener(l net.Listener, ac prometheus.Counter, cc prometheus.Counter) *connectionTrackingListener
- func NewGrpcRequestRecorder(fullMethodName string, reqLatency prometheus.ObserverVec) requestRecorder
- func NewStatsHandler(ctx context.Context, o prometheus.ObserverVec) (*statsHandler, error)
- func SplitMethodName(fullMethodName string) (string, string)
- func StatusFromError(err error) *status.Status
- type TestInvoker
- type TestableObserverVec
Constants ¶
const ( LabelConnectionType = "conn_type" LabelGrpcService = "grpc_service" LabelGrpcMethod = "grpc_method" LabelGrpcCode = "grpc_code" LabelHttpPath = "path" LabelHttpMethod = "method" LabelHttpCode = "code" )
Variables ¶
var ( ListGrpcLabels = []string{LabelGrpcService, LabelGrpcMethod, LabelGrpcCode} ListHttpLabels = []string{LabelHttpPath, LabelHttpMethod, LabelHttpCode} )
Functions ¶
func InitializeApiCollectors ¶
func InitializeApiCollectors(r prometheus.Registerer, v prometheus.ObserverVec, expectedPathsToMethods map[string][]string, expectedStatusCodesPerMethod map[string][]int)
InitializeApiCollectors registers and zeroes a Prometheus histogram, populating all path, code, and method labels from the provided maps in its parameters.
func InitializeConnectionCounters ¶
func InitializeConnectionCounters(r prometheus.Registerer, counters []prometheus.CounterVec)
func InitializeGrpcCollectorsFromPackage ¶
func InitializeGrpcCollectorsFromPackage(r prometheus.Registerer, v prometheus.ObserverVec, pkgs []protoreflect.FileDescriptor, codes []codes.Code, filter func(string, string) bool, )
InitializeGrpcCollectorsFromPackage registers and zeroes a Prometheus histogram, populating all service and method labels by ranging through the package containing the provided FileDescriptor. The filter function takes in a service name and method name and skips adding them as labels upon returning true. Note: inputting a protoreflect.FileDescriptor will populate all services and methods found in its package, not just methods associated with that specific FileDescriptor.
func InitializeGrpcCollectorsFromServer ¶
func InitializeGrpcCollectorsFromServer(r prometheus.Registerer, v prometheus.ObserverVec, server *grpc.Server, codes []codes.Code)
InitializeGrpcCollectorsFromServer registers and zeroes a Prometheus histogram, finding all service and method labels from the provided gRPC server.
func NewConnectionTrackingListener ¶
func NewConnectionTrackingListener(l net.Listener, ac prometheus.Counter, cc prometheus.Counter) *connectionTrackingListener
NewConnectionTrackingListener registers a new Prometheus gauge with an unique connection type label and wraps an existing listener to track when connections are accepted and closed. Multiple calls to Close() a listener connection will only decrement the gauge once. A call to Close() will decrement the gauge even if Close() errors.
func NewGrpcRequestRecorder ¶
func NewGrpcRequestRecorder(fullMethodName string, reqLatency prometheus.ObserverVec) requestRecorder
NewGrpcRequestRecorder creates a requestRecorder struct which is used to measure gRPC client request latencies.
func NewStatsHandler ¶
func NewStatsHandler(ctx context.Context, o prometheus.ObserverVec) (*statsHandler, error)
NewStatsHandler takes a request latency metric (prometheus.ObserverVec) and returns a grpc stats.Handler that updates the provided metric with the request latency.
func SplitMethodName ¶
SplitMethodName returns the service and the method name when given the full method name as provided by the grpc request handler.
func StatusFromError ¶
StatusFromError retrieves the *status.Status from the provided error. It'll attempt to unwrap the *status.Error, which is something status.FromError does not do.
Types ¶
type TestInvoker ¶
func (*TestInvoker) Invoke ¶
func (i *TestInvoker) Invoke(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, opts ...grpc.CallOption) error
type TestableObserverVec ¶
type TestableObserverVec struct { Observations []*testableObserver prometheus.ObserverVec }
testableObserverVec allows us to assert which observations are being made with which labels.
func (*TestableObserverVec) With ¶
func (v *TestableObserverVec) With(l prometheus.Labels) prometheus.Observer