diff --git a/internal/proxy/impl_test.go b/internal/proxy/impl_test.go index 101476885f..be1f7283b9 100644 --- a/internal/proxy/impl_test.go +++ b/internal/proxy/impl_test.go @@ -266,7 +266,9 @@ func TestProxy_ResourceGroup(t *testing.T) { }) t.Run("describe resource group", func(t *testing.T) { - resp, err := node.DescribeResourceGroup(ctx, &milvuspb.DescribeResourceGroupRequest{ResourceGroup: "rg"}) + resp, err := node.DescribeResourceGroup(ctx, &milvuspb.DescribeResourceGroupRequest{ + ResourceGroup: "rg", + }) assert.NoError(t, err) assert.Equal(t, resp.Status.ErrorCode, commonpb.ErrorCode_Success) }) diff --git a/internal/proxy/multi_rate_limiter_test.go b/internal/proxy/multi_rate_limiter_test.go index 538dbbad14..ef96d2b7b2 100644 --- a/internal/proxy/multi_rate_limiter_test.go +++ b/internal/proxy/multi_rate_limiter_test.go @@ -134,7 +134,8 @@ func TestRateLimiter(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - newRate := fmt.Sprintf("%.4f", rand.Float64()) + // avoid production precision issues when comparing 0-terminated numbers + newRate := fmt.Sprintf("%.3f1", rand.Float64()) etcdCli.KV.Put(ctx, "by-dev/config/quotaAndLimits/ddl/collectionRate", newRate) etcdCli.KV.Put(ctx, "by-dev/config/quotaAndLimits/ddl/partitionRate", "invalid") diff --git a/internal/proxy/query_coord_mock_test.go b/internal/proxy/query_coord_mock_test.go index 29f1782bfa..2436a90400 100644 --- a/internal/proxy/query_coord_mock_test.go +++ b/internal/proxy/query_coord_mock_test.go @@ -463,19 +463,29 @@ func (coord *QueryCoordMock) ListResourceGroups(ctx context.Context, req *milvus } func (coord *QueryCoordMock) DescribeResourceGroup(ctx context.Context, req *querypb.DescribeResourceGroupRequest) (*querypb.DescribeResourceGroupResponse, error) { + if req.GetResourceGroup() == "rg" { + return &querypb.DescribeResourceGroupResponse{ + Status: &commonpb.Status{ + ErrorCode: commonpb.ErrorCode_Success, + Reason: "", + }, + ResourceGroup: &querypb.ResourceGroupInfo{ + Name: "rg", + Capacity: 2, + NumAvailableNode: 1, + NumOutgoingNode: map[int64]int32{1: 1}, + NumIncomingNode: map[int64]int32{2: 2}, + }, + }, nil + } + return &querypb.DescribeResourceGroupResponse{ Status: &commonpb.Status{ - ErrorCode: commonpb.ErrorCode_Success, + ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "", }, - ResourceGroup: &querypb.ResourceGroupInfo{ - Name: "rg", - Capacity: 2, - NumAvailableNode: 1, - NumOutgoingNode: map[int64]int32{1: 1}, - NumIncomingNode: map[int64]int32{2: 2}, - }, }, nil + } func NewQueryCoordMock(opts ...QueryCoordMockOption) *QueryCoordMock { diff --git a/internal/proxy/task.go b/internal/proxy/task.go index d9327d9fc2..f1fb1ec14a 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -2108,7 +2108,10 @@ func (t *DescribeResourceGroupTask) Execute(ctx context.Context) error { resp, err := t.queryCoord.DescribeResourceGroup(ctx, &querypb.DescribeResourceGroupRequest{ ResourceGroup: t.ResourceGroup, }) - rgInfo := resp.GetResourceGroup() + + if err != nil { + return err + } getCollectionNameFunc := func(value int32, key int64) string { name, err := globalMetaCache.GetCollectionName(ctx, key) @@ -2119,22 +2122,31 @@ func (t *DescribeResourceGroupTask) Execute(ctx context.Context) error { return name } - loadReplicas := lo.MapKeys(rgInfo.NumLoadedReplica, getCollectionNameFunc) - outgoingNodes := lo.MapKeys(rgInfo.NumOutgoingNode, getCollectionNameFunc) - incomingNodes := lo.MapKeys(rgInfo.NumIncomingNode, getCollectionNameFunc) + if resp.Status.ErrorCode == commonpb.ErrorCode_Success { + rgInfo := resp.GetResourceGroup() - t.result = &milvuspb.DescribeResourceGroupResponse{ - Status: resp.Status, - ResourceGroup: &milvuspb.ResourceGroup{ - Name: rgInfo.GetName(), - Capacity: rgInfo.GetCapacity(), - NumAvailableNode: rgInfo.NumAvailableNode, - NumLoadedReplica: loadReplicas, - NumOutgoingNode: outgoingNodes, - NumIncomingNode: incomingNodes, - }, + loadReplicas := lo.MapKeys(rgInfo.NumLoadedReplica, getCollectionNameFunc) + outgoingNodes := lo.MapKeys(rgInfo.NumOutgoingNode, getCollectionNameFunc) + incomingNodes := lo.MapKeys(rgInfo.NumIncomingNode, getCollectionNameFunc) + + t.result = &milvuspb.DescribeResourceGroupResponse{ + Status: resp.Status, + ResourceGroup: &milvuspb.ResourceGroup{ + Name: rgInfo.GetName(), + Capacity: rgInfo.GetCapacity(), + NumAvailableNode: rgInfo.NumAvailableNode, + NumLoadedReplica: loadReplicas, + NumOutgoingNode: outgoingNodes, + NumIncomingNode: incomingNodes, + }, + } + } else { + t.result = &milvuspb.DescribeResourceGroupResponse{ + Status: resp.Status, + } } - return err + + return nil } func (t *DescribeResourceGroupTask) PostExecute(ctx context.Context) error { diff --git a/internal/proxy/task_test.go b/internal/proxy/task_test.go index c6237ae1b5..e878e8624a 100644 --- a/internal/proxy/task_test.go +++ b/internal/proxy/task_test.go @@ -2784,3 +2784,43 @@ func TestDescribeResourceGroupTask(t *testing.T) { assert.NotNil(t, outgoingNodeNum["collection1"]) assert.NotNil(t, incomingNodeNum["collection2"]) } + +func TestDescribeResourceGroupTaskFailed(t *testing.T) { + rc := &MockRootCoordClientInterface{} + qc := NewQueryCoordMock() + qc.Start() + defer qc.Stop() + ctx := context.Background() + mgr := newShardClientMgr() + InitMetaCache(ctx, rc, qc, mgr) + // make it avoid remote call on rc + globalMetaCache.GetCollectionSchema(context.Background(), "collection1") + globalMetaCache.GetCollectionSchema(context.Background(), "collection2") + + req := &milvuspb.DescribeResourceGroupRequest{ + Base: &commonpb.MsgBase{ + MsgID: 1, + Timestamp: 2, + TargetID: 3, + }, + ResourceGroup: "rgggg", + } + + task := &DescribeResourceGroupTask{ + DescribeResourceGroupRequest: req, + ctx: ctx, + queryCoord: qc, + } + task.PreExecute(ctx) + + assert.Equal(t, commonpb.MsgType_DescribeResourceGroup, task.Type()) + assert.Equal(t, UniqueID(1), task.ID()) + assert.Equal(t, Timestamp(2), task.BeginTs()) + assert.Equal(t, Timestamp(2), task.EndTs()) + assert.Equal(t, paramtable.GetNodeID(), task.Base.GetSourceID()) + assert.Equal(t, UniqueID(3), task.Base.GetTargetID()) + + err := task.Execute(ctx) + assert.Nil(t, err) + assert.Equal(t, commonpb.ErrorCode_UnexpectedError, task.result.Status.ErrorCode) +}