mirror of
				https://github.com/linka-cloud/grpc.git
				synced 2025-10-31 01:22:29 +00:00 
			
		
		
		
	metrics: fix registration
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
		| @@ -5,42 +5,63 @@ import ( | ||||
| 	"google.golang.org/grpc" | ||||
|  | ||||
| 	"go.linka.cloud/grpc/interceptors" | ||||
| 	"go.linka.cloud/grpc/service" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	Register = grpc_prometheus.Register | ||||
| ) | ||||
| type Registerer interface { | ||||
| 	Register(svc service.Service) | ||||
| } | ||||
|  | ||||
| type Interceptors interface { | ||||
| 	interceptors.Interceptors | ||||
| 	Registerer | ||||
| } | ||||
|  | ||||
| type ServerInterceptors interface { | ||||
| 	interceptors.ServerInterceptors | ||||
| 	Registerer | ||||
| } | ||||
|  | ||||
| type ClientInterceptors interface { | ||||
| 	interceptors.ClientInterceptors | ||||
| } | ||||
|  | ||||
| type metrics struct { | ||||
| 	s *grpc_prometheus.ServerMetrics | ||||
| 	c *grpc_prometheus.ClientMetrics | ||||
| } | ||||
|  | ||||
| func NewInterceptors(opts ...grpc_prometheus.CounterOption) interceptors.Interceptors { | ||||
| func (m *metrics) Register(svc service.Service) { | ||||
| 	if m.s != nil { | ||||
| 		m.s.InitializeMetrics(svc) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func NewInterceptors(opts ...grpc_prometheus.CounterOption) Interceptors { | ||||
| 	s := grpc_prometheus.NewServerMetrics(opts...) | ||||
| 	c := grpc_prometheus.NewClientMetrics(opts...) | ||||
| 	return &metrics{s: s, c: c} | ||||
| } | ||||
|  | ||||
| func NewServerInterceptors(opts ...grpc_prometheus.CounterOption) interceptors.ServerInterceptors { | ||||
| func NewServerInterceptors(opts ...grpc_prometheus.CounterOption) ServerInterceptors { | ||||
| 	s := grpc_prometheus.NewServerMetrics(opts...) | ||||
| 	return &metrics{s: s} | ||||
| } | ||||
|  | ||||
| func NewClientInterceptors(opts ...grpc_prometheus.CounterOption) interceptors.ClientInterceptors { | ||||
| func NewClientInterceptors(opts ...grpc_prometheus.CounterOption) ClientInterceptors { | ||||
| 	c := grpc_prometheus.NewClientMetrics(opts...) | ||||
| 	return &metrics{c: c} | ||||
| } | ||||
|  | ||||
| func DefaultInterceptors() interceptors.Interceptors { | ||||
| func DefaultInterceptors() Interceptors { | ||||
| 	return &metrics{s: grpc_prometheus.DefaultServerMetrics, c: grpc_prometheus.DefaultClientMetrics} | ||||
| } | ||||
|  | ||||
| func DefaultServerInterceptors() interceptors.ServerInterceptors { | ||||
| func DefaultServerInterceptors() ServerInterceptors { | ||||
| 	return &metrics{s: grpc_prometheus.DefaultServerMetrics} | ||||
| } | ||||
|  | ||||
| func DefaultClientInterceptors() interceptors.ClientInterceptors { | ||||
| func DefaultClientInterceptors() ClientInterceptors { | ||||
| 	return &metrics{c: grpc_prometheus.DefaultClientMetrics} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user