mirror of https://github.com/milvus-io/milvus.git
enhance: fix access log can't print SDK version when client connect (#29680)
Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>pull/30126/head
parent
6bfa826320
commit
4142743128
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue