Skip to content

Commit b6f2517

Browse files
authored
enhance: support print nq and params for search and query (#41802)
relate: #41801 Signed-off-by: aoiasd <[email protected]>
1 parent f2a8330 commit b6f2517

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

configs/milvus.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ proxy:
315315
base:
316316
format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost]"
317317
query:
318-
format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [expr: $method_expr]"
318+
format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [expr: $method_expr] [params: $query_params]"
319319
methods: "Query, Delete"
320320
search:
321-
format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [anns_field: $anns_field] [expr: $method_expr]"
321+
format: "[$time_now] [ACCESS] <$user_name: $user_addr> $method_name [status: $method_status] [code: $error_code] [sdk: $sdk_version] [msg: $error_msg] [traceID: $trace_id] [timeCost: $time_cost] [database: $database_name] [collection: $collection_name] [partitions: $partition_name] [expr: $method_expr] [nq: $nq] [params: $search_params]"
322322
methods: "HybridSearch, Search"
323323
cacheSize: 0 # Size of log of write cache, in byte. (Close write cache if size was 0)
324324
cacheFlushInterval: 3 # time interval of auto flush write cache, in seconds. (Close auto flush if interval was 0)

internal/proxy/accesslog/info/grpc_info.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,32 @@ func (i *GrpcAccessInfo) AnnsField() string {
316316
}
317317
return Unknown
318318
}
319+
320+
func (i *GrpcAccessInfo) NQ() string {
321+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
322+
return fmt.Sprint(req.GetNq())
323+
}
324+
325+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
326+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return fmt.Sprint(req.GetNq()) }))
327+
}
328+
return Unknown
329+
}
330+
331+
func (i *GrpcAccessInfo) SearchParams() string {
332+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
333+
return kvsToString(req.GetSearchParams())
334+
}
335+
336+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
337+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return kvsToString(req.GetSearchParams()) }))
338+
}
339+
return Unknown
340+
}
341+
342+
func (i *GrpcAccessInfo) QueryParams() string {
343+
if req, ok := i.req.(*milvuspb.QueryRequest); ok {
344+
return kvsToString(req.GetQueryParams())
345+
}
346+
return Unknown
347+
}

internal/proxy/accesslog/info/info.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ var MetricFuncMap = map[string]getMetricFunc{
4848
"$cluster_prefix": getClusterPrefix,
4949
"$consistency_level": getConsistencyLevel,
5050
"$anns_field": getAnnsField,
51+
"$nq": getNq,
52+
"$search_params": getSearchParams,
53+
"$query_params": getQueryParams,
5154
}
5255

5356
type AccessInfo interface {
@@ -72,6 +75,9 @@ type AccessInfo interface {
7275
OutputFields() string
7376
SdkVersion() string
7477
ConsistencyLevel() string
78+
NQ() string
79+
SearchParams() string
80+
QueryParams() string
7581
}
7682

7783
func Get(i AccessInfo, keys ...string) []any {
@@ -174,3 +180,15 @@ func getAnnsField(i AccessInfo) string {
174180
func getClusterPrefix(i AccessInfo) string {
175181
return ClusterPrefix.Load()
176182
}
183+
184+
func getNq(i AccessInfo) string {
185+
return i.NQ()
186+
}
187+
188+
func getSearchParams(i AccessInfo) string {
189+
return i.SearchParams()
190+
}
191+
192+
func getQueryParams(i AccessInfo) string {
193+
return i.QueryParams()
194+
}

internal/proxy/accesslog/info/restful_info.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,32 @@ func (i *RestfulInfo) AnnsField() string {
226226
}
227227
return Unknown
228228
}
229+
230+
func (i *RestfulInfo) NQ() string {
231+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
232+
return fmt.Sprint(req.GetNq())
233+
}
234+
235+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
236+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return fmt.Sprint(req.GetNq()) }))
237+
}
238+
return Unknown
239+
}
240+
241+
func (i *RestfulInfo) SearchParams() string {
242+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
243+
return kvsToString(req.GetSearchParams())
244+
}
245+
246+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
247+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return kvsToString(req.GetSearchParams()) }))
248+
}
249+
return Unknown
250+
}
251+
252+
func (i *RestfulInfo) QueryParams() string {
253+
if req, ok := i.req.(*milvuspb.QueryRequest); ok {
254+
return kvsToString(req.GetQueryParams())
255+
}
256+
return Unknown
257+
}

internal/proxy/accesslog/info/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ func listToString(strs []string) string {
111111
}
112112
return result + "]"
113113
}
114+
115+
func kvsToString(kvs []*commonpb.KeyValuePair) string {
116+
str := "{"
117+
for _, kv := range kvs {
118+
str += fmt.Sprintf("%s:%s,", kv.GetKey(), kv.GetValue())
119+
}
120+
return str + "}"
121+
}

0 commit comments

Comments
 (0)