metric

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

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

View Source
const (
	LabelConnectionType = "conn_type"
	LabelGrpcService    = "grpc_service"
	LabelGrpcMethod     = "grpc_method"
	LabelGrpcCode       = "grpc_code"
	LabelHttpPath       = "path"
	LabelHttpMethod     = "method"
	LabelHttpCode       = "code"
)

Variables

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

func SplitMethodName(fullMethodName string) (string, string)

SplitMethodName returns the service and the method name when given the full method name as provided by the grpc request handler.

func StatusFromError

func StatusFromError(err error) *status.Status

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

type TestInvoker struct {
	T      *testing.T
	Called bool
	RetErr error
}

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

Jump to

Keyboard shortcuts

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