[#3] metrics: Add gRPC middleware
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
3c1b76ee51
commit
c97d21411e
2 changed files with 59 additions and 0 deletions
31
metrics/grpc/client.go
Normal file
31
metrics/grpc/client.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package grpc
|
||||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var clientMetrics *grpcprom.ClientMetrics = grpcprom.NewClientMetrics(
|
||||
grpcprom.WithClientHandlingTimeHistogram(
|
||||
grpcprom.WithHistogramBuckets(prometheus.DefBuckets),
|
||||
),
|
||||
grpcprom.WithClientStreamRecvHistogram(
|
||||
grpcprom.WithHistogramBuckets(prometheus.DefBuckets),
|
||||
),
|
||||
)
|
||||
|
||||
func init() {
|
||||
metrics.Register(clientMetrics)
|
||||
}
|
||||
|
||||
// NewUnaryClientInterceptor returns client interceptor to collect metrics from unary RPCs.
|
||||
func NewUnaryClientInterceptor() grpc.UnaryClientInterceptor {
|
||||
return clientMetrics.UnaryClientInterceptor()
|
||||
}
|
||||
|
||||
// NewStreamClientInterceptor returns client interceptor to collect metrics from stream RPCs.
|
||||
func NewStreamClientInterceptor() grpc.StreamClientInterceptor {
|
||||
return clientMetrics.StreamClientInterceptor()
|
||||
}
|
28
metrics/grpc/server.go
Normal file
28
metrics/grpc/server.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package grpc
|
||||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var serverMetrics *grpcprom.ServerMetrics = grpcprom.NewServerMetrics(
|
||||
grpcprom.WithServerHandlingTimeHistogram(
|
||||
grpcprom.WithHistogramBuckets(prometheus.DefBuckets),
|
||||
),
|
||||
)
|
||||
|
||||
func init() {
|
||||
metrics.Register(serverMetrics)
|
||||
}
|
||||
|
||||
// NewUnaryServerInterceptor returns server interceptor to collect metrics from unary RPCs.
|
||||
func NewUnaryServerInterceptor() grpc.UnaryServerInterceptor {
|
||||
return serverMetrics.UnaryServerInterceptor()
|
||||
}
|
||||
|
||||
// NewStreamServerInterceptor returns server interceptor to collect metrics from stream RPCs.
|
||||
func NewStreamServerInterceptor() grpc.StreamServerInterceptor {
|
||||
return serverMetrics.StreamServerInterceptor()
|
||||
}
|
Loading…
Reference in a new issue