Files
weave-scope/vendor/github.com/weaveworks/common/middleware/grpc_instrumentation.go
2017-02-24 13:43:06 +00:00

24 lines
700 B
Go

package middleware
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// ServerInstrumentInterceptor instruments gRPC requests for errors and latency.
func ServerInstrumentInterceptor(duration *prometheus.HistogramVec) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
begin := time.Now()
resp, err := handler(ctx, req)
status := "success"
if err != nil {
status = "error"
}
duration.WithLabelValues(gRPC, info.FullMethod, status, "false").Observe(time.Since(begin).Seconds())
return resp, err
}
}