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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 @@
"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 @@
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) {

Check warning on line 60 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L60

Added line #L60 was not covered by tests
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 @@
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())

Check warning on line 239 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L239

Added line #L239 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeInternal(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 242 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L242

Added line #L242 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
return nil, attrs, err

Check warning on line 245 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L245

Added line #L245 was not covered by tests
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 @@
ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
}, info.Get(),
)
attrs = trace.StatusCodeDeadlineExceeded(err.Error())

Check warning on line 266 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L266

Added line #L266 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeDeadlineExceeded(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 269 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L269

Added line #L269 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
return nil, attrs, err

Check warning on line 272 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L272

Added line #L272 was not covered by tests
}
if 0 < min && len(res.GetResults()) < min {
err = status.WrapWithDeadlineExceeded(
Expand All @@ -281,12 +284,13 @@
ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
}, info.Get(),
)
attrs = trace.StatusCodeDeadlineExceeded(err.Error())

Check warning on line 287 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L287

Added line #L287 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeDeadlineExceeded(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 290 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L290

Added line #L290 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
return nil, attrs, err

Check warning on line 293 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L293

Added line #L293 was not covered by tests
}
}

Expand All @@ -301,14 +305,15 @@
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)

Check warning on line 308 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L308

Added line #L308 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(attrs...)

Check warning on line 311 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L311

Added line #L311 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
log.Warn(err)
if len(res.GetResults()) == 0 {
return nil, err
return nil, attrs, err

Check warning on line 316 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L316

Added line #L316 was not covered by tests
}
}
if num != 0 && len(res.GetResults()) == 0 {
Expand All @@ -324,21 +329,23 @@
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())

Check warning on line 332 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L332

Added line #L332 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeNotFound(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 335 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L335

Added line #L335 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
return nil, attrs, err

Check warning on line 338 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L338

Added line #L338 was not covered by tests
}

if 0 < min && len(res.GetResults()) < min {
if err == nil {
err = errors.ErrInsuffcientSearchResult
}
attrs = trace.StatusCodeNotFound(err.Error())

Check warning on line 345 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L345

Added line #L345 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeNotFound(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 348 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L348

Added line #L348 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
err = status.WrapWithNotFound(
Expand All @@ -353,15 +360,16 @@
ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
}, info.Get(),
)
attrs = trace.StatusCodeNotFound(err.Error())

Check warning on line 363 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L363

Added line #L363 was not covered by tests
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.StatusCodeNotFound(err.Error())...)
span.SetAttributes(attrs...)

Check warning on line 366 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L366

Added line #L366 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
return nil, attrs, err

Check warning on line 369 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L369

Added line #L369 was not covered by tests
}
res.RequestId = bcfg.GetRequestId()
return res, nil
return res, attrs, nil

Check warning on line 372 in pkg/gateway/lb/handler/grpc/aggregation.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lb/handler/grpc/aggregation.go#L372

Added line #L372 was not covered by tests
}

// vald standard algorithm.
Expand Down
Loading
Loading