update:Use the Milliseconds method of duration to get the number of milliseconds (#3285)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package clientinterceptors
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
@@ -37,7 +36,7 @@ func PrometheusInterceptor(ctx context.Context, method string, req, reply any,
|
||||
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
startTime := timex.Now()
|
||||
err := invoker(ctx, method, req, reply, cc, opts...)
|
||||
metricClientReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), method)
|
||||
metricClientReqDur.Observe(timex.Since(startTime).Milliseconds(), method)
|
||||
metricClientReqCodeTotal.Inc(method, strconv.Itoa(int(status.Code(err))))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package serverinterceptors
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/metric"
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
@@ -37,7 +36,7 @@ func UnaryPrometheusInterceptor(ctx context.Context, req any,
|
||||
info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
||||
startTime := timex.Now()
|
||||
resp, err := handler(ctx, req)
|
||||
metricServerReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), info.FullMethod)
|
||||
metricServerReqDur.Observe(timex.Since(startTime).Milliseconds(), info.FullMethod)
|
||||
metricServerReqCodeTotal.Inc(info.FullMethod, strconv.Itoa(int(status.Code(err))))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user