Skip to content

Commit

Permalink
fix: not enable rate limiter for restful v1
Browse files Browse the repository at this point in the history
Signed-off-by: lixinguo <[email protected]>
  • Loading branch information
lixinguo committed Jan 23, 2025
1 parent 355dc82 commit 678ba55
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
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 @@ -517,7 +517,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 @@ -595,7 +595,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 @@ -675,7 +675,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 @@ -758,7 +758,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 @@ -864,7 +864,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 @@ -967,7 +967,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 @@ -1288,7 +1288,12 @@ func CheckLimiter(ctx context.Context, req interface{}, pxy types.ProxyComponent
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")
}

dbID, collectionIDToPartIDs, rt, n, err := proxy.GetRequestInfo(ctx, request)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ func GetRequestLabelFromContext(ctx context.Context) bool {
}

// 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 @@ -1989,6 +1989,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.Any("req", req))
return util.InvalidDBID, map[int64][]int64{}, 0, 0, nil
}
}
Expand Down

0 comments on commit 678ba55

Please sign in to comment.