Skip to content

Commit

Permalink
remove data race from telemetry metrics hot pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Jan 31, 2025
1 parent 091c522 commit 8bc28bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions internal/newtelemetry/globalclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
globalClientRecorder = internal.NewRecorder[Client]()

// metricsHandleHotPointers contains all the metricsHotPointer, used to replay actions done before the actual MetricHandle is set
metricsHandleHotPointers []metricsHotPointer
metricsHandleHotPointers []*metricsHotPointer
metricsHandleHotPointersMu sync.Mutex
)

Expand Down Expand Up @@ -62,8 +62,7 @@ func SwapClient(client Client) {
metricsHandleHotPointersMu.Lock()
defer metricsHandleHotPointersMu.Unlock()
for i := range metricsHandleHotPointers {
hotPointer := &metricsHandleHotPointers[i]
hotPointer.swap(hotPointer.maker(client))
metricsHandleHotPointers[i].swap(metricsHandleHotPointers[i].maker(client))
}
}
}
Expand Down Expand Up @@ -236,8 +235,9 @@ func newMetricsHotPointer(maker func(client Client) MetricHandle) *metricsHotPoi
metricsHandleHotPointersMu.Lock()
defer metricsHandleHotPointersMu.Unlock()

metricsHandleHotPointers = append(metricsHandleHotPointers, metricsHotPointer{maker: maker})
return &metricsHandleHotPointers[len(metricsHandleHotPointers)-1]
hotPtr := &metricsHotPointer{maker: maker}
metricsHandleHotPointers = append(metricsHandleHotPointers, hotPtr)
return hotPtr
}

var metricLogLossOnce sync.Once
Expand Down
2 changes: 1 addition & 1 deletion internal/newtelemetry/internal/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestWriter_Flush_MultipleEndpoints(t *testing.T) {
assert.Zero(t, results[0].PayloadByteSize)

assert.Equal(t, http.StatusOK, results[1].StatusCode)
assert.InDelta(t, time.Duration(1), results[1].CallDuration, float64(time.Millisecond))
assert.InDelta(t, time.Duration(1), results[1].CallDuration, float64(time.Second))
assert.NotZero(t, results[1].PayloadByteSize)
assert.NoError(t, results[1].Error)

Expand Down

0 comments on commit 8bc28bc

Please sign in to comment.