Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store: Fix data race in advertised label set in bucket store #5204

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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