Skip to content

Commit

Permalink
fix: accesslog method status not return failed when error in response (
Browse files Browse the repository at this point in the history
…milvus-io#28824)

relate: milvus-io#28086

Signed-off-by: aoiasd <[email protected]>
  • Loading branch information
aoiasd authored Dec 1, 2023
1 parent 1174a75 commit 24c565e
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions internal/proxy/accesslog/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ type AccessInfo interface {
}

type GrpcAccessInfo struct {
ctx context.Context
info *grpc.UnaryServerInfo
req interface{}
resp interface{}
err error
ctx context.Context
info *grpc.UnaryServerInfo
status *commonpb.Status
req interface{}
resp interface{}
err error

start time.Time
end time.Time
Expand All @@ -69,6 +70,19 @@ func (i *GrpcAccessInfo) SetResult(resp interface{}, err error) {
i.resp = resp
i.err = err
i.end = time.Now()

// extract status from response
baseResp, ok := i.resp.(BaseResponse)
if ok {
i.status = baseResp.GetStatus()
return
}

status, ok := i.resp.(*commonpb.Status)
if ok {
i.status = status
return
}
}

func (i *GrpcAccessInfo) Get(keys ...string) []string {
Expand Down Expand Up @@ -150,6 +164,11 @@ func getMethodStatus(i *GrpcAccessInfo) string {
if code != codes.OK && code != codes.Unknown {
return fmt.Sprintf("Grpc%s", code.String())
}

if i.status.GetCode() != 0 {
return "Failed"
}

return code.String()
}

Expand Down Expand Up @@ -179,15 +198,8 @@ type BaseResponse interface {
}

func getErrorCode(i *GrpcAccessInfo) string {
baseResp, ok := i.resp.(BaseResponse)
if ok {
status := baseResp.GetStatus()
return fmt.Sprint(int(status.GetErrorCode()))
}

status, ok := i.resp.(*commonpb.Status)
if ok {
return fmt.Sprint(int(status.GetErrorCode()))
if i.status != nil {
return fmt.Sprint(i.status.GetCode())
}

return fmt.Sprint(merr.Code(i.err))
Expand Down

0 comments on commit 24c565e

Please sign in to comment.