enhance: [2.4] add hit segment num metrics for queryHook (#35619)

issue: #35576 
pr: #35577

Signed-off-by: chasingegg <chao.gao@zilliz.com>
This commit is contained in:
Gao 2024-08-23 12:49:02 +08:00 committed by GitHub
parent 5b5119a51f
commit 1687d64c46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/milvus-io/milvus/internal/proto/querypb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/metrics"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)
@ -29,7 +30,8 @@ func OptimizeSearchParams(ctx context.Context, req *querypb.SearchRequest, query
return req, nil
}
log := log.Ctx(ctx).With(zap.Int64("collection", req.GetReq().GetCollectionID()))
collectionId := req.GetReq().GetCollectionID()
log := log.Ctx(ctx).With(zap.Int64("collection", collectionId))
serializedPlan := req.GetReq().GetSerializedExprPlan()
// plan not found
@ -55,6 +57,8 @@ func OptimizeSearchParams(ctx context.Context, req *querypb.SearchRequest, query
case *planpb.PlanNode_VectorAnns:
// use shardNum * segments num in shard to estimate total segment number
estSegmentNum := numSegments * int(channelNum)
metrics.QueryNodeSearchHitSegmentNum.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), fmt.Sprint(collectionId), metrics.SearchLabel).Observe(float64(estSegmentNum))
withFilter := (plan.GetVectorAnns().GetPredicates() != nil)
queryInfo := plan.GetVectorAnns().GetQueryInfo()
params := map[string]any{

View File

@ -362,6 +362,18 @@ var (
nodeIDLabelName,
})
QueryNodeSearchHitSegmentNum = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: milvusNamespace,
Subsystem: typeutil.QueryNodeRole,
Name: "search_hit_segment_num",
Help: "the number of segments actually involved in search task",
}, []string{
nodeIDLabelName,
collectionIDLabelName,
queryTypeLabelName,
})
QueryNodeSegmentPruneRatio = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: milvusNamespace,
@ -819,6 +831,7 @@ func RegisterQueryNode(registry *prometheus.Registry) {
registry.MustRegister(QueryNodeApplyBFCost)
registry.MustRegister(QueryNodeForwardDeleteCost)
registry.MustRegister(QueryNodeSegmentPruneRatio)
registry.MustRegister(QueryNodeSearchHitSegmentNum)
// Add cgo metrics
RegisterCGOMetrics(registry)
}