metrics: fix registration

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2022-03-12 00:24:37 +01:00
parent 2832f13f3c
commit b1988e0458
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF

View File

@ -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}
}