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 1 commit
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,15 +162,15 @@
}()
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)

Check failure on line 165 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 165 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
if st != nil && sspan != nil {

Check failure on line 166 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 166 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)

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

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

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

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamLocation{
Payload: &payload.Object_StreamLocation_Status{
Status: st.Proto(),

Check failure on line 173 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 173 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
},
}, err
}
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)

Check failure on line 184 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 184 in pkg/agent/core/ngt/handler/grpc/insert.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
if st != nil && span != nil {

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

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

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

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)

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

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

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

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down
77 changes: 24 additions & 53 deletions pkg/agent/core/ngt/handler/grpc/linear_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,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)

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

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

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

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
if st != nil && sspan != nil {

Check failure on line 348 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 348 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)

Check failure on line 350 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View workflow job for this annotation

GitHub Actions / grpc-sequential

undefined: st

Check failure on line 350 in pkg/agent/core/ngt/handler/grpc/linear_search.go

View workflow job for this annotation

GitHub Actions / grpc-stream

undefined: st
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -363,11 +363,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 && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand All @@ -394,10 +393,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 {
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -413,10 +412,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 && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down Expand Up @@ -454,15 +453,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 {
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -480,19 +474,10 @@
}
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 {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -530,15 +515,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 {
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -556,19 +536,10 @@
}
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 {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down
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 @@ 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 GetObject 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamVector{
Expand All @@ -170,10 +170,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 StreamGetObject gRPC error response")
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}

Expand Down
27 changes: 9 additions & 18 deletions pkg/agent/core/ngt/handler/grpc/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,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 Remove 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Object_StreamLocation{
Expand All @@ -176,10 +176,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 StreamRemove gRPC error response")
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down Expand Up @@ -314,20 +314,11 @@ func (s *server) RemoveByTimestamp(
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),
},
)
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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down
77 changes: 24 additions & 53 deletions pkg/agent/core/ngt/handler/grpc/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,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 Search 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -367,11 +367,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 StreamSearch gRPC error response")
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand All @@ -396,10 +395,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 SearchByID 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
return &payload.Search_StreamResponse{
Expand All @@ -415,10 +414,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 StreamSearchByID gRPC error response")
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return err
Expand Down Expand Up @@ -456,15 +455,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 Search 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -482,19 +476,10 @@ func (s *server) MultiSearch(
}
wg.Wait()
if errs != nil {
st, msg, err := status.ParseError(errs, codes.Internal,
"failed to parse MultiSearch gRPC error response",
&errdetails.RequestInfo{
RequestId: strings.Join(rids, ","),
ServingData: errdetails.Serialize(reqs),
},
&errdetails.ResourceInfo{
ResourceType: ngtResourceType + "/ngt.MultiSearch",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -532,15 +517,10 @@ func (s *server) MultiSearchByID(
defer wg.Done()
r, err := s.SearchByID(ctx, query)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse SearchByID 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.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
sspan.SetStatus(trace.StatusError, err.Error())
}
mu.Lock()
Expand All @@ -558,19 +538,10 @@ func (s *server) MultiSearchByID(
}
wg.Wait()
if errs != nil {
st, msg, err := status.ParseError(errs, codes.Internal,
"failed to parse MultiSearchByID gRPC error response",
&errdetails.RequestInfo{
RequestId: strings.Join(rids, ","),
ServingData: errdetails.Serialize(reqs),
},
&errdetails.ResourceInfo{
ResourceType: ngtResourceType + "/ngt.MultiSearchByID",
ResourceName: fmt.Sprintf("%s: %s(%s)", apiName, s.name, s.ip),
})
if span != nil {
st, _ = status.FromError(err)
if st != nil && sspan != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Massage())...)
datelier marked this conversation as resolved.
Show resolved Hide resolved
datelier marked this conversation as resolved.
Show resolved Hide resolved
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down
Loading
Loading