Skip to content

Commit

Permalink
Query: fix exemplarsServer data race (#4777)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmiehan <hanjinming@outlook.com>
  • Loading branch information
hanjm committed Oct 28, 2021
1 parent 5eacdf0 commit 27c6178
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/exemplars/exemplars.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package exemplars
import (
"context"
"sort"
"sync"

"github.com/pkg/errors"
"github.com/prometheus/prometheus/storage"
Expand Down Expand Up @@ -37,10 +38,13 @@ type exemplarsServer struct {

warnings []error
data []*exemplarspb.ExemplarData
mu sync.Mutex
}

func (srv *exemplarsServer) Send(res *exemplarspb.ExemplarsResponse) error {
if res.GetWarning() != "" {
srv.mu.Lock()
defer srv.mu.Unlock()
srv.warnings = append(srv.warnings, errors.New(res.GetWarning()))
return nil
}
Expand All @@ -49,6 +53,8 @@ func (srv *exemplarsServer) Send(res *exemplarspb.ExemplarsResponse) error {
return errors.New("empty exemplars data")
}

srv.mu.Lock()
defer srv.mu.Unlock()
srv.data = append(srv.data, res.GetData())
return nil
}
Expand Down

0 comments on commit 27c6178

Please sign in to comment.