mirror of https://github.com/milvus-io/milvus.git
enhance: Forbid access log print error message with line break (#34491)
Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>pull/35359/head
parent
80a7c78f28
commit
bc2bbdc82f
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/milvus-io/milvus/internal/proxy/accesslog/info"
|
||||
"github.com/milvus-io/milvus/internal/proxy/connection"
|
||||
"github.com/milvus-io/milvus/pkg/util"
|
||||
"github.com/milvus-io/milvus/pkg/util/merr"
|
||||
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
||||
)
|
||||
|
||||
|
@ -31,6 +32,7 @@ func genTestData(clientInfo *commonpb.ClientInfo, identifier int64) []*TestData
|
|||
},
|
||||
resp: &milvuspb.QueryResults{
|
||||
CollectionName: "test1",
|
||||
Status: merr.Status(merr.WrapErrParameterInvalid("testA", "testB", "stack: 1\n 2\n")),
|
||||
},
|
||||
err: nil,
|
||||
})
|
||||
|
@ -42,6 +44,7 @@ func genTestData(clientInfo *commonpb.ClientInfo, identifier int64) []*TestData
|
|||
},
|
||||
resp: &milvuspb.SearchResults{
|
||||
CollectionName: "test2",
|
||||
Status: merr.Status(nil),
|
||||
},
|
||||
err: nil,
|
||||
})
|
||||
|
@ -52,6 +55,7 @@ func genTestData(clientInfo *commonpb.ClientInfo, identifier int64) []*TestData
|
|||
},
|
||||
resp: &milvuspb.ConnectResponse{
|
||||
Identifier: identifier,
|
||||
Status: merr.Status(nil),
|
||||
},
|
||||
err: nil,
|
||||
})
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
@ -202,11 +203,11 @@ func (i *GrpcAccessInfo) respStatus() *commonpb.Status {
|
|||
|
||||
func (i *GrpcAccessInfo) ErrorMsg() string {
|
||||
if i.err != nil {
|
||||
return i.err.Error()
|
||||
return strings.ReplaceAll(i.err.Error(), "\n", "\\n")
|
||||
}
|
||||
|
||||
if status := i.respStatus(); status != nil {
|
||||
return status.GetReason()
|
||||
return strings.ReplaceAll(status.GetReason(), "\n", "\\n")
|
||||
}
|
||||
|
||||
return Unknown
|
||||
|
|
|
@ -98,6 +98,11 @@ func (s *GrpcAccessInfoSuite) TestErrorMsg() {
|
|||
result = Get(s.info, "$error_msg")
|
||||
s.Equal(merr.ErrChannelLack.Error(), result[0])
|
||||
|
||||
// replace line breaks
|
||||
s.info.resp = merr.Status(fmt.Errorf("test error. stack: 1:\n 2:\n 3:\n"))
|
||||
result = Get(s.info, "$error_msg")
|
||||
s.Equal("test error. stack: 1:\\n 2:\\n 3:\\n", result[0])
|
||||
|
||||
s.info.err = status.Errorf(codes.Unavailable, "mock")
|
||||
result = Get(s.info, "$error_msg")
|
||||
s.Equal("rpc error: code = Unavailable desc = mock", result[0])
|
||||
|
|
|
@ -19,6 +19,7 @@ package info
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -138,7 +139,7 @@ func (i *RestfulInfo) ErrorMsg() string {
|
|||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprint(message)
|
||||
return strings.ReplaceAll(message.(string), "\n", "\\n")
|
||||
}
|
||||
|
||||
func (i *RestfulInfo) ErrorType() string {
|
||||
|
|
|
@ -129,6 +129,10 @@ func (s *RestfulAccessInfoSuite) TestErrorMsg() {
|
|||
s.info.params.Keys[ContextReturnMessage] = merr.ErrChannelLack.Error()
|
||||
result := Get(s.info, "$error_msg")
|
||||
s.Equal(merr.ErrChannelLack.Error(), result[0])
|
||||
|
||||
s.info.params.Keys[ContextReturnMessage] = "test error. stack: 1:\n 2:\n 3:\n"
|
||||
result = Get(s.info, "$error_msg")
|
||||
s.Equal("test error. stack: 1:\\n 2:\\n 3:\\n", result[0])
|
||||
}
|
||||
|
||||
func (s *RestfulAccessInfoSuite) TestDbName() {
|
||||
|
|
Loading…
Reference in New Issue