Skip to content

Commit

Permalink
Store: Fix data race in advertised label set in bucket store (#5204)
Browse files Browse the repository at this point in the history
* Fix info data race

Signed-off-by: Matej Gera <matejgera@gmail.com>

* Fix lint

Signed-off-by: Matej Gera <matejgera@gmail.com>
  • Loading branch information
matej-g committed Mar 2, 2022
1 parent afe25fa commit 34e6527
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
37 changes: 9 additions & 28 deletions pkg/info/info.go
Expand Up @@ -35,6 +35,13 @@ func NewInfoServer(
) *InfoServer {
srv := &InfoServer{
component: component,
// By default, do not return info for any API.
getLabelSet: func() []labelpb.ZLabelSet { return nil },
getStoreInfo: func() *infopb.StoreInfo { return nil },
getExemplarsInfo: func() *infopb.ExemplarsInfo { return nil },
getRulesInfo: func() *infopb.RulesInfo { return nil },
getTargetsInfo: func() *infopb.TargetsInfo { return nil },
getMetricMetadataInfo: func() *infopb.MetricMetadataInfo { return nil },
}

for _, o := range options {
Expand Down Expand Up @@ -146,39 +153,13 @@ func RegisterInfoServer(infoSrv infopb.InfoServer) func(*grpc.Server) {

// Info returns the information about label set and available APIs exposed by the component.
func (srv *InfoServer) Info(ctx context.Context, req *infopb.InfoRequest) (*infopb.InfoResponse, error) {
if srv.getLabelSet == nil {
srv.getLabelSet = func() []labelpb.ZLabelSet { return nil }
}

if srv.getStoreInfo == nil {
srv.getStoreInfo = func() *infopb.StoreInfo { return nil }
}

if srv.getExemplarsInfo == nil {
srv.getExemplarsInfo = func() *infopb.ExemplarsInfo { return nil }
}

if srv.getRulesInfo == nil {
srv.getRulesInfo = func() *infopb.RulesInfo { return nil }
}

if srv.getTargetsInfo == nil {
srv.getTargetsInfo = func() *infopb.TargetsInfo { return nil }
}

if srv.getMetricMetadataInfo == nil {
srv.getMetricMetadataInfo = func() *infopb.MetricMetadataInfo { return nil }
}

resp := &infopb.InfoResponse{
return &infopb.InfoResponse{
LabelSets: srv.getLabelSet(),
ComponentType: srv.component,
Store: srv.getStoreInfo(),
Exemplars: srv.getExemplarsInfo(),
Rules: srv.getRulesInfo(),
Targets: srv.getTargetsInfo(),
MetricMetadata: srv.getMetricMetadataInfo(),
}

return resp, nil
}, nil
}
6 changes: 3 additions & 3 deletions pkg/store/bucket.go
Expand Up @@ -684,7 +684,9 @@ func (s *BucketStore) TimeRange() (mint, maxt int64) {
}

func (s *BucketStore) LabelSet() []labelpb.ZLabelSet {
s.mtx.RLock()
labelSets := s.advLabelSets
s.mtx.RUnlock()

if s.enableCompatibilityLabel && len(labelSets) > 0 {
labelSets = append(labelSets, labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: CompatibilityTypeLabelName, Value: "store"}}})
Expand All @@ -700,11 +702,9 @@ func (s *BucketStore) Info(context.Context, *storepb.InfoRequest) (*storepb.Info
StoreType: component.Store.ToProto(),
MinTime: mint,
MaxTime: maxt,
LabelSets: s.LabelSet(),
}

s.mtx.RLock()
res.LabelSets = s.LabelSet()
s.mtx.RUnlock()
return res, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/query_test.go
Expand Up @@ -120,7 +120,7 @@ func sortResults(res model.Vector) {
func TestSidecarNotReady(t *testing.T) {
t.Parallel()

e, err := e2e.NewDockerEnvironment("e2e_test_query")
e, err := e2e.NewDockerEnvironment("e2e_test_query_sidecar_not_ready")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

Expand Down

0 comments on commit 34e6527

Please sign in to comment.