enhance: fix access log can't print SDK version when client connect (#29680)

Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
pull/30126/head
aoiasd 2024-01-22 17:22:54 +08:00 committed by GitHub
parent 6bfa826320
commit 4142743128
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 9 deletions

View File

@ -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"
@ -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 {

View File

@ -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() {