mirror of https://github.com/milvus-io/milvus.git
enhance: access log support print with consistency level (#33503)
relate: https://github.com/milvus-io/milvus/issues/33563 Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>pull/33641/head
parent
01ce32caa1
commit
b9bafc76b4
|
@ -262,3 +262,11 @@ func (i *GrpcAccessInfo) OutputFields() string {
|
||||||
}
|
}
|
||||||
return Unknown
|
return Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *GrpcAccessInfo) ConsistencyLevel() string {
|
||||||
|
level, ok := requestutil.GetConsistencyLevelFromRequst(i.req)
|
||||||
|
if ok {
|
||||||
|
return level.String()
|
||||||
|
}
|
||||||
|
return Unknown
|
||||||
|
}
|
||||||
|
|
|
@ -190,6 +190,17 @@ func (s *GrpcAccessInfoSuite) TestOutputFields() {
|
||||||
s.Equal(fmt.Sprint(fields), result[0])
|
s.Equal(fmt.Sprint(fields), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GrpcAccessInfoSuite) TestConsistencyLevel() {
|
||||||
|
result := Get(s.info, "$consistency_level")
|
||||||
|
s.Equal(Unknown, result[0])
|
||||||
|
|
||||||
|
s.info.req = &milvuspb.QueryRequest{
|
||||||
|
ConsistencyLevel: commonpb.ConsistencyLevel_Bounded,
|
||||||
|
}
|
||||||
|
result = Get(s.info, "$consistency_level")
|
||||||
|
s.Equal(commonpb.ConsistencyLevel_Bounded.String(), result[0])
|
||||||
|
}
|
||||||
|
|
||||||
func (s *GrpcAccessInfoSuite) TestClusterPrefix() {
|
func (s *GrpcAccessInfoSuite) TestClusterPrefix() {
|
||||||
cluster := "instance-test"
|
cluster := "instance-test"
|
||||||
paramtable.Init()
|
paramtable.Init()
|
||||||
|
|
|
@ -26,25 +26,26 @@ type getMetricFunc func(i AccessInfo) string
|
||||||
|
|
||||||
// supported metrics
|
// supported metrics
|
||||||
var MetricFuncMap = map[string]getMetricFunc{
|
var MetricFuncMap = map[string]getMetricFunc{
|
||||||
"$method_name": getMethodName,
|
"$method_name": getMethodName,
|
||||||
"$method_status": getMethodStatus,
|
"$method_status": getMethodStatus,
|
||||||
"$trace_id": getTraceID,
|
"$trace_id": getTraceID,
|
||||||
"$user_addr": getAddr,
|
"$user_addr": getAddr,
|
||||||
"$user_name": getUserName,
|
"$user_name": getUserName,
|
||||||
"$response_size": getResponseSize,
|
"$response_size": getResponseSize,
|
||||||
"$error_code": getErrorCode,
|
"$error_code": getErrorCode,
|
||||||
"$error_msg": getErrorMsg,
|
"$error_msg": getErrorMsg,
|
||||||
"$database_name": getDbName,
|
"$database_name": getDbName,
|
||||||
"$collection_name": getCollectionName,
|
"$collection_name": getCollectionName,
|
||||||
"$partition_name": getPartitionName,
|
"$partition_name": getPartitionName,
|
||||||
"$time_cost": getTimeCost,
|
"$time_cost": getTimeCost,
|
||||||
"$time_now": getTimeNow,
|
"$time_now": getTimeNow,
|
||||||
"$time_start": getTimeStart,
|
"$time_start": getTimeStart,
|
||||||
"$time_end": getTimeEnd,
|
"$time_end": getTimeEnd,
|
||||||
"$method_expr": getExpr,
|
"$method_expr": getExpr,
|
||||||
"$output_fields": getOutputFields,
|
"$output_fields": getOutputFields,
|
||||||
"$sdk_version": getSdkVersion,
|
"$sdk_version": getSdkVersion,
|
||||||
"$cluster_prefix": getClusterPrefix,
|
"$cluster_prefix": getClusterPrefix,
|
||||||
|
"$consistency_level": getConsistencyLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessInfo interface {
|
type AccessInfo interface {
|
||||||
|
@ -66,6 +67,7 @@ type AccessInfo interface {
|
||||||
Expression() string
|
Expression() string
|
||||||
OutputFields() string
|
OutputFields() string
|
||||||
SdkVersion() string
|
SdkVersion() string
|
||||||
|
ConsistencyLevel() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get(i AccessInfo, keys ...string) []any {
|
func Get(i AccessInfo, keys ...string) []any {
|
||||||
|
@ -153,6 +155,10 @@ func getOutputFields(i AccessInfo) string {
|
||||||
return i.OutputFields()
|
return i.OutputFields()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getConsistencyLevel(i AccessInfo) string {
|
||||||
|
return i.ConsistencyLevel()
|
||||||
|
}
|
||||||
|
|
||||||
func getClusterPrefix(i AccessInfo) string {
|
func getClusterPrefix(i AccessInfo) string {
|
||||||
return ClusterPrefix.Load()
|
return ClusterPrefix.Load()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package info
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -35,10 +34,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type RestfulInfo struct {
|
type RestfulInfo struct {
|
||||||
params *gin.LogFormatterParams
|
params *gin.LogFormatterParams
|
||||||
start time.Time
|
start time.Time
|
||||||
req interface{}
|
req interface{}
|
||||||
reqInitOnce sync.Once
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRestfulInfo() *RestfulInfo {
|
func NewRestfulInfo() *RestfulInfo {
|
||||||
|
@ -187,3 +185,11 @@ func (i *RestfulInfo) OutputFields() string {
|
||||||
}
|
}
|
||||||
return Unknown
|
return Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *RestfulInfo) ConsistencyLevel() string {
|
||||||
|
level, ok := requestutil.GetConsistencyLevelFromRequst(i.req)
|
||||||
|
if ok {
|
||||||
|
return level.String()
|
||||||
|
}
|
||||||
|
return Unknown
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"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-proto/go-api/v2/milvuspb"
|
||||||
"github.com/milvus-io/milvus/pkg/util/merr"
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
||||||
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
||||||
|
@ -178,6 +179,18 @@ func (s *RestfulAccessInfoSuite) TestOutputFields() {
|
||||||
s.Equal(fmt.Sprint(fields), result[0])
|
s.Equal(fmt.Sprint(fields), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *RestfulAccessInfoSuite) TestConsistencyLevel() {
|
||||||
|
result := Get(s.info, "$consistency_level")
|
||||||
|
s.Equal(Unknown, result[0])
|
||||||
|
|
||||||
|
s.info.params.Keys[ContextRequest] = &milvuspb.QueryRequest{
|
||||||
|
ConsistencyLevel: commonpb.ConsistencyLevel_Bounded,
|
||||||
|
}
|
||||||
|
s.info.InitReq()
|
||||||
|
result = Get(s.info, "$consistency_level")
|
||||||
|
s.Equal(commonpb.ConsistencyLevel_Bounded.String(), result[0])
|
||||||
|
}
|
||||||
|
|
||||||
func (s *RestfulAccessInfoSuite) TestClusterPrefix() {
|
func (s *RestfulAccessInfoSuite) TestClusterPrefix() {
|
||||||
cluster := "instance-test"
|
cluster := "instance-test"
|
||||||
paramtable.Init()
|
paramtable.Init()
|
||||||
|
|
|
@ -156,6 +156,18 @@ func GetStatusFromResponse(resp interface{}) (*commonpb.Status, bool) {
|
||||||
return getter.GetStatus(), true
|
return getter.GetStatus(), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConsistencyLevelGetter interface {
|
||||||
|
GetConsistencyLevel() commonpb.ConsistencyLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetConsistencyLevelFromRequst(req interface{}) (commonpb.ConsistencyLevel, bool) {
|
||||||
|
getter, ok := req.(ConsistencyLevelGetter)
|
||||||
|
if !ok {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return getter.GetConsistencyLevel(), true
|
||||||
|
}
|
||||||
|
|
||||||
var TraceLogBaseInfoFuncMap = map[string]func(interface{}) (any, bool){
|
var TraceLogBaseInfoFuncMap = map[string]func(interface{}) (any, bool){
|
||||||
"collection_name": GetCollectionNameFromRequest,
|
"collection_name": GetCollectionNameFromRequest,
|
||||||
"db_name": GetDbNameFromRequest,
|
"db_name": GetDbNameFromRequest,
|
||||||
|
|
Loading…
Reference in New Issue