Skip to content

Commit

Permalink
Add Condition For Too Many Traces
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Jan 5, 2025
1 parent 153ff63 commit fa5db45
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions storage_v2/v1adapter/spanreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package v1adapter

import (
"context"
"errors"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
Expand All @@ -13,6 +14,8 @@ import (

var _ spanstore.Reader = (*SpanReader)(nil)

var errTooManyTracesFound = errors.New("too many traces found")

// SpanReader wraps a tracestore.Reader so that it can be downgraded to implement
// the v1 spanstore.Reader interface.
type SpanReader struct {
Expand All @@ -37,6 +40,8 @@ func (sr *SpanReader) GetTrace(ctx context.Context, query spanstore.GetTracePara
}
if len(traces) == 0 {
return nil, spanstore.ErrTraceNotFound
} else if len(traces) > 1 {
return nil, errTooManyTracesFound
}
return traces[0], nil
}
Expand Down
29 changes: 28 additions & 1 deletion storage_v2/v1adapter/spanreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,34 @@ func TestSpanReader_GetTrace(t *testing.T) {
expectedErr: spanstore.ErrTraceNotFound,
},
{
name: "succses",
name: "too many traces found",
query: spanstore.GetTraceParameters{
TraceID: model.NewTraceID(1, 2),
},
expectedQuery: tracestore.GetTraceParams{
TraceID: [16]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2},
},
traces: func() []ptrace.Traces {
traces1 := ptrace.NewTraces()
resources1 := traces1.ResourceSpans().AppendEmpty()
resources1.Resource().Attributes().PutStr("service.name", "service1")
scopes1 := resources1.ScopeSpans().AppendEmpty()
span1 := scopes1.Spans().AppendEmpty()
span1.SetTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2})

traces2 := ptrace.NewTraces()
resources2 := traces2.ResourceSpans().AppendEmpty()
resources2.Resource().Attributes().PutStr("service.name", "service1")
scopes2 := resources2.ScopeSpans().AppendEmpty()
span2 := scopes2.Spans().AppendEmpty()
span2.SetTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3})

return []ptrace.Traces{traces1, traces2}
}(),
expectedErr: errTooManyTracesFound,
},
{
name: "success",
query: spanstore.GetTraceParameters{
TraceID: model.NewTraceID(1, 2),
},
Expand Down

0 comments on commit fa5db45

Please sign in to comment.