Skip to content

Commit

Permalink
fix: Restful API use deprecate error code cause access log panic. (#3…
Browse files Browse the repository at this point in the history
…4576)

relate: #34578

---------

Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
  • Loading branch information
aoiasd committed Jul 12, 2024
1 parent 358e9a1 commit 5bb0d21
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions internal/distributed/proxy/httpserver/handler_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (

var StatusSuccess = commonpb.Status{
ErrorCode: commonpb.ErrorCode_Success,
Code: merr.Code(nil),
Reason: "",
}

Expand Down
1 change: 1 addition & 0 deletions internal/distributed/proxy/httpserver/handler_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ func TestMethodGet(t *testing.T) {

var commonSuccessStatus = &commonpb.Status{
ErrorCode: commonpb.ErrorCode_Success,
Code: merr.Code(nil),
Reason: "",
}

Expand Down
15 changes: 8 additions & 7 deletions internal/distributed/proxy/httpserver/request_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus/pkg/util/merr"
)

type DatabaseReq struct {
Expand Down Expand Up @@ -356,14 +357,14 @@ func (req *AliasCollectionReq) GetAliasName() string {
}

func wrapperReturnHas(has bool) gin.H {
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: gin.H{HTTPReturnHas: has}}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: gin.H{HTTPReturnHas: has}}
}

func wrapperReturnList(names []string) gin.H {
if names == nil {
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: []string{}}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: []string{}}
}
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: names}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: names}
}

func wrapperReturnRowCount(pairs []*commonpb.KeyValuePair) gin.H {
Expand All @@ -375,15 +376,15 @@ func wrapperReturnRowCount(pairs []*commonpb.KeyValuePair) gin.H {
}
rowCount, err := strconv.ParseInt(rowCountValue, 10, 64)
if err != nil {
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: gin.H{HTTPReturnRowCount: rowCountValue}}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: gin.H{HTTPReturnRowCount: rowCountValue}}
}
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: gin.H{HTTPReturnRowCount: rowCount}}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: gin.H{HTTPReturnRowCount: rowCount}}
}

func wrapperReturnDefault() gin.H {
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: gin.H{}}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: gin.H{}}
}

func wrapperReturnDefaultWithCost(cost int) gin.H {
return gin.H{HTTPReturnCode: commonpb.ErrorCode_Success, HTTPReturnData: gin.H{}, HTTPReturnCost: cost}
return gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: gin.H{}, HTTPReturnCost: cost}
}
16 changes: 13 additions & 3 deletions internal/proxy/accesslog/info/restful_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ func (i *RestfulInfo) MethodStatus() string {
return fmt.Sprintf("HttpError%d", i.params.StatusCode)
}

if code, ok := i.params.Keys[ContextReturnCode]; !ok || code.(int32) != 0 {
return "Failed"
value, ok := i.params.Keys[ContextReturnCode]
if !ok {
return Unknown
}

return "Successful"
code, ok := value.(int32)
if ok {
if code != 0 {
return "Failed"
}

return "Successful"
}

return Unknown
}

func (i *RestfulInfo) UserName() string {
Expand Down

0 comments on commit 5bb0d21

Please sign in to comment.