github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/observer.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 "google.golang.org/grpc/codes" 7 ) 8 9 type ObserverMetrics interface { 10 RecordRPC(handler, rpc string, code codes.Code) 11 } 12 13 type ObserverCollector struct { 14 rpcs *prometheus.CounterVec 15 } 16 17 var _ ObserverMetrics = (*ObserverCollector)(nil) 18 19 func NewObserverCollector() *ObserverCollector { 20 return &ObserverCollector{ 21 rpcs: promauto.NewCounterVec(prometheus.CounterOpts{ 22 Namespace: namespaceObserver, 23 Subsystem: subsystemObserverGRPC, 24 Name: "handler_grpc_counter", 25 Help: "tracking error/success rate of each rpc for the observer service", 26 }, []string{"handler", "grpc_method", "grpc_code"}), 27 } 28 } 29 30 func (oc *ObserverCollector) RecordRPC(handler, rpc string, code codes.Code) { 31 oc.rpcs.With(prometheus.Labels{ 32 "handler": handler, 33 "grpc_method": rpc, 34 "grpc_code": code.String(), 35 }).Inc() 36 }