Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [2.5]not enable rate limiter for restful v1 #39555

Open
wants to merge 1 commit into
base: 2.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/distributed/proxy/httpserver/handler_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func (h *HandlersV1) query(c *gin.Context) {
username, _ := c.Get(ContextUsername)
ctx := proxy.NewContextWithMetadata(c, username.(string), req.DbName)
response, err := h.executeRestRequestInterceptor(ctx, c, req, func(reqCtx context.Context, req any) (any, error) {
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down Expand Up @@ -611,7 +611,7 @@ func (h *HandlersV1) get(c *gin.Context) {
return nil, RestRequestInterceptorErr
}
queryReq := req.(*milvuspb.QueryRequest)
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down Expand Up @@ -691,7 +691,7 @@ func (h *HandlersV1) delete(c *gin.Context) {
}
deleteReq.Expr = filter
}
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down Expand Up @@ -774,7 +774,7 @@ func (h *HandlersV1) insert(c *gin.Context) {
})
return nil, RestRequestInterceptorErr
}
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down Expand Up @@ -880,7 +880,7 @@ func (h *HandlersV1) upsert(c *gin.Context) {
})
return nil, RestRequestInterceptorErr
}
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down Expand Up @@ -983,7 +983,7 @@ func (h *HandlersV1) search(c *gin.Context) {
username, _ := c.Get(ContextUsername)
ctx := proxy.NewContextWithMetadata(c, username.(string), req.DbName)
response, err := h.executeRestRequestInterceptor(ctx, c, req, func(reqCtx context.Context, req any) (any, error) {
if _, err := CheckLimiter(ctx, &req, h.proxy); err != nil {
if _, err := CheckLimiter(ctx, req, h.proxy); err != nil {
c.AbortWithStatusJSON(http.StatusOK, gin.H{
HTTPReturnCode: merr.Code(err),
HTTPReturnMessage: err.Error() + ", error: " + err.Error(),
Expand Down
7 changes: 6 additions & 1 deletion internal/distributed/proxy/httpserver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,12 @@
return nil, err
}

dbID, collectionIDToPartIDs, rt, n, err := proxy.GetRequestInfo(ctx, req)
request, ok := req.(proto.Message)
if !ok {
return nil, merr.WrapErrParameterInvalidMsg("wrong req format when check limiter")
}

Check warning on line 1464 in internal/distributed/proxy/httpserver/utils.go

View check run for this annotation

Codecov / codecov/patch

internal/distributed/proxy/httpserver/utils.go#L1463-L1464

Added lines #L1463 - L1464 were not covered by tests

dbID, collectionIDToPartIDs, rt, n, err := proxy.GetRequestInfo(ctx, request)
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/proxy/rate_limit_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/types"
Expand All @@ -38,7 +39,11 @@
// RateLimitInterceptor returns a new unary server interceptors that performs request rate limiting.
func RateLimitInterceptor(limiter types.Limiter) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
dbID, collectionIDToPartIDs, rt, n, err := GetRequestInfo(ctx, req)
request, ok := req.(proto.Message)
if !ok {
return nil, merr.WrapErrParameterInvalidMsg("wrong req format when check limiter")
}

Check warning on line 45 in internal/proxy/rate_limit_interceptor.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/rate_limit_interceptor.go#L44-L45

Added lines #L44 - L45 were not covered by tests
dbID, collectionIDToPartIDs, rt, n, err := GetRequestInfo(ctx, request)
if err != nil {
log.Warn("failed to get request info", zap.Error(err))
return handler(ctx, req)
Expand Down
4 changes: 3 additions & 1 deletion internal/proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package proxy
import (
"context"
"fmt"
"reflect"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -2107,7 +2108,7 @@ func GetCostValue(status *commonpb.Status) int {
}

// GetRequestInfo returns collection name and rateType of request and return tokens needed.
func GetRequestInfo(ctx context.Context, req interface{}) (int64, map[int64][]int64, internalpb.RateType, int, error) {
func GetRequestInfo(ctx context.Context, req proto.Message) (int64, map[int64][]int64, internalpb.RateType, int, error) {
switch r := req.(type) {
case *milvuspb.InsertRequest:
dbID, collToPartIDs, err := getCollectionAndPartitionID(ctx, req.(reqPartName))
Expand Down Expand Up @@ -2185,6 +2186,7 @@ func GetRequestInfo(ctx context.Context, req interface{}) (int64, map[int64][]in
if req == nil {
return util.InvalidDBID, map[int64][]int64{}, 0, 0, fmt.Errorf("null request")
}
log.RatedWarn(60, "not supported request type for rate limiter", zap.String("type", reflect.TypeOf(req).String()))
return util.InvalidDBID, map[int64][]int64{}, 0, 0, nil
}
}
Expand Down
Loading