Add tracing and metrics #3

Merged
fyrchik merged 1 commit from dstepanov-yadro/frostfs-observability:feat/tracing into master 2023-07-26 21:08:06 +00:00
2 changed files with 59 additions and 0 deletions
Showing only changes of commit c97d21411e - Show all commits

31
metrics/grpc/client.go Normal file
View 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
View 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()
}