frostfs-observability/metrics/grpc/client.go
Dmitrii Stepanov c97d21411e [#3] metrics: Add gRPC middleware
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-31 11:27:42 +03:00

31 lines
985 B
Go

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()
}