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

Propagate TraceNotFound error from grpc storage plugins #2455

Merged
merged 5 commits into from
Sep 7, 2020
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
7 changes: 3 additions & 4 deletions plugin/storage/grpc/shared/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*mode
trace := model.Trace{}
for received, err := stream.Recv(); err != io.EOF; received, err = stream.Recv() {
if err != nil {
if e, ok := status.FromError(err); !ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't this if statement mostly correct, except the condition should be ok instead of !ok?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's true. I prefer what I have pushed b/c it doesn't matter if err is an error or a status.Status if the message is "trace not found" then it will return the correct error.

We can do the minimal change if it's preferred though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original version (aside from !ok) seems better, because your version is ignoring the error, so s may be undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. I am relying on status.FromError to return a non-nil status. I think this would the best construction

if s, _ := status.FromError(err); s != nil {
  // check if s is a trace not found error.
}

ok just indicates if FromError had to create a new status.Status or if it was able to retrieve one using the GRPCStatus() method. For our purposes we don't care, we're just going to compare s.Message() to "trace not found" either way.

if e.Message() == spanstore.ErrTraceNotFound.Error() {
return nil, spanstore.ErrTraceNotFound
}
s, _ := status.FromError(err)
if s.Message() == spanstore.ErrTraceNotFound.Error() {
return nil, spanstore.ErrTraceNotFound
}
return nil, fmt.Errorf("grpc stream error: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion plugin/storage/grpc/shared/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/storage_v1"
Expand Down Expand Up @@ -200,9 +201,11 @@ func TestGRPCClientGetTrace_NoTrace(t *testing.T) {
}

func TestGRPCClientGetTrace_StreamErrorTraceNotFound(t *testing.T) {
s, _ := status.FromError(spanstore.ErrTraceNotFound)

withGRPCClient(func(r *grpcClientTest) {
traceClient := new(grpcMocks.SpanReaderPlugin_GetTraceClient)
traceClient.On("Recv").Return(nil, spanstore.ErrTraceNotFound)
traceClient.On("Recv").Return(nil, s.Err())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should write a test that goes through client and server, not just mocking the client.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I can't say I have time right now to knock it out. Perhaps if i find some time in the next week or two I'll dig into it.

r.spanReader.On("GetTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
}).Return(traceClient, nil)
Expand Down