Skip to content

Commit 515ad5d

Browse files
committed
common: update instrumentGRPC to consider context error
align with GRPC itself
1 parent 495239f commit 515ad5d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/common/interceptors.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ func instrumentGRPC(driverType string) grpc.UnaryServerInterceptor {
3939
}
4040

4141
func recordExecTime(time time.Duration, method, driverType string, err error) {
42+
// copied from google.golang.org/grpc/server.go
43+
appStatus, ok := status.FromError(err)
44+
if !ok {
45+
// Convert non-status application error to a status error with code
46+
// Unknown, but handle context errors specifically.
47+
appStatus = status.FromContextError(err)
48+
}
49+
4250
labels := prometheus.Labels{
4351
metric.CsiGrpcExecTimeLabelMethod: method,
4452
metric.CsiGrpcExecTimeLabelType: driverType,
45-
metric.CsiGrpcExecTimeLabelCode: status.Code(err).String(),
53+
metric.CsiGrpcExecTimeLabelCode: appStatus.Code().String(),
4654
}
4755
metric.CsiGrpcExecTimeCollector.ExecCountMetric.With(labels).Inc()
4856
metric.CsiGrpcExecTimeCollector.ExecTimeTotalMetric.With(labels).Add(time.Seconds())

0 commit comments

Comments
 (0)