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

modify ParseError to FromError for agent handler #2667

Merged
merged 7 commits into from
Oct 8, 2024
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
12 changes: 6 additions & 6 deletions pkg/agent/core/ngt/handler/grpc/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@
}()
res, err := s.Insert(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse Insert 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())...)

Check warning on line 168 in pkg/agent/core/ngt/handler/grpc/insert.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/insert.go#L168

Added line #L168 was not covered by tests
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamLocation{
Expand All @@ -181,10 +181,10 @@
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse StreamInsert gRPC error response")
if span != nil {
st, _ := status.FromError(err)
if st != nil && span != nil {

Check warning on line 185 in pkg/agent/core/ngt/handler/grpc/insert.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/insert.go#L184-L185

Added lines #L184 - L185 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 187 in pkg/agent/core/ngt/handler/grpc/insert.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/insert.go#L187

Added line #L187 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down
90 changes: 30 additions & 60 deletions pkg/agent/core/ngt/handler/grpc/linear_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"github.com/vdaas/vald/internal/info"
"github.com/vdaas/vald/internal/log"
"github.com/vdaas/vald/internal/net/grpc"
"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"
Expand Down Expand Up @@ -344,10 +343,10 @@
}()
res, err := s.LinearSearch(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse LinearSearch gRPC error response")
if sspan != nil {
st, _ := status.FromError(err)
if st != nil && sspan != nil {

Check warning on line 347 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L346-L347

Added lines #L346 - L347 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 349 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L349

Added line #L349 was not covered by tests
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -363,11 +362,10 @@
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse StreamLinearSearch gRPC error response")
if span != nil {
st, _ := status.FromError(err)
if st != nil && span != nil {

Check warning on line 366 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L365-L366

Added lines #L365 - L366 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 368 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L368

Added line #L368 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand All @@ -394,10 +392,10 @@
}()
res, err := s.LinearSearchByID(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse LinearSearchByID gRPC error response")
if sspan != nil {
st, _ := status.FromError(err)
if st != nil && sspan != nil {

Check warning on line 396 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L395-L396

Added lines #L395 - L396 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 398 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L398

Added line #L398 was not covered by tests
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -413,10 +411,10 @@
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse StreamLinearSearchByID gRPC error response")
if span != nil {
st, _ := status.FromError(err)
if st != nil && span != nil {

Check warning on line 415 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L414-L415

Added lines #L414 - L415 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 417 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L417

Added line #L417 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down Expand Up @@ -454,15 +452,10 @@
}()
r, err := s.LinearSearch(ctx, query)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse LinearSearch 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 {

Check warning on line 456 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L455-L456

Added lines #L455 - L456 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 458 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L458

Added line #L458 was not covered by tests
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -480,22 +473,13 @@
}
wg.Wait()
if errs != nil {
st, msg, err := status.ParseError(errs, codes.Internal,
"failed to parse MultiLinearSearch gRPC error response",
&errdetails.RequestInfo{
RequestId: strings.Join(rids, ","),
ServingData: errdetails.Serialize(reqs),
},
&errdetails.ResourceInfo{
ResourceType: ngtResourceType + "/ngt.MultiLinearSearch",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
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())

Check warning on line 480 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L476-L480

Added lines #L476 - L480 were not covered by tests
}
return nil, err
return nil, errs

Check warning on line 482 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L482

Added line #L482 was not covered by tests
}
return res, nil
}
Expand Down Expand Up @@ -530,15 +514,10 @@
defer wg.Done()
r, err := s.LinearSearchByID(ctx, query)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse LinearSearchByID 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 {

Check warning on line 518 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L517-L518

Added lines #L517 - L518 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 520 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L520

Added line #L520 was not covered by tests
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -556,22 +535,13 @@
}
wg.Wait()
if errs != nil {
st, msg, err := status.ParseError(errs, codes.Internal,
"failed to parse MultiLinearSearchByID gRPC error response",
&errdetails.RequestInfo{
RequestId: strings.Join(rids, ","),
ServingData: errdetails.Serialize(reqs),
},
&errdetails.ResourceInfo{
ResourceType: ngtResourceType + "/ngt.MultiLinearSearchByID",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
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())

Check warning on line 542 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L538-L542

Added lines #L538 - L542 were not covered by tests
}
return nil, err
return nil, errs

Check warning on line 544 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/linear_search.go#L544

Added line #L544 was not covered by tests
}
return res, nil
}
12 changes: 6 additions & 6 deletions pkg/agent/core/ngt/handler/grpc/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@
}()
res, err := s.GetObject(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse GetObject gRPC error response")
if sspan != nil {
st, _ := status.FromError(err)
if st != nil && sspan != nil {

Check warning on line 155 in pkg/agent/core/ngt/handler/grpc/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/object.go#L154-L155

Added lines #L154 - L155 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 157 in pkg/agent/core/ngt/handler/grpc/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/object.go#L157

Added line #L157 was not covered by tests
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamVector{
Expand All @@ -170,10 +170,10 @@
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse StreamGetObject gRPC error response")
if span != nil {
st, _ := status.FromError(err)
if st != nil && span != nil {

Check warning on line 174 in pkg/agent/core/ngt/handler/grpc/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/object.go#L173-L174

Added lines #L173 - L174 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 176 in pkg/agent/core/ngt/handler/grpc/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/object.go#L176

Added line #L176 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}

Expand Down
36 changes: 13 additions & 23 deletions pkg/agent/core/ngt/handler/grpc/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"github.com/vdaas/vald/internal/info"
"github.com/vdaas/vald/internal/log"
"github.com/vdaas/vald/internal/net/grpc"
"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"
Expand Down Expand Up @@ -157,10 +156,10 @@
}()
res, err := s.Remove(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse Remove gRPC error response")
if sspan != nil {
st, _ := status.FromError(err)
if st != nil && sspan != nil {

Check warning on line 160 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L159-L160

Added lines #L159 - L160 were not covered by tests
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 162 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L162

Added line #L162 was not covered by tests
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamLocation{
Expand All @@ -176,10 +175,10 @@
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse StreamRemove gRPC error response")
if span != nil {
st, _ := status.FromError(err)
if st != nil && span != nil {

Check warning on line 179 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L178-L179

Added lines #L178 - L179 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 181 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L181

Added line #L181 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down Expand Up @@ -314,23 +313,14 @@
return true
})
if errs != nil {
st, msg, err := status.ParseError(errs, codes.Internal,
"failed to parse "+vald.RemoveByTimestampRPCName+" gRPC error response",
&errdetails.RequestInfo{
ServingData: errdetails.Serialize(req),
},
&errdetails.ResourceInfo{
ResourceType: ngtResourceType + "/ngt.Remove",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
},
)
log.Error(err)
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetStatus(trace.StatusError, err.Error())
st, _ := status.FromError(errs)
log.Error(errs)
if st != nil && span != nil {
span.RecordError(errs)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, errs.Error())

Check warning on line 321 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L316-L321

Added lines #L316 - L321 were not covered by tests
}
return nil, err
return nil, errs

Check warning on line 323 in pkg/agent/core/ngt/handler/grpc/remove.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/remove.go#L323

Added line #L323 was not covered by tests
}
if locs == nil || len(locs.GetLocations()) == 0 {
err := status.WrapWithNotFound(
Expand Down
Loading
Loading