From d61f0e9d760d72fc0c681f199d4a6522f8019770 Mon Sep 17 00:00:00 2001 From: Adphi Date: Sat, 12 Mar 2022 00:40:16 +0100 Subject: [PATCH] metrics: add server interceptor missing prometheus collector wrapped method Signed-off-by: Adphi --- interceptors/metrics/interceptors.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/interceptors/metrics/interceptors.go b/interceptors/metrics/interceptors.go index 6918e3c..d840a0b 100644 --- a/interceptors/metrics/interceptors.go +++ b/interceptors/metrics/interceptors.go @@ -2,6 +2,7 @@ package metrics import ( grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/prometheus/client_golang/prometheus" "google.golang.org/grpc" "go.linka.cloud/grpc/interceptors" @@ -13,13 +14,14 @@ type Registerer interface { } type Interceptors interface { - interceptors.Interceptors - Registerer + ServerInterceptors + ClientInterceptors } type ServerInterceptors interface { - interceptors.ServerInterceptors Registerer + interceptors.ServerInterceptors + prometheus.Collector } type ClientInterceptors interface { @@ -31,6 +33,18 @@ type metrics struct { c *grpc_prometheus.ClientMetrics } +func (m *metrics) Describe(descs chan<- *prometheus.Desc) { + if m.s != nil { + m.s.Describe(descs) + } +} + +func (m *metrics) Collect(c chan<- prometheus.Metric) { + if m.s != nil { + m.s.Collect(c) + } +} + func (m *metrics) Register(svc service.Service) { if m.s != nil { m.s.InitializeMetrics(svc)