Skip to content

Commit 6d30007

Browse files
authored
[grpc][v2] Implement FindTraceIDs in gRPC v2 handler (#7003)
## Which problem is this PR solving? - Towards #6979 ## Description of the changes - Implement the `FindTraceIDs` call in the gRPC v2 handler ## How was this change tested? - Added unit tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab <[email protected]>
1 parent 862c09c commit 6d30007

File tree

2 files changed

+114
-11
lines changed

2 files changed

+114
-11
lines changed

internal/storage/v2/grpc/handler.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,7 @@ func (h *Handler) FindTraces(
103103
req *storage.FindTracesRequest,
104104
srv storage.TraceReader_FindTracesServer,
105105
) error {
106-
query := tracestore.TraceQueryParams{
107-
ServiceName: req.Query.ServiceName,
108-
OperationName: req.Query.OperationName,
109-
Attributes: convertKeyValueListToMap(req.Query.Attributes),
110-
StartTimeMin: req.Query.StartTimeMin,
111-
StartTimeMax: req.Query.StartTimeMax,
112-
DurationMin: req.Query.DurationMin,
113-
DurationMax: req.Query.DurationMax,
114-
SearchDepth: int(req.Query.SearchDepth),
115-
}
116-
for traces, err := range h.traceReader.FindTraces(srv.Context(), query) {
106+
for traces, err := range h.traceReader.FindTraces(srv.Context(), toTraceQueryParams(req.Query)) {
117107
if err != nil {
118108
return err
119109
}
@@ -127,6 +117,41 @@ func (h *Handler) FindTraces(
127117
return nil
128118
}
129119

120+
func (h *Handler) FindTraceIDs(
121+
ctx context.Context,
122+
req *storage.FindTracesRequest,
123+
) (*storage.FindTraceIDsResponse, error) {
124+
foundTraceIDs := []*storage.FoundTraceID{}
125+
for traceIDs, err := range h.traceReader.FindTraceIDs(ctx, toTraceQueryParams(req.Query)) {
126+
if err != nil {
127+
return nil, err
128+
}
129+
for _, traceID := range traceIDs {
130+
foundTraceIDs = append(foundTraceIDs, &storage.FoundTraceID{
131+
TraceId: traceID.TraceID[:],
132+
Start: traceID.Start,
133+
End: traceID.End,
134+
})
135+
}
136+
}
137+
return &storage.FindTraceIDsResponse{
138+
TraceIds: foundTraceIDs,
139+
}, nil
140+
}
141+
142+
func toTraceQueryParams(t *storage.TraceQueryParameters) tracestore.TraceQueryParams {
143+
return tracestore.TraceQueryParams{
144+
ServiceName: t.ServiceName,
145+
OperationName: t.OperationName,
146+
Attributes: convertKeyValueListToMap(t.Attributes),
147+
StartTimeMin: t.StartTimeMin,
148+
StartTimeMax: t.StartTimeMax,
149+
DurationMin: t.DurationMin,
150+
DurationMax: t.DurationMax,
151+
SearchDepth: int(t.SearchDepth),
152+
}
153+
}
154+
130155
func convertKeyValueListToMap(kvList []*storage.KeyValue) pcommon.Map {
131156
m := pcommon.NewMap()
132157
for _, kv := range kvList {

internal/storage/v2/grpc/handler_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,84 @@ func TestHandler_FindTraces(t *testing.T) {
311311
}
312312
}
313313

314+
func TestHandler_FindTraceIDs(t *testing.T) {
315+
reader := new(tracestoremocks.Reader)
316+
query := tracestore.TraceQueryParams{
317+
ServiceName: "service",
318+
OperationName: "operation",
319+
Attributes: pcommon.NewMap(),
320+
}
321+
now := time.Now()
322+
traceIDA := [16]byte{1}
323+
traceIDB := [16]byte{2}
324+
tests := []struct {
325+
name string
326+
traceIDs []tracestore.FoundTraceID
327+
expectedTraceIDs []*storage.FoundTraceID
328+
findTraceIDsErr error
329+
expectedErr error
330+
}{
331+
{
332+
name: "success",
333+
traceIDs: []tracestore.FoundTraceID{
334+
{
335+
TraceID: traceIDA,
336+
Start: now,
337+
End: now.Add(time.Minute),
338+
},
339+
{
340+
TraceID: traceIDB,
341+
Start: now,
342+
End: now.Add(time.Hour),
343+
},
344+
},
345+
expectedTraceIDs: []*storage.FoundTraceID{
346+
{
347+
TraceId: traceIDA[:],
348+
Start: now,
349+
End: now.Add(time.Minute),
350+
},
351+
{
352+
TraceId: traceIDB[:],
353+
Start: now,
354+
End: now.Add(time.Hour),
355+
},
356+
},
357+
},
358+
{
359+
name: "empty",
360+
traceIDs: []tracestore.FoundTraceID{},
361+
expectedTraceIDs: []*storage.FoundTraceID{},
362+
},
363+
{
364+
name: "error",
365+
findTraceIDsErr: assert.AnError,
366+
expectedErr: assert.AnError,
367+
},
368+
}
369+
370+
for _, test := range tests {
371+
reader.On("FindTraceIDs", mock.Anything, query).
372+
Return(iter.Seq2[[]tracestore.FoundTraceID, error](func(yield func([]tracestore.FoundTraceID, error) bool) {
373+
yield(test.traceIDs, test.findTraceIDsErr)
374+
})).Once()
375+
server := NewHandler(reader)
376+
377+
response, err := server.FindTraceIDs(context.Background(), &storage.FindTracesRequest{
378+
Query: &storage.TraceQueryParameters{
379+
ServiceName: "service",
380+
OperationName: "operation",
381+
},
382+
})
383+
if test.expectedErr != nil {
384+
require.ErrorIs(t, err, test.expectedErr)
385+
} else {
386+
require.NoError(t, err)
387+
require.Equal(t, test.expectedTraceIDs, response.TraceIds)
388+
}
389+
}
390+
}
391+
314392
func TestConvertKeyValueListToMap(t *testing.T) {
315393
tests := []struct {
316394
name string

0 commit comments

Comments
 (0)