Skip to content

Commit 0e75e66

Browse files
authored
enhance: accesslog support fetch hybrid search expr and field (#40167) (#41921)
relate: #40166 pr: #40167 Signed-off-by: aoiasd <[email protected]>
1 parent 7fc7e51 commit 0e75e66

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

configs/milvus.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ proxy:
303303
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]"
304304
query:
305305
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]"
306-
methods: "Query,Search,Delete"
306+
methods: "Query, Delete"
307+
search:
308+
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]"
309+
methods: "HybridSearch, Search"
307310
cacheSize: 0 # Size of log of write cache, in byte. (Close write cache if size was 0)
308311
cacheFlushInterval: 3 # time interval of auto flush write cache, in seconds. (Close auto flush if interval was 0)
309312
connectionCheckIntervalSeconds: 120 # the interval time(in seconds) for connection manager to scan inactive client info

internal/proxy/accesslog/info/grpc_info.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/samber/lo"
2627
"go.opentelemetry.io/otel/trace"
2728
"google.golang.org/grpc"
2829
"google.golang.org/grpc/codes"
@@ -264,6 +265,10 @@ func (i *GrpcAccessInfo) Expression() string {
264265
return expr.(string)
265266
}
266267

268+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
269+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return req.GetDsl() }))
270+
}
271+
267272
dsl, ok := requestutil.GetDSLFromRequest(i.req)
268273
if ok {
269274
return dsl.(string)
@@ -299,3 +304,15 @@ func (i *GrpcAccessInfo) ConsistencyLevel() string {
299304
}
300305
return Unknown
301306
}
307+
308+
func (i *GrpcAccessInfo) AnnsField() string {
309+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
310+
return getAnnsFieldFromKvs(req.GetSearchParams())
311+
}
312+
313+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
314+
fields := lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return getAnnsFieldFromKvs(req.GetSearchParams()) })
315+
return listToString(fields)
316+
}
317+
return Unknown
318+
}

internal/proxy/accesslog/info/info.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var MetricFuncMap = map[string]getMetricFunc{
4747
"$sdk_version": getSdkVersion,
4848
"$cluster_prefix": getClusterPrefix,
4949
"$consistency_level": getConsistencyLevel,
50+
"$anns_field": getAnnsField,
5051
}
5152

5253
type AccessInfo interface {
@@ -64,6 +65,7 @@ type AccessInfo interface {
6465
ErrorMsg() string
6566
ErrorType() string
6667
DbName() string
68+
AnnsField() string
6769
CollectionName() string
6870
PartitionName() string
6971
Expression() string
@@ -165,6 +167,10 @@ func getConsistencyLevel(i AccessInfo) string {
165167
return i.ConsistencyLevel()
166168
}
167169

170+
func getAnnsField(i AccessInfo) string {
171+
return i.AnnsField()
172+
}
173+
168174
func getClusterPrefix(i AccessInfo) string {
169175
return ClusterPrefix.Load()
170176
}

internal/proxy/accesslog/info/restful_info.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"time"
2424

2525
"github.com/gin-gonic/gin"
26+
"github.com/samber/lo"
2627

28+
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
2729
"github.com/milvus-io/milvus/pkg/v2/util/requestutil"
2830
)
2931

@@ -187,6 +189,10 @@ func (i *RestfulInfo) Expression() string {
187189
return expr.(string)
188190
}
189191

192+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
193+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return req.GetDsl() }))
194+
}
195+
190196
dsl, ok := requestutil.GetDSLFromRequest(i.req)
191197
if ok {
192198
return dsl.(string)
@@ -209,3 +215,14 @@ func (i *RestfulInfo) ConsistencyLevel() string {
209215
}
210216
return Unknown
211217
}
218+
219+
func (i *RestfulInfo) AnnsField() string {
220+
if req, ok := i.req.(*milvuspb.SearchRequest); ok {
221+
return getAnnsFieldFromKvs(req.GetSearchParams())
222+
}
223+
224+
if req, ok := i.req.(*milvuspb.HybridSearchRequest); ok {
225+
return listToString(lo.Map(req.GetRequests(), func(req *milvuspb.SearchRequest, _ int) string { return getAnnsFieldFromKvs(req.GetSearchParams()) }))
226+
}
227+
return Unknown
228+
}

internal/proxy/accesslog/info/util.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import (
2525
"go.uber.org/atomic"
2626
"google.golang.org/grpc/metadata"
2727

28+
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
2829
"github.com/milvus-io/milvus/pkg/v2/util"
2930
"github.com/milvus-io/milvus/pkg/v2/util/crypto"
31+
"github.com/milvus-io/milvus/pkg/v2/util/funcutil"
3032
)
3133

3234
var ClusterPrefix atomic.String
@@ -90,3 +92,22 @@ func getSdkTypeByUserAgent(userAgents []string) (string, bool) {
9092
return "", false
9193
}
9294
}
95+
96+
func getAnnsFieldFromKvs(kvs []*commonpb.KeyValuePair) string {
97+
field, err := funcutil.GetAttrByKeyFromRepeatedKV("anns_field", kvs)
98+
if err != nil {
99+
return "default"
100+
}
101+
return field
102+
}
103+
104+
func listToString(strs []string) string {
105+
result := "["
106+
for i, str := range strs {
107+
if i != 0 {
108+
result += ", "
109+
}
110+
result += "\"" + str + "\""
111+
}
112+
return result + "]"
113+
}

0 commit comments

Comments
 (0)