Skip to content

Commit

Permalink
[test] Explicitly test writing traces with duplicate span ids (jaeger…
Browse files Browse the repository at this point in the history
…tracing#6254)

Signed-off-by: vaidikcode <[email protected]>

## Which problem is this PR solving?
Resolves jaegertracing#4466 

## Description of the changes
- 
added new testGetLargeSpanWithDuplicateIds with a method to generate
duplicate span ids and also fixed testGetLargeSpan to generate unique
ids
## How was this change tested?
- 

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`
  • Loading branch information
vaidikcode authored Nov 30, 2024
1 parent 91c8bef commit 2e5ed05
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions plugin/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ func (s *StorageIntegration) testGetLargeSpan(t *testing.T) {
s.skipIfNeeded(t)
defer s.cleanUp(t)

t.Log("Testing Large Trace over 10K ...")
expected := s.loadParseAndWriteLargeTrace(t)
t.Log("Testing Large Trace over 10K with duplicate IDs...")

expected := s.writeLargeTraceWithDuplicateSpanIds(t)
expectedTraceID := expected.Spans[0].TraceID

var actual *model.Trace
Expand All @@ -219,9 +220,22 @@ func (s *StorageIntegration) testGetLargeSpan(t *testing.T) {
actual, err = s.SpanReader.GetTrace(context.Background(), expectedTraceID)
return err == nil && len(actual.Spans) >= len(expected.Spans)
})

if !assert.True(t, found) {
CompareTraces(t, expected, actual)
return
}

duplicateCount := 0
seenIDs := make(map[model.SpanID]int)

for _, span := range actual.Spans {
seenIDs[span.SpanID]++
if seenIDs[span.SpanID] > 1 {
duplicateCount++
}
}
assert.Positive(t, duplicateCount, "Duplicate SpanIDs should be present in the trace")
}

func (s *StorageIntegration) testGetOperations(t *testing.T) {
Expand Down Expand Up @@ -365,19 +379,21 @@ func (s *StorageIntegration) loadParseAndWriteExampleTrace(t *testing.T) *model.
return trace
}

func (s *StorageIntegration) loadParseAndWriteLargeTrace(t *testing.T) *model.Trace {
func (s *StorageIntegration) writeLargeTraceWithDuplicateSpanIds(t *testing.T) *model.Trace {
trace := s.getTraceFixture(t, "example_trace")
span := trace.Spans[0]
spns := make([]*model.Span, 1, 10008)
trace.Spans = spns
trace.Spans[0] = span
for i := 1; i < 10008; i++ {
s := new(model.Span)
*s = *span
//nolint: gosec // G115
s.SpanID = model.SpanID(i)
s.StartTime = s.StartTime.Add(time.Second * time.Duration(i+1))
trace.Spans = append(trace.Spans, s)
repeatedSpan := trace.Spans[0]
trace.Spans = make([]*model.Span, 0, 10008)
for i := 0; i < 10008; i++ {
newSpan := new(model.Span)
*newSpan = *repeatedSpan
switch {
case i%100 == 0:
newSpan.SpanID = repeatedSpan.SpanID
default:
newSpan.SpanID = model.SpanID(i)
}
newSpan.StartTime = newSpan.StartTime.Add(time.Second * time.Duration(i+1))
trace.Spans = append(trace.Spans, newSpan)
}
s.writeTrace(t, trace)
return trace
Expand Down

0 comments on commit 2e5ed05

Please sign in to comment.