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 error handling of SearchByID API in lb gateway #1084

Merged
merged 2 commits into from
Mar 16, 2021
Merged
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
20 changes: 10 additions & 10 deletions internal/db/rdb/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (m *mySQLClient) Open(ctx context.Context) (err error) {
func (m *mySQLClient) Ping(ctx context.Context) (err error) {
if m.session == nil {
err = errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}
pctx, cancel := context.WithTimeout(ctx, m.initialPingTimeLimit)
Expand Down Expand Up @@ -183,7 +183,7 @@ func (m *mySQLClient) Ping(ctx context.Context) (err error) {
func (m *mySQLClient) Close(ctx context.Context) (err error) {
if m.session == nil {
err = errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
m.connected.Store(false)
return err
}
Expand All @@ -205,7 +205,7 @@ func (m *mySQLClient) GetVector(ctx context.Context, uuid string) (Vector, error

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return nil, err
}

Expand Down Expand Up @@ -238,7 +238,7 @@ func (m *mySQLClient) GetIPs(ctx context.Context, uuid string) ([]string, error)

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return nil, err
}

Expand Down Expand Up @@ -281,7 +281,7 @@ func (m *mySQLClient) SetVector(ctx context.Context, vec Vector) error {

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}

Expand Down Expand Up @@ -338,7 +338,7 @@ func (m *mySQLClient) SetVectors(ctx context.Context, vecs ...Vector) error {

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}

Expand Down Expand Up @@ -398,7 +398,7 @@ func (m *mySQLClient) deleteVector(ctx context.Context, val string) error {

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}

Expand Down Expand Up @@ -457,7 +457,7 @@ func (m *mySQLClient) SetIPs(ctx context.Context, uuid string, ips ...string) er

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}

Expand Down Expand Up @@ -496,7 +496,7 @@ func (m *mySQLClient) RemoveIPs(ctx context.Context, ips ...string) error {

if m.session == nil {
err := errors.ErrMySQLSessionNil
m.outputLog(err)
m.errorLog(err)
return err
}

Expand All @@ -514,7 +514,7 @@ func (m *mySQLClient) RemoveIPs(ctx context.Context, ips ...string) error {
return tx.Commit()
}

func (m *mySQLClient) outputLog(err error) {
func (m *mySQLClient) errorLog(err error) {
log.Errorf(
"err: %v, { host: %s, port: %d, user: %s, name: %s, db: %s, charset: %s, socketPath: %s, network: %s} ",
err, m.host, m.port, m.user, m.name, m.db, m.charset, m.socketPath, m.network,
Expand Down
6 changes: 3 additions & 3 deletions pkg/gateway/lb/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
if serr == nil {
return res, nil
}
err = errors.Wrap(err, status.WrapWithInternal("SearchByID API failed to process search request", err,
err = errors.Wrap(err, status.WrapWithInternal("SearchByID API failed to process search request", serr,
&errdetails.RequestInfo{
RequestId: req.GetConfig().GetRequestId(),
ServingData: errdetails.Serialize(req),
Expand All @@ -252,11 +252,11 @@ func (s *server) SearchByID(ctx context.Context, req *payload.Search_IDRequest)
ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.SearchByID",
ResourceName: strings.Join(s.gateway.Addrs(ctx), ", "),
Owner: errdetails.ValdResourceOwner,
Description: err.Error(),
Description: serr.Error(),
}).Error())
log.Error(err)
if span != nil {
span.SetStatus(trace.StatusCodeNotFound(err.Error()))
span.SetStatus(trace.StatusCodeInternal(err.Error()))
}
return nil, err
}
Expand Down