From a88178a5eaef499f0342729c51ae38d5cedf35a5 Mon Sep 17 00:00:00 2001 From: "zhenshan.cao" Date: Fri, 14 Apr 2023 15:30:29 +0800 Subject: [PATCH] Add slow log for read (#23272) Signed-off-by: zhenshan.cao --- internal/proxy/impl.go | 22 ++++++++++++++++++++++ internal/proxy/rpc_msg.go | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/internal/proxy/impl.go b/internal/proxy/impl.go index efa738cfa0..c36413b05a 100644 --- a/internal/proxy/impl.go +++ b/internal/proxy/impl.go @@ -22,6 +22,7 @@ import ( "os" "strconv" "sync" + "time" "github.com/cockroachdb/errors" "github.com/golang/protobuf/proto" @@ -59,6 +60,7 @@ import ( ) const moduleName = "Proxy" +const SlowReadSpan = time.Second * 5 // UpdateStateCode updates the state code of Proxy. func (node *Proxy) UpdateStateCode(code commonpb.StateCode) { @@ -2431,6 +2433,13 @@ func (node *Proxy) Search(ctx context.Context, request *milvuspb.SearchRequest) zap.Uint64("travel_timestamp", travelTs), zap.Uint64("guarantee_timestamp", guaranteeTs)) + defer func() { + span := tr.ElapseSpan() + if span >= SlowReadSpan { + log.Info(rpcSlow(method), zap.Duration("duration", span)) + } + }() + log.Debug( rpcReceived(method)) @@ -2610,6 +2619,19 @@ func (node *Proxy) Query(ctx context.Context, request *milvuspb.QueryRequest) (* zap.String("collection", request.CollectionName), zap.Strings("partitions", request.PartitionNames)) + defer func() { + span := tr.ElapseSpan() + if span >= SlowReadSpan { + log.Info( + rpcSlow(method), + zap.String("expr", request.Expr), + zap.Strings("OutputFields", request.OutputFields), + zap.Uint64("travel_timestamp", request.TravelTimestamp), + zap.Uint64("guarantee_timestamp", request.GuaranteeTimestamp), + zap.Duration("duration", span)) + } + }() + log.Debug( rpcReceived(method), zap.String("expr", request.Expr), diff --git a/internal/proxy/rpc_msg.go b/internal/proxy/rpc_msg.go index 5960384a70..af7331a85a 100644 --- a/internal/proxy/rpc_msg.go +++ b/internal/proxy/rpc_msg.go @@ -30,6 +30,10 @@ func rpcDone(method string) string { return fmt.Sprintf("%s done", method) } +func rpcSlow(method string) string { + return fmt.Sprintf("%s slow", method) +} + func rpcFailedToEnqueue(method string) string { return fmt.Sprintf("%s failed to enqueue", method) }