Skip to content

Commit

Permalink
Propagate TraceNotFound error from grpc storage plugins jaegertracing…
Browse files Browse the repository at this point in the history
…#1741 (jaegertracing#1814)

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

Signed-off-by: chandresh-pancholi <chandreshpancholi007@gmail.com>

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

Signed-off-by: chandresh-pancholi <chandreshpancholi007@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
chandresh-pancholi authored and rubenvp8510 committed Oct 10, 2019
1 parent b217e1b commit bf90ada
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
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 @@ -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"
Expand Down Expand Up @@ -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")
}

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 @@ -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)
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

0 comments on commit bf90ada

Please sign in to comment.