Skip to content

Commit 205bf1d

Browse files
committed
fix(test): Surface trace writer chunk errors
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
1 parent 2199381 commit 205bf1d

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

cmd/jaeger/internal/integration/trace_writer.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ func (w *traceWriter) WriteTraces(ctx context.Context, td ptrace.Traces) error {
9494
)
9595

9696
if spanCount == MaxChunkSize {
97-
err = w.exporter.ConsumeTraces(ctx, currentChunk)
97+
if err = w.exporter.ConsumeTraces(ctx, currentChunk); err != nil {
98+
return false
99+
}
98100
currentChunk = ptrace.NewTraces()
99101
spanCount = 0
100102
currentResourceIndex = -1
@@ -123,10 +125,13 @@ func (w *traceWriter) WriteTraces(ctx context.Context, td ptrace.Traces) error {
123125

124126
return true
125127
})
128+
if err != nil {
129+
return err
130+
}
126131

127132
// write the last chunk if it has any spans
128133
if spanCount > 0 {
129-
err = w.exporter.ConsumeTraces(ctx, currentChunk)
134+
return w.exporter.ConsumeTraces(ctx, currentChunk)
130135
}
131-
return err
136+
return nil
132137
}

cmd/jaeger/internal/integration/trace_writer_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"testing"
1011

@@ -122,3 +123,36 @@ func TestWriteTraces(t *testing.T) {
122123
thirdChunkScope := thirdChunkResource.ScopeSpans().At(0)
123124
assert.Equal(t, "span5", thirdChunkScope.Spans().At(0).Name())
124125
}
126+
127+
func TestWriteTracesReturnsIntermediateChunkError(t *testing.T) {
128+
td := ptrace.NewTraces()
129+
resource := td.ResourceSpans().AppendEmpty()
130+
scope := resource.ScopeSpans().AppendEmpty()
131+
for i := 1; i <= 3; i++ {
132+
span := scope.Spans().AppendEmpty()
133+
span.SetSpanID(pcommon.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, byte(i)}))
134+
span.SetName(fmt.Sprintf("span%d", i))
135+
}
136+
137+
expectedErr := errors.New("send failed")
138+
mockExporter := &MockExporter{}
139+
mockExporter.On("ConsumeTraces", mock.Anything, mock.Anything).Return(expectedErr).Once()
140+
tw := &traceWriter{
141+
logger: zaptest.NewLogger(t),
142+
exporter: mockExporter,
143+
}
144+
145+
origMaxChunkSize := MaxChunkSize
146+
MaxChunkSize = 2
147+
defer func() {
148+
MaxChunkSize = origMaxChunkSize
149+
}()
150+
151+
err := tw.WriteTraces(context.Background(), td)
152+
153+
require.ErrorIs(t, err, expectedErr)
154+
mockExporter.AssertNumberOfCalls(t, "ConsumeTraces", 1)
155+
mockExporter.AssertExpectations(t)
156+
require.Len(t, mockExporter.chunks, 1)
157+
assert.Equal(t, 2, mockExporter.chunks[0].SpanCount())
158+
}

0 commit comments

Comments
 (0)