From 2d69ce6fb520290581012f52321a7914c52b617b Mon Sep 17 00:00:00 2001 From: Chandresh Pancholi <3134439+chandresh-pancholi@users.noreply.github.com> Date: Thu, 10 Oct 2019 03:36:54 +0530 Subject: [PATCH] Propagate TraceNotFound error from grpc storage plugins #1741 (#1814) * Handling of expected error codes coming from grpc storage plugins #1741 Signed-off-by: chandresh-pancholi * Handling of expected error codes coming from grpc storage plugins #1741 Signed-off-by: chandresh-pancholi Signed-off-by: radekg --- plugin/storage/grpc/shared/grpc_client.go | 6 ++++++ plugin/storage/grpc/shared/grpc_client_test.go | 14 ++++++++++++++ plugin/storage/memory/memory.go | 4 +--- plugin/storage/memory/memory_test.go | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugin/storage/grpc/shared/grpc_client.go b/plugin/storage/grpc/shared/grpc_client.go index 4c715f2ea8a..89fe9e9dc86 100644 --- a/plugin/storage/grpc/shared/grpc_client.go +++ b/plugin/storage/grpc/shared/grpc_client.go @@ -21,6 +21,7 @@ import ( "github.com/pkg/errors" "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/proto-gen/storage_v1" @@ -76,6 +77,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") } diff --git a/plugin/storage/grpc/shared/grpc_client_test.go b/plugin/storage/grpc/shared/grpc_client_test.go index 7b6b295557b..6adacf3e27c 100644 --- a/plugin/storage/grpc/shared/grpc_client_test.go +++ b/plugin/storage/grpc/shared/grpc_client_test.go @@ -183,6 +183,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.Equal(t, spanstore.ErrTraceNotFound, err) + assert.Nil(t, s) + }) +} + func TestGRPCClientFindTraces(t *testing.T) { withGRPCClient(func(r *grpcClientTest) { traceClient := new(grpcMocks.SpanReaderPlugin_FindTracesClient) diff --git a/plugin/storage/memory/memory.go b/plugin/storage/memory/memory.go index e5727642985..f4fc9f22d00 100644 --- a/plugin/storage/memory/memory.go +++ b/plugin/storage/memory/memory.go @@ -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 @@ -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 } diff --git a/plugin/storage/memory/memory_test.go b/plugin/storage/memory/memory_test.go index ac3efc16454..497606bacd2 100644 --- a/plugin/storage/memory/memory_test.go +++ b/plugin/storage/memory/memory_test.go @@ -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) }) }