Skip to content

Commit

Permalink
fix(otelbench): avoid data race when collecting PromQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 16, 2024
1 parent bc636eb commit fdc0ba4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/otelbench/promql_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
Expand Down Expand Up @@ -75,7 +76,9 @@ type PromQL struct {
start time.Time
end time.Time

queries []tracedQuery
queries []tracedQuery
queriesMux sync.Mutex

reports []PromQLReportQuery
tracer trace.Tracer
}
Expand Down Expand Up @@ -261,7 +264,11 @@ func (p *PromQL) sendAndRecord(ctx context.Context, id int, q promproxy.Query) (
return errors.Wrap(err, "send")
}
tq.Duration = time.Since(start)

p.queriesMux.Lock()
p.queries = append(p.queries, tq)
p.queriesMux.Unlock()

return nil
}

Expand Down

0 comments on commit fdc0ba4

Please sign in to comment.