From ad4a53d225fa650dcd88fc43633cbd5acb83e375 Mon Sep 17 00:00:00 2001 From: aoiasd <45024769+aoiasd@users.noreply.github.com> Date: Sun, 4 Feb 2024 16:37:07 +0800 Subject: [PATCH] enhance: [Cherry-Pick] Fix some access log bugs (#30496) pr: https://github.com/milvus-io/milvus/pull/30409 https://github.com/milvus-io/milvus/pull/29680 --------- Signed-off-by: aoiasd --- internal/proxy/accesslog/info.go | 16 +++++++++++----- internal/proxy/accesslog/info_test.go | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/internal/proxy/accesslog/info.go b/internal/proxy/accesslog/info.go index 85e0e4f88d..2280951121 100644 --- a/internal/proxy/accesslog/info.go +++ b/internal/proxy/accesslog/info.go @@ -30,6 +30,7 @@ import ( "google.golang.org/grpc/status" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" + "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" "github.com/milvus-io/milvus/internal/proxy/connection" "github.com/milvus-io/milvus/pkg/util/merr" "github.com/milvus-io/milvus/pkg/util/paramtable" @@ -165,11 +166,11 @@ func getMethodStatus(i *GrpcAccessInfo) string { return fmt.Sprintf("Grpc%s", code.String()) } - if i.status.GetCode() != 0 { + if i.status.GetCode() != 0 || i.err != nil { return "Failed" } - return code.String() + return "Successful" } func getUserName(i *GrpcAccessInfo) string { @@ -268,10 +269,15 @@ func getExpr(i *GrpcAccessInfo) string { func getSdkVersion(i *GrpcAccessInfo) string { clientInfo := connection.GetManager().Get(i.ctx) - if clientInfo == nil { - return unknownString + if clientInfo != nil { + return clientInfo.SdkType + "-" + clientInfo.SdkVersion } - return clientInfo.SdkType + "-" + clientInfo.SdkVersion + + if req, ok := i.req.(*milvuspb.ConnectRequest); ok { + return req.ClientInfo.SdkType + "-" + req.ClientInfo.SdkVersion + } + + return unknownString } func getClusterPrefix(i *GrpcAccessInfo) string { diff --git a/internal/proxy/accesslog/info_test.go b/internal/proxy/accesslog/info_test.go index d2c4215268..0a39176bfc 100644 --- a/internal/proxy/accesslog/info_test.go +++ b/internal/proxy/accesslog/info_test.go @@ -113,22 +113,29 @@ func (s *GrpcAccessInfoSuite) TestDbName() { func (s *GrpcAccessInfoSuite) TestSdkInfo() { ctx := context.Background() + clientInfo := &commonpb.ClientInfo{ + SdkType: "test", + SdkVersion: "1.0", + } + s.info.ctx = ctx result := s.info.Get("$sdk_version") s.Equal(unknownString, result[0]) + s.info.req = &milvuspb.ConnectRequest{ + ClientInfo: clientInfo, + } + result = s.info.Get("$sdk_version") + s.Equal(clientInfo.SdkType+"-"+clientInfo.SdkVersion, result[0]) + identifier := 11111 md := metadata.MD{util.IdentifierKey: []string{fmt.Sprint(identifier)}} ctx = metadata.NewIncomingContext(ctx, md) - info := &commonpb.ClientInfo{ - SdkType: "test", - SdkVersion: "1.0", - } - connection.GetManager().Register(ctx, int64(identifier), info) + connection.GetManager().Register(ctx, int64(identifier), clientInfo) s.info.ctx = ctx result = s.info.Get("$sdk_version") - s.Equal(info.SdkType+"-"+info.SdkVersion, result[0]) + s.Equal(clientInfo.SdkType+"-"+clientInfo.SdkVersion, result[0]) } func (s *GrpcAccessInfoSuite) TestExpression() {