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

Handling of expected error codes coming from grpc storage plugins #1741 #1814

Merged
merged 6 commits into from
Oct 9, 2019
6 changes: 6 additions & 0 deletions plugin/storage/grpc/shared/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/pkg/errors"
"google.golang.org/grpc/status"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/storage_v1"
Expand Down Expand Up @@ -61,6 +62,11 @@ 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 {
if e.Message() == spanstore.ErrTraceNotFound.Error() {
return nil, spanstore.ErrTraceNotFound
}
}
return nil, errors.Wrap(err, "grpc stream error")
}

Expand Down
14 changes: 14 additions & 0 deletions plugin/storage/grpc/shared/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ func TestGRPCClientGetTrace_NoTrace(t *testing.T) {
})
}

func TestGRPCClientGetTrace_StreamErrorTraceNotFound(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
traceClient := new(grpcMocks.SpanReaderPlugin_GetTraceClient)
traceClient.On("Recv").Return(nil, spanstore.ErrTraceNotFound)
r.spanReader.On("GetTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
}).Return(traceClient, nil)

s, err := r.client.GetTrace(context.Background(), mockTraceID)
assert.Error(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

that doesn't test the issue, you probably want ErrorEquals method

Copy link
Member

Choose a reason for hiding this comment

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

or simply assert.Equals(t, spanstore.ErrTraceNotFound, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

assert.Nil(t, s)
})
}

func TestGRPCClientFindTraces(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
traceClient := new(grpcMocks.SpanReaderPlugin_FindTracesClient)
Expand Down
4 changes: 1 addition & 3 deletions plugin/storage/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)

var errTraceNotFound = errors.New("trace was not found")

// Store is an in-memory store of traces
type Store struct {
sync.RWMutex
Expand Down Expand Up @@ -154,7 +152,7 @@ func (m *Store) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Tra
defer m.RUnlock()
retMe := m.traces[traceID]
if retMe == nil {
return nil, errTraceNotFound
return nil, spanstore.ErrTraceNotFound
}
return retMe, nil
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestStoreGetTraceSuccess(t *testing.T) {
func TestStoreGetTraceFailure(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
trace, err := store.GetTrace(context.Background(), model.TraceID{})
assert.EqualError(t, err, errTraceNotFound.Error())
assert.EqualError(t, err, spanstore.ErrTraceNotFound.Error())
assert.Nil(t, trace)
})
}
Expand Down