From d1c879ada77c788714f951a1f1190c95f80a54fb Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 26 Jul 2023 10:39:06 +0800 Subject: [PATCH] address the comment Signed-off-by: Ryan Leung --- errors.toml | 4 ++-- pkg/errs/errno.go | 2 +- server/grpc_service.go | 16 ++++++++-------- tests/integrations/client/client_test.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/errors.toml b/errors.toml index acd5e881d2e..06848a79d1e 100644 --- a/errors.toml +++ b/errors.toml @@ -701,9 +701,9 @@ error = ''' leader is nil ''' -["PD:server:ErrReachRateLimit"] +["PD:server:ErrRateLimitExceeded"] error = ''' -reach rate limit +rate limit exceeded ''' ["PD:server:ErrServerNotStarted"] diff --git a/pkg/errs/errno.go b/pkg/errs/errno.go index c6becf845b9..a5e05219dfa 100644 --- a/pkg/errs/errno.go +++ b/pkg/errs/errno.go @@ -182,7 +182,7 @@ var ( ErrCancelStartEtcd = errors.Normalize("etcd start canceled", errors.RFCCodeText("PD:server:ErrCancelStartEtcd")) ErrConfigItem = errors.Normalize("cannot set invalid configuration", errors.RFCCodeText("PD:server:ErrConfiguration")) ErrServerNotStarted = errors.Normalize("server not started", errors.RFCCodeText("PD:server:ErrServerNotStarted")) - ErrReachRateLimit = errors.Normalize("reach rate limit", errors.RFCCodeText("PD:server:ErrReachRateLimit")) + ErrRateLimitExceeded = errors.Normalize("rate limit exceeded", errors.RFCCodeText("PD:server:ErrRateLimitExceeded")) ) // logutil errors diff --git a/server/grpc_service.go b/server/grpc_service.go index 735b6bc9d3b..47e24293ed7 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -284,7 +284,7 @@ func (s *GrpcServer) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb defer limiter.Release(fName) } else { return &pdpb.GetMembersResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -775,7 +775,7 @@ func (s *GrpcServer) GetStore(ctx context.Context, request *pdpb.GetStoreRequest defer limiter.Release(fName) } else { return &pdpb.GetStoreResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -878,7 +878,7 @@ func (s *GrpcServer) GetAllStores(ctx context.Context, request *pdpb.GetAllStore defer limiter.Release(fName) } else { return &pdpb.GetAllStoresResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -923,7 +923,7 @@ func (s *GrpcServer) StoreHeartbeat(ctx context.Context, request *pdpb.StoreHear defer limiter.Release(fName) } else { return &pdpb.StoreHeartbeatResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -1304,7 +1304,7 @@ func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionReque defer limiter.Release(fName) } else { return &pdpb.GetRegionResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -1348,7 +1348,7 @@ func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionR defer limiter.Release(fName) } else { return &pdpb.GetRegionResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -1393,7 +1393,7 @@ func (s *GrpcServer) GetRegionByID(ctx context.Context, request *pdpb.GetRegionB defer limiter.Release(fName) } else { return &pdpb.GetRegionResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } @@ -1437,7 +1437,7 @@ func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsR defer limiter.Release(fName) } else { return &pdpb.ScanRegionsResponse{ - Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrReachRateLimit.FastGenByArgs().Error()), + Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, errs.ErrRateLimitExceeded.FastGenByArgs().Error()), }, nil } } diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index f848d512a3d..5b5ccf537a6 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -1551,7 +1551,7 @@ func TestGRPCRateLimitMiddleware(t *testing.T) { re.NoError(err) resp.Body.Close() re.Equal(http.StatusOK, resp.StatusCode) - expectErr := "reach rate limit" + expectErr := errs.ErrRateLimitExceeded.Error() for i := 0; i < 3; i++ { _, err := client.GetStore(ctx, 1) if i > 0 {