Skip to content

Commit 8af7455

Browse files
committed
Fix ES integration test race conditions
This change fixes two issues in ES integration tests: 1. Prevents index not found exceptions by proper index readiness checks 2. Prevents duplicate span detection issues The solution uses sync.Map for thread-safe: - Index existence caching - Span tracking Fixes jaegertracing#6094 Signed-off-by: ayush-gupta-dev <[email protected]>
1 parent 50eeed3 commit 8af7455

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

plugin/storage/es/spanstore/writer.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -201,31 +201,28 @@ func (s *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
201201
// Write with retries
202202
var lastErr error
203203
for i := 0; i < 3; i++ {
204-
if err := s.writeSpanWithResult(ctx, spanIndexName, jsonSpan); err == nil {
205-
s.logger.Debug("Successfully wrote span",
206-
zap.String("trace_id", span.TraceID.String()),
207-
zap.String("span_id", span.SpanID.String()),
208-
zap.String("index", spanIndexName))
204+
err := s.writeSpanWithResult(ctx, spanIndexName, jsonSpan)
205+
if err == nil {
209206
return nil
210-
} else {
211-
lastErr = err
212-
s.logger.Debug("Retrying span write",
213-
zap.String("index", spanIndexName),
214-
zap.Int("attempt", i+1),
215-
zap.Error(lastErr))
216207
}
208+
lastErr = err
209+
s.logger.Debug("Retrying span write",
210+
zap.String("index", spanIndexName),
211+
zap.Int("attempt", i+1),
212+
zap.Error(lastErr))
217213
time.Sleep(time.Duration(i+1) * 100 * time.Millisecond)
218214
}
219215

220216
return fmt.Errorf("failed to write span after retries: %w", lastErr)
221217
}
222218

223-
func (s *SpanWriter) writeSpanWithResult(ctx context.Context, indexName string, jsonSpan *dbmodel.Span) error {
224-
s.client().Index().
219+
func (s *SpanWriter) writeSpanWithResult(_ context.Context, indexName string, jsonSpan *dbmodel.Span) error {
220+
indexService := s.client().Index().
225221
Index(indexName).
226222
Type(spanType).
227-
BodyJson(jsonSpan).
228-
Add()
223+
BodyJson(jsonSpan)
224+
225+
indexService.Add()
229226
return nil
230227
}
231228

0 commit comments

Comments
 (0)