metrics interceptors: fix default server registration

metrics interceptors: add missing client histogram methods

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2022-11-06 22:51:03 +01:00
parent dcd2f18f65
commit 01b37a0d91
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF
2 changed files with 41 additions and 2 deletions

View File

@ -110,7 +110,7 @@ func run(opts ...service.Option) {
ready := make(chan struct{})
var svc service.Service
var err error
metrics := metrics2.NewInterceptors()
metrics := metrics2.DefaultInterceptors()
validation := validation2.NewInterceptors(true)
defaulter := defaulter.NewInterceptors()
address := "0.0.0.0:9991"
@ -156,6 +156,7 @@ func run(opts ...service.Option) {
panic(err)
}
RegisterGreeterServer(svc, &GreeterHandler{})
metrics.EnableHandlingTimeHistogram()
metrics.Register(svc)
go func() {
if err := svc.Start(); err != nil {

View File

@ -23,6 +23,10 @@ type ServerInterceptors interface {
interceptors.ServerInterceptors
prometheus.Collector
EnableHandlingTimeHistogram(opts ...grpc_prometheus.HistogramOption)
EnableClientHandlingTimeHistogram(opts ...grpc_prometheus.HistogramOption)
EnableClientStreamReceiveTimeHistogram(opts ...grpc_prometheus.HistogramOption)
EnableClientStreamSendTimeHistogram(opts ...grpc_prometheus.HistogramOption)
}
type ClientInterceptors interface {
@ -36,9 +40,43 @@ type metrics struct {
func (m *metrics) EnableHandlingTimeHistogram(opts ...grpc_prometheus.HistogramOption) {
if m.s != nil {
if m.s == grpc_prometheus.DefaultServerMetrics {
grpc_prometheus.EnableHandlingTimeHistogram(opts...)
} else {
m.s.EnableHandlingTimeHistogram(opts...)
}
}
}
func (m *metrics) EnableClientHandlingTimeHistogram(opts ...grpc_prometheus.HistogramOption) {
if m.c != nil {
if m.c == grpc_prometheus.DefaultClientMetrics {
grpc_prometheus.EnableClientHandlingTimeHistogram(opts...)
} else {
m.c.EnableClientHandlingTimeHistogram(opts...)
}
}
}
func (m *metrics) EnableClientStreamReceiveTimeHistogram(opts ...grpc_prometheus.HistogramOption) {
if m.c != nil {
if m.c == grpc_prometheus.DefaultClientMetrics {
grpc_prometheus.EnableClientStreamReceiveTimeHistogram(opts...)
} else {
m.c.EnableClientStreamReceiveTimeHistogram(opts...)
}
}
}
func (m *metrics) EnableClientStreamSendTimeHistogram(opts ...grpc_prometheus.HistogramOption) {
if m.c != nil {
if m.c == grpc_prometheus.DefaultClientMetrics {
grpc_prometheus.EnableClientStreamSendTimeHistogram(opts...)
} else {
m.c.EnableClientStreamSendTimeHistogram(opts...)
}
}
}
func (m *metrics) Describe(descs chan<- *prometheus.Desc) {
if m.s != nil {