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 gRPC error msg handling for lb-gateway handler #2663

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 23 additions & 15 deletions pkg/gateway/lb/handler/grpc/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
vankichi marked this conversation as resolved.
Show resolved Hide resolved
ctx, span := trace.StartSpan(grpc.WrapGRPCMethod(ctx, "aggregationSearch"), apiName+"/aggregationSearch")
defer func() {
if span != nil {
Expand Down Expand Up @@ -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
vankichi marked this conversation as resolved.
Show resolved Hide resolved
}
res = aggr.Result()
if num != 0 && len(res.GetResults()) > num {
Expand All @@ -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(
Expand All @@ -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
}
}

Expand All @@ -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 {
Expand All @@ -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(
Expand All @@ -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.
Expand Down
Loading
Loading