fix: v2.6 WebUI metrics response schema change bug (#42957)

#42919  
fix metrics response schema incompatibility with WebUI v2.6

Signed-off-by: tinswzy <zhenyuan.wei@zilliz.com>
This commit is contained in:
tinswzy 2025-07-08 22:56:47 +08:00 committed by GitHub
parent 6989e18599
commit c4634d861e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/tidwall/gjson"
"github.com/tikv/client-go/v2/txnkv"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/atomic"
@ -582,6 +583,15 @@ func (s *mixCoordImpl) GetMetrics(ctx context.Context, in *milvuspb.GetMetricsRe
NodesInfo: make([]metricsinfo.SystemTopologyNode, 0),
}
// If a processing role is specified, the corresponding role will be used for processing
ret := gjson.Parse(in.GetRequest())
processRole, _ := metricsinfo.ParseMetricProcessInRole(ret)
if len(processRole) > 0 && processRole == typeutil.QueryCoordRole {
return s.GetQcMetrics(ctx, in)
} else if len(processRole) > 0 && processRole == typeutil.DataCoordRole {
return s.GetDcMetrics(ctx, in)
}
identifierMap := make(map[string]int)
rootCoordResp, rootCoordErr := s.rootcoordServer.GetMetrics(ctx, in)

View File

@ -169,7 +169,7 @@ func buildReqParams(c *gin.Context, metricsType string, customParams ...*commonp
func getQueryComponentMetrics(node *Proxy, metricsType string, customParams ...*commonpb.KeyValuePair) gin.HandlerFunc {
return func(c *gin.Context) {
params := buildReqParams(c, metricsType)
params := buildReqParams(c, metricsType, metricsinfo.RequestProcessInQCRole)
req, err := metricsinfo.ConstructGetMetricsRequest(params)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
@ -191,7 +191,7 @@ func getQueryComponentMetrics(node *Proxy, metricsType string, customParams ...*
func getDataComponentMetrics(node *Proxy, metricsType string, customParams ...*commonpb.KeyValuePair) gin.HandlerFunc {
return func(c *gin.Context) {
params := buildReqParams(c, metricsType)
params := buildReqParams(c, metricsType, metricsinfo.RequestProcessInDCRole)
req, err := metricsinfo.ConstructGetMetricsRequest(params)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{

View File

@ -26,6 +26,7 @@ import (
"github.com/milvus-io/milvus/pkg/v2/common"
"github.com/milvus-io/milvus/pkg/v2/log"
"github.com/milvus-io/milvus/pkg/v2/util/commonpbutil"
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
)
const (
@ -93,6 +94,8 @@ const (
MetricsRequestParamsInQC = "qc"
MetricsRequestParamsInDN = "dn"
MetricsRequestParamsInQN = "qn"
MetricRequestProcessInRoleKey = "ProcessRole"
)
var (
@ -100,6 +103,9 @@ var (
RequestParamsInQC = &commonpb.KeyValuePair{Key: MetricRequestParamINKey, Value: MetricsRequestParamsInQC}
RequestParamsInDN = &commonpb.KeyValuePair{Key: MetricRequestParamINKey, Value: MetricsRequestParamsInDN}
RequestParamsInQN = &commonpb.KeyValuePair{Key: MetricRequestParamINKey, Value: MetricsRequestParamsInQN}
RequestProcessInDCRole = &commonpb.KeyValuePair{Key: MetricRequestProcessInRoleKey, Value: typeutil.DataCoordRole}
RequestProcessInQCRole = &commonpb.KeyValuePair{Key: MetricRequestProcessInRoleKey, Value: typeutil.QueryCoordRole}
)
type MetricsRequestAction func(ctx context.Context, req *milvuspb.GetMetricsRequest, jsonReq gjson.Result) (string, error)
@ -176,6 +182,15 @@ func ParseMetricRequestType(jsonRet gjson.Result) (string, error) {
return "", fmt.Errorf("%s or %s not found in request", MetricTypeKey, MetricRequestTypeKey)
}
func ParseMetricProcessInRole(jsonRet gjson.Result) (string, error) {
v := jsonRet.Get(MetricRequestProcessInRoleKey)
if v.Exists() {
return v.String(), nil
}
return "", fmt.Errorf("%s not found in request", MetricRequestProcessInRoleKey)
}
func GetCollectionIDFromRequest(jsonReq gjson.Result) int64 {
v := jsonReq.Get(MetricRequestParamCollectionIDKey)
if !v.Exists() {

View File

@ -13,6 +13,7 @@ package metricsinfo
import (
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
@ -20,6 +21,7 @@ import (
"go.uber.org/zap"
"github.com/milvus-io/milvus/pkg/v2/log"
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
)
func Test_ParseMetricType(t *testing.T) {
@ -79,3 +81,51 @@ func Test_ConstructRequestByMetricType(t *testing.T) {
}
}
}
func Test_ParseMetricProcessInRole(t *testing.T) {
tests := []struct {
name string
input string
expected string
wantErr bool
}{
{
name: "Empty JSON",
input: "{}",
expected: "",
wantErr: true,
},
{
name: "Valid ProcessRole value",
input: fmt.Sprintf(`{"%s": "%s"}`, MetricRequestProcessInRoleKey, typeutil.DataCoordRole),
expected: typeutil.DataCoordRole,
wantErr: false,
},
{
name: "Valid ProcessRole with integer value",
input: fmt.Sprintf(`{"%s": 123}`, MetricRequestProcessInRoleKey),
expected: "123",
wantErr: false,
},
{
name: "Invalid key name",
input: `{"invalid_key": "value"}`,
expected: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
jsonRet := gjson.Parse(tt.input)
result, err := ParseMetricProcessInRole(jsonRet)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
}
})
}
}