Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testbed] Detect and fix data race at testbed integration test #30549

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func (ocr *Receiver) processReceivedMsg(
func (ocr *Receiver) sendToNextConsumer(longLivedRPCCtx context.Context, td ptrace.Traces) error {
ctx := ocr.obsrecv.StartTracesOp(longLivedRPCCtx)

numReceivedSpans := td.SpanCount()
err := ocr.nextConsumer.ConsumeTraces(ctx, td)
ocr.obsrecv.EndTracesOp(ctx, receiverDataFormat, td.SpanCount(), err)
ocr.obsrecv.EndTracesOp(ctx, receiverDataFormat, numReceivedSpans, err)

return err
}
3 changes: 2 additions & 1 deletion receiver/zipkinreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,14 @@ func (zr *zipkinReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

numReceivedSpans := td.SpanCount()
consumerErr := zr.nextConsumer.ConsumeTraces(ctx, td)

receiverTagValue := zipkinV2TagValue
if asZipkinv1 {
receiverTagValue = zipkinV1TagValue
}
obsrecv.EndTracesOp(ctx, receiverTagValue, td.SpanCount(), consumerErr)
obsrecv.EndTracesOp(ctx, receiverTagValue, numReceivedSpans, consumerErr)
if consumerErr == nil {
// Send back the response "Accepted" as
// required at https://zipkin.io/zipkin-api/#/default/post_spans
Expand Down
5 changes: 5 additions & 0 deletions testbed/testbed/load_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ProviderSender struct {
// Number of data items (spans or metric data points) sent.
dataItemsSent atomic.Uint64
startedAt time.Time
startMutex sync.Mutex

// Number of permanent errors received
permanentErrors atomic.Uint64
Expand Down Expand Up @@ -116,6 +117,8 @@ func (ps *ProviderSender) Start(options LoadOptions) {

// Begin generation
go ps.generate()
ps.startMutex.Lock()
defer ps.startMutex.Unlock()
ps.startedAt = time.Now()
}

Expand Down Expand Up @@ -148,6 +151,8 @@ func (ps *ProviderSender) IsReady() bool {

// GetStats returns the stats as a printable string.
func (ps *ProviderSender) GetStats() string {
ps.startMutex.Lock()
defer ps.startMutex.Unlock()
sent := ps.DataItemsSent()
return printer.Sprintf("Sent:%10d %s (%d/sec)", sent, ps.sendType, int(float64(sent)/time.Since(ps.startedAt).Seconds()))
}
Expand Down
14 changes: 9 additions & 5 deletions testbed/testbed/mock_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ type MockBackend struct {
logFile *os.File

// Start/stop flags
isStarted bool
stopOnce sync.Once
startedAt time.Time
isStarted bool
stopOnce sync.Once
startedAt time.Time
startMutex sync.Mutex

// Recording fields.
isRecording bool
Expand Down Expand Up @@ -100,6 +101,8 @@ func (mb *MockBackend) Start() error {
}

mb.isStarted = true
mb.startMutex.Lock()
defer mb.startMutex.Unlock()
mb.startedAt = time.Now()
return nil
}
Expand Down Expand Up @@ -130,6 +133,8 @@ func (mb *MockBackend) EnableRecording() {
}

func (mb *MockBackend) GetStats() string {
mb.startMutex.Lock()
defer mb.startMutex.Unlock()
received := mb.DataItemsReceived()
return printer.Sprintf("Received:%10d items (%d/sec)", received, int(float64(received)/time.Since(mb.startedAt).Seconds()))
}
Expand Down Expand Up @@ -190,8 +195,6 @@ func (tc *MockTraceConsumer) ConsumeTraces(_ context.Context, td ptrace.Traces)
return err
}

tc.numSpansReceived.Add(uint64(td.SpanCount()))

rs := td.ResourceSpans()
for i := 0; i < rs.Len(); i++ {
ils := rs.At(i).ScopeSpans()
Expand Down Expand Up @@ -221,6 +224,7 @@ func (tc *MockTraceConsumer) ConsumeTraces(_ context.Context, td ptrace.Traces)
}

tc.backend.ConsumeTrace(td)
tc.numSpansReceived.Add(uint64(td.SpanCount()))

return nil
}
Expand Down
Loading