Skip to content

Commit

Permalink
Fix race condition with Exemplar in Counter
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Oct 17, 2022
1 parent 9e13cd2 commit 7c2fd47
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prometheus/counter.go
Expand Up @@ -140,7 +140,8 @@ func (c *counter) get() float64 {
}

func (c *counter) Write(out *dto.Metric) error {

// Read the Exemplar first and the value second. This is to avoid a race condition
// where users see an exemplar for a not-yet-existing observation.
var exemplar *dto.Exemplar
if e := c.exemplar.Load(); e != nil {
exemplar = e.(*dto.Exemplar)
Expand Down

0 comments on commit 7c2fd47

Please sign in to comment.