diff --git a/example/example.go b/example/example.go index e657c12..885f45b 100644 --- a/example/example.go +++ b/example/example.go @@ -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 { diff --git a/interceptors/metrics/interceptors.go b/interceptors/metrics/interceptors.go index 0345958..9644d2f 100644 --- a/interceptors/metrics/interceptors.go +++ b/interceptors/metrics/interceptors.go @@ -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,7 +40,41 @@ type metrics struct { func (m *metrics) EnableHandlingTimeHistogram(opts ...grpc_prometheus.HistogramOption) { if m.s != nil { - m.s.EnableHandlingTimeHistogram(opts...) + 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...) + } } }