From 6c9ab99a2f6f0b715280d6bf9ea2e14c97a1672e Mon Sep 17 00:00:00 2001 From: Kiichiro YUKAWA Date: Tue, 8 Oct 2024 15:29:59 +0900 Subject: [PATCH] Fix gRPC error msg handling for lb-gateway handler (#2663) * :recycle: refactor: replace ParseError with FromError Signed-off-by: vankichi * :recycle: fix Signed-off-by: vankichi * :recycle: fix Signed-off-by: vankichi * :recycle: fix Signed-off-by: vankichi --------- Signed-off-by: vankichi Co-authored-by: Kosuke Morimoto --- pkg/gateway/lb/handler/grpc/aggregation.go | 38 +- pkg/gateway/lb/handler/grpc/handler.go | 552 ++++++++------------- 2 files changed, 233 insertions(+), 357 deletions(-) diff --git a/pkg/gateway/lb/handler/grpc/aggregation.go b/pkg/gateway/lb/handler/grpc/aggregation.go index 596762cabc..eb4addd84b 100644 --- a/pkg/gateway/lb/handler/grpc/aggregation.go +++ b/pkg/gateway/lb/handler/grpc/aggregation.go @@ -31,6 +31,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/codes" "github.com/vdaas/vald/internal/net/grpc/errdetails" "github.com/vdaas/vald/internal/net/grpc/status" + "github.com/vdaas/vald/internal/observability/attribute" "github.com/vdaas/vald/internal/observability/trace" "github.com/vdaas/vald/internal/sync" "github.com/vdaas/vald/pkg/gateway/lb/service" @@ -56,7 +57,7 @@ func (s *server) aggregationSearch( f func(ctx context.Context, fcfg *payload.Search_Config, // Forwarding Config to Agent vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error), -) (res *payload.Search_Response, err error) { +) (res *payload.Search_Response, attrs []attribute.KeyValue, err error) { ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, "aggregationSearch"), apiName+"/aggregationSearch") defer func() { if span != nil { @@ -235,12 +236,13 @@ func (s *server) aggregationSearch( ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.search", ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }) + attrs = trace.StatusCodeInternal(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeInternal(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } - return nil, err + return nil, attrs, err } res = aggr.Result() if num != 0 && len(res.GetResults()) > num { @@ -261,12 +263,13 @@ func (s *server) aggregationSearch( ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }, info.Get(), ) + attrs = trace.StatusCodeDeadlineExceeded(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeDeadlineExceeded(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } - return nil, err + return nil, attrs, err } if 0 < min && len(res.GetResults()) < min { err = status.WrapWithDeadlineExceeded( @@ -281,12 +284,13 @@ func (s *server) aggregationSearch( ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }, info.Get(), ) + attrs = trace.StatusCodeDeadlineExceeded(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeDeadlineExceeded(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } - return nil, err + return nil, attrs, err } } @@ -301,14 +305,15 @@ func (s *server) aggregationSearch( ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.search", ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }, info.Get()) + attrs = trace.FromGRPCStatus(st.Code(), msg) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } log.Warn(err) if len(res.GetResults()) == 0 { - return nil, err + return nil, attrs, err } } if num != 0 && len(res.GetResults()) == 0 { @@ -324,21 +329,23 @@ func (s *server) aggregationSearch( ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1.search", ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }, info.Get()) + attrs = trace.StatusCodeNotFound(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeNotFound(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } - return nil, err + return nil, attrs, err } if 0 < min && len(res.GetResults()) < min { if err == nil { err = errors.ErrInsuffcientSearchResult } + attrs = trace.StatusCodeNotFound(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeNotFound(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } err = status.WrapWithNotFound( @@ -353,15 +360,16 @@ func (s *server) aggregationSearch( ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), }, info.Get(), ) + attrs = trace.StatusCodeNotFound(err.Error()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.StatusCodeNotFound(err.Error())...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } - return nil, err + return nil, attrs, err } res.RequestId = bcfg.GetRequestId() - return res, nil + return res, attrs, nil } // vald standard algorithm. diff --git a/pkg/gateway/lb/handler/grpc/handler.go b/pkg/gateway/lb/handler/grpc/handler.go index 10021e53e4..740422e4f6 100644 --- a/pkg/gateway/lb/handler/grpc/handler.go +++ b/pkg/gateway/lb/handler/grpc/handler.go @@ -39,6 +39,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/codes" "github.com/vdaas/vald/internal/net/grpc/errdetails" "github.com/vdaas/vald/internal/net/grpc/status" + "github.com/vdaas/vald/internal/observability/attribute" "github.com/vdaas/vald/internal/observability/trace" "github.com/vdaas/vald/internal/safety" "github.com/vdaas/vald/internal/strings" @@ -254,11 +255,19 @@ func (s *server) Exists( attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: var ( - st *status.Status - msg string + st *status.Status + code codes.Code + msg string ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.ExistsRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ = status.FromError(err) + if st != nil { + code = st.Code() + msg = uuid + "'s object id:" + vald.ExistsRPCName + " API uuid " + uuid + "'s request returned error\t" + st.String() + } else { + code = codes.Unknown + msg = uuid + "'s object id:" + vald.ExistsRPCName + " API uuid " + uuid + "'s request returned error" + } + attrs = trace.FromGRPCStatus(code, msg) } log.Debug(err) if span != nil { @@ -301,23 +310,14 @@ func (s *server) Search( } return nil, err } - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + res, attrs, err := s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.Search(ctx, req, copts...) }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.SearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: req.GetConfig().GetRequestId(), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.SearchRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) - if span != nil { + if attrs != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -367,24 +367,24 @@ func (s *server) SearchByID( }, }) if err != nil { - st, msg, err := status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API for "+vald.SearchByIDRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) + st, _ := status.FromError(err) if span != nil && st != nil && st.Code() != codes.NotFound { span.RecordError(err) span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } // try search by using agent's SearchByID method this operation is emergency fallback, the search quality is not same as usual SearchByID operation. - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + var attrs []attribute.KeyValue + res, attrs, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.SearchByID(ctx, req, copts...) }) if err == nil { return res, nil } - st, msg, err = status.ParseError(err, codes.Internal, vald.SearchByIDRPCName+" API failed to process search request", reqInfo, resInfo) - if span != nil { + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -394,18 +394,15 @@ func (s *server) SearchByID( Config: req.GetConfig(), }) if err != nil { - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + var attrs []attribute.KeyValue + res, attrs, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.SearchByID(ctx, req, copts...) }) - if err == nil { - return res, nil - } if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, vald.SearchByIDRPCName+" API failed to process search request", reqInfo, resInfo) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -433,7 +430,7 @@ func (s *server) doSearch( ctx context.Context, cfg *payload.Search_Config, f func(ctx context.Context, cfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error), -) (res *payload.Search_Response, err error) { +) (res *payload.Search_Response, attrs []attribute.KeyValue, err error) { ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, "doSearch"), apiName+"/doSearch") defer func() { if span != nil { @@ -489,10 +486,10 @@ func (s *server) StreamSearch(stream vald.Search_StreamSearchServer) (err error) }() res, err := s.Search(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Search_StreamResponse{ @@ -508,11 +505,10 @@ func (s *server) StreamSearch(stream vald.Search_StreamSearchServer) (err error) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.StreamSearchRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -537,10 +533,10 @@ func (s *server) StreamSearchByID(stream vald.Search_StreamSearchByIDServer) (er }() res, err := s.SearchByID(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Search_StreamResponse{ @@ -556,11 +552,10 @@ func (s *server) StreamSearchByID(stream vald.Search_StreamSearchByIDServer) (er }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.StreamSearchByIDRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -598,14 +593,10 @@ func (s *server) MultiSearch( }() r, err := s.Search(ctx, query) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: query.GetConfig().GetRequestId(), - ServingData: errdetails.Serialize(query), - }) - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -625,21 +616,13 @@ func (s *server) MultiSearch( } wg.Wait() if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "failed to parse "+vald.MultiSearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: strings.Join(rids, ","), - ServingData: errdetails.Serialize(reqs), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.MultiSearchRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }) - if span != nil { - span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) - span.SetStatus(trace.StatusError, err.Error()) + st, _ := status.FromError(errs) + if st != nil && span != nil { + span.RecordError(errs) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) + span.SetStatus(trace.StatusError, errs.Error()) } - return res, err + return res, errs } return res, nil } @@ -675,14 +658,10 @@ func (s *server) MultiSearchByID( }() r, err := s.SearchByID(ctx, query) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: query.GetConfig().GetRequestId(), - ServingData: errdetails.Serialize(query), - }) - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -702,21 +681,13 @@ func (s *server) MultiSearchByID( } wg.Wait() if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "failed to parse "+vald.MultiSearchByIDRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: strings.Join(rids, ","), - ServingData: errdetails.Serialize(reqs), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.MultiSearchByIDRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }) - if span != nil { - span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) - span.SetStatus(trace.StatusError, err.Error()) + st, _ := status.FromError(errs) + if st != nil && span != nil { + span.RecordError(errs) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) + span.SetStatus(trace.StatusError, errs.Error()) } - return res, err + return res, errs } return res, nil } @@ -753,23 +724,14 @@ func (s *server) LinearSearch( } return nil, err } - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + res, attrs, err := s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.LinearSearch(ctx, req, copts...) }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.LinearSearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: req.GetConfig().GetRequestId(), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.LinearSearchRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -819,24 +781,24 @@ func (s *server) LinearSearchByID( }, }) if err != nil { - st, msg, err := status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API for "+vald.LinearSearchByIDRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) + st, _ := status.FromError(err) if span != nil && st != nil && st.Code() != codes.NotFound { span.RecordError(err) span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } // try search by using agent's LinearSearchByID method this operation is emergency fallback, the search quality is not same as usual LinearSearchByID operation. - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + var attrs []attribute.KeyValue + res, attrs, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.LinearSearchByID(ctx, req, copts...) }) if err == nil { return res, nil } - st, msg, err = status.ParseError(err, codes.Internal, vald.LinearSearchByIDRPCName+" API failed to process search request", reqInfo, resInfo) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -846,18 +808,15 @@ func (s *server) LinearSearchByID( Config: req.GetConfig(), }) if err != nil { - res, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { + var attrs []attribute.KeyValue + res, attrs, err = s.doSearch(ctx, req.GetConfig(), func(ctx context.Context, fcfg *payload.Search_Config, vc vald.Client, copts ...grpc.CallOption) (*payload.Search_Response, error) { req.Config = fcfg return vc.LinearSearchByID(ctx, req, copts...) }) - if err == nil { - return res, nil - } if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, vald.LinearSearchByIDRPCName+" API failed to process search request", reqInfo, resInfo) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(attrs...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -883,10 +842,10 @@ func (s *server) StreamLinearSearch(stream vald.Search_StreamLinearSearchServer) }() res, err := s.LinearSearch(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.LinearSearchRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Search_StreamResponse{ @@ -902,11 +861,10 @@ func (s *server) StreamLinearSearch(stream vald.Search_StreamLinearSearchServer) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.StreamLinearSearchRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -936,10 +894,10 @@ func (s *server) StreamLinearSearchByID( }() res, err := s.LinearSearchByID(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.LinearSearchByIDRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Search_StreamResponse{ @@ -955,11 +913,10 @@ func (s *server) StreamLinearSearchByID( }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.StreamLinearSearchByIDRPCName+" gRPC error response") + st, _ := status.FromError(err) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -997,14 +954,10 @@ func (s *server) MultiLinearSearch( }() r, err := s.LinearSearch(ctx, query) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: query.GetConfig().GetRequestId(), - ServingData: errdetails.Serialize(query), - }) - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -1024,21 +977,13 @@ func (s *server) MultiLinearSearch( } wg.Wait() if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "failed to parse "+vald.MultiLinearSearchRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: strings.Join(rids, ","), - ServingData: errdetails.Serialize(reqs), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.MultiLinearSearchRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }) - if span != nil { - span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) - span.SetStatus(trace.StatusError, err.Error()) + st, _ := status.FromError(errs) + if st != nil && span != nil { + span.RecordError(errs) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) + span.SetStatus(trace.StatusError, errs.Error()) } - return res, err + return res, errs } return res, nil } @@ -1074,14 +1019,10 @@ func (s *server) MultiLinearSearchByID( }() r, err := s.LinearSearchByID(ctx, query) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: query.GetConfig().GetRequestId(), - ServingData: errdetails.Serialize(query), - }) + st, _ := status.FromError(err) if sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -1101,21 +1042,13 @@ func (s *server) MultiLinearSearchByID( } wg.Wait() if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "failed to parse "+vald.MultiLinearSearchByIDRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: strings.Join(rids, ","), - ServingData: errdetails.Serialize(reqs), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.MultiLinearSearchByIDRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }) + st, _ := status.FromError(errs) if span != nil { - span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) - span.SetStatus(trace.StatusError, err.Error()) + span.RecordError(errs) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) + span.SetStatus(trace.StatusError, errs.Error()) } - return res, err + return res, errs } return res, nil } @@ -1321,19 +1254,10 @@ func (s *server) Insert( } } if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, - "failed to parse "+vald.InsertRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: uuid, - ServingData: errdetails.Serialize(req), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.InsertRPCName + ".DoMulti", - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) - if span != nil { + st, _ := status.FromError(errs) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -1360,10 +1284,10 @@ func (s *server) StreamInsert(stream vald.Insert_StreamInsertServer) (err error) }() res, err := s.Insert(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Object_StreamLocation{ @@ -1379,10 +1303,10 @@ func (s *server) StreamInsert(stream vald.Insert_StreamInsertServer) (err error) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamInsertRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -1421,10 +1345,10 @@ func (s *server) MultiInsert( }() res, err := s.Insert(ectx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -1493,10 +1417,10 @@ func (s *server) MultiInsert( } if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "error detected"+vald.MultiInsertRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } errs = err @@ -1708,10 +1632,10 @@ func (s *server) Update( }, }) if err != nil { - st, msg, err := status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API for "+vald.UpdateRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) + st, _ := status.FromError(err) if span != nil && st != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -1783,20 +1707,10 @@ func (s *server) Update( return nil, err } - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.RemoveRPCName+" for "+vald.UpdateRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: uuid, - ServingData: errdetails.Serialize(rreq), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.UpdateRPCName + "." + vald.RemoveRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) - - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -1829,19 +1743,10 @@ func (s *server) Update( } return nil, err } - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.InsertRPCName+" for "+vald.UpdateRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: uuid, - ServingData: errdetails.Serialize(ireq), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.UpdateRPCName + "." + vald.InsertRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -1866,10 +1771,10 @@ func (s *server) StreamUpdate(stream vald.Update_StreamUpdateServer) (err error) }() res, err := s.Update(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Object_StreamLocation{ @@ -1885,10 +1790,10 @@ func (s *server) StreamUpdate(stream vald.Update_StreamUpdateServer) (err error) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamUpdateRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -1927,10 +1832,10 @@ func (s *server) MultiUpdate( }() res, err := s.Update(ectx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -1999,10 +1904,10 @@ func (s *server) MultiUpdate( } if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "error detected"+vald.MultiUpdateRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } errs = err @@ -2130,11 +2035,10 @@ func (s *server) UpdateTimestamp( }) switch { case err != nil: - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.UpdateTimestampRPCName+" gRPC error response", reqInfo, resInfo, info.Get()) - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -2155,10 +2059,10 @@ func (s *server) UpdateTimestamp( }, }) if err != nil { - st, msg, err := status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API for "+vald.UpdateTimestampRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - if span != nil && st != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -2203,10 +2107,10 @@ func (s *server) UpdateTimestamp( return nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Unknown, vald.InsertRPCName+" API for "+vald.UpdateTimestampRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - if span != nil && st != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -2292,13 +2196,9 @@ func (s *server) Upsert( }) var attrs trace.Attributes if err != nil || vec == nil { - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API for "+vald.UpsertRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) + st, _ := status.FromError(err) if st != nil { - attrs = trace.FromGRPCStatus(st.Code(), msg) + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) if st.Code() == codes.NotFound { shouldInsert = true err = nil @@ -2370,6 +2270,8 @@ func (s *server) Upsert( } if err != nil { + // Should we use `status.FromError(err)` instead of `status.PraseError(err)` ? + // It seems `operation` has an important role for tracing, so I don't refactor for now. st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+operation+" for "+vald.UpsertRPCName+" gRPC error response", &errdetails.RequestInfo{ @@ -2407,10 +2309,10 @@ func (s *server) StreamUpsert(stream vald.Upsert_StreamUpsertServer) (err error) }() res, err := s.Upsert(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpsertRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Object_StreamLocation{ @@ -2426,10 +2328,10 @@ func (s *server) StreamUpsert(stream vald.Upsert_StreamUpsertServer) (err error) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamUpsertRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -2468,10 +2370,10 @@ func (s *server) MultiUpsert( }() res, err := s.Upsert(ectx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpsertRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -2540,10 +2442,10 @@ func (s *server) MultiUpsert( } if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "error detected"+vald.MultiUpsertRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } errs = err @@ -2606,12 +2508,10 @@ func (s *server) Remove( err = status.WrapWithDeadlineExceeded(vald.ExistsRPCName+" API for "+vald.RemoveRPCName+" API deadline exceeded", err, reqInfo, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.ExistsRPCName+" API for "+vald.RemoveRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } if err != nil { if span != nil { @@ -2673,11 +2573,10 @@ func (s *server) Remove( return nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.RemoveRPCName+" gRPC error response", reqInfo, resInfo, info.Get()) - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -2698,7 +2597,7 @@ func (s *server) Remove( } func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error) { - ctx, span := trace.StartSpan(grpc.WithGRPCMethod(stream.Context(), vald.PackageName+"."+vald.SearchRPCServiceName+"/"+vald.StreamSearchRPCName), apiName+"/"+vald.StreamSearchRPCName) + ctx, span := trace.StartSpan(grpc.WithGRPCMethod(stream.Context(), vald.PackageName+"."+vald.RemoveRPCServiceName+"/"+vald.StreamRemoveRPCName), apiName+"/"+vald.StreamRemoveRPCName) defer func() { if span != nil { span.End() @@ -2714,10 +2613,10 @@ func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error) }() res, err := s.Remove(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.RemoveRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Object_StreamLocation{ @@ -2733,10 +2632,10 @@ func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error) }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamRemoveRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return err @@ -2775,10 +2674,10 @@ func (s *server) MultiRemove( }() res, err := s.Remove(ectx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.RemoveRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } emu.Lock() @@ -2836,10 +2735,10 @@ func (s *server) MultiRemove( } if errs != nil { - st, msg, err := status.ParseError(errs, codes.Internal, "error detected"+vald.MultiRemoveRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } errs = err @@ -2937,19 +2836,11 @@ func (s *server) RemoveByTimestamp( err = errors.Join(err, errs) } if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.RemoveByTimestampRPCName+" gRPC error response", - &errdetails.RequestInfo{ - ServingData: errdetails.Serialize(req), - }, - &errdetails.ResourceInfo{ - ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip), - }, - ) + st, _ := status.FromError(err) log.Error(err) - if span != nil { + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -3165,19 +3056,10 @@ func (s *server) Flush( return nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, - "failed to parse "+vald.FlushRPCName+" gRPC error response", - &errdetails.RequestInfo{ - RequestId: strconv.FormatInt(now, 10), - ServingData: errdetails.Serialize(req), - }, - &errdetails.ResourceInfo{ - ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.FlushRPCName, - ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)), - }, info.Get()) + st, _ := status.FromError(err) if span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return nil, err @@ -3263,12 +3145,10 @@ func (s *server) GetObject( err = status.WrapWithDeadlineExceeded(vald.GetObjectRPCName+" API deadline exceeded", err, reqInfo, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.GetObjectRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil { @@ -3296,10 +3176,10 @@ func (s *server) StreamGetObject(stream vald.Object_StreamGetObjectServer) (err }() res, err := s.GetObject(ctx, req) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.GetObjectRPCName+" gRPC error response") - if sspan != nil { + st, _ := status.FromError(err) + if st != nil && sspan != nil { sspan.RecordError(err) - sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) sspan.SetStatus(trace.StatusError, err.Error()) } return &payload.Object_StreamVector{ @@ -3315,10 +3195,10 @@ func (s *server) StreamGetObject(stream vald.Object_StreamGetObjectServer) (err }, nil }) if err != nil { - st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamGetObjectRPCName+" gRPC error response") - if span != nil { + st, _ := status.FromError(err) + if st != nil && span != nil { span.RecordError(err) - span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...) + span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } @@ -3527,12 +3407,10 @@ func (s *server) IndexInfo( err = status.WrapWithDeadlineExceeded(vald.IndexInfoRPCName+" API deadline exceeded", err, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.IndexInfoRPCName+" API request returned error", resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil { @@ -3660,12 +3538,10 @@ func (s *server) IndexDetail( err = status.WrapWithDeadlineExceeded(vald.IndexDetailRPCName+" API deadline exceeded", err, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.IndexDetailRPCName+" API request returned error", resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil { @@ -3828,12 +3704,10 @@ func (s *server) GetTimestamp( err = status.WrapWithDeadlineExceeded(vald.GetTimestampRPCName+" API deadline exceeded", err, reqInfo, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.GetTimestampRPCName+" API uuid "+uuid+"'s request returned error", reqInfo, resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } if span != nil { span.RecordError(err) @@ -3872,12 +3746,10 @@ func (s *server) IndexStatistics( err = status.WrapWithDeadlineExceeded(vald.IndexStatisticsRPCName+" API deadline exceeded", err, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.IndexStatisticsRPCName+" API request returned error", resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil { @@ -3999,12 +3871,10 @@ func (s *server) IndexStatisticsDetail( err = status.WrapWithDeadlineExceeded(vald.IndexStatisticsDetailRPCName+" API deadline exceeded", err, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.IndexStatisticsDetailRPCName+" API request returned error", resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil { @@ -4239,12 +4109,10 @@ func (s *server) IndexProperty( err = status.WrapWithDeadlineExceeded(vald.IndexPropertyRPCName+" API deadline exceeded", err, resInfo) attrs = trace.StatusCodeDeadlineExceeded(err.Error()) default: - var ( - st *status.Status - msg string - ) - st, msg, err = status.ParseError(err, codes.Unknown, vald.IndexPropertyRPCName+" API request returned error", resInfo) - attrs = trace.FromGRPCStatus(st.Code(), msg) + st, _ := status.FromError(err) + if st != nil { + attrs = trace.FromGRPCStatus(st.Code(), st.Message()) + } } log.Debug(err) if span != nil {