From 84e21b00f272ea116f45ea6436964469e2c0a4bf Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Wed, 2 Mar 2022 11:51:30 +0100 Subject: [PATCH 1/2] Fix info data race Signed-off-by: Matej Gera --- pkg/info/info.go | 37 +++++++++---------------------------- pkg/store/bucket.go | 7 ++++--- test/e2e/query_test.go | 2 +- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/pkg/info/info.go b/pkg/info/info.go index 4c4beee504..40df172a68 100644 --- a/pkg/info/info.go +++ b/pkg/info/info.go @@ -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 { @@ -146,31 +153,7 @@ 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(), @@ -178,7 +161,5 @@ func (srv *InfoServer) Info(ctx context.Context, req *infopb.InfoRequest) (*info Rules: srv.getRulesInfo(), Targets: srv.getTargetsInfo(), MetricMetadata: srv.getMetricMetadataInfo(), - } - - return resp, nil + }, nil } diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index 0be444d24a..098bed9928 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -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"}}}) @@ -700,11 +702,10 @@ 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 } diff --git a/test/e2e/query_test.go b/test/e2e/query_test.go index 481ae091f7..1248efd606 100644 --- a/test/e2e/query_test.go +++ b/test/e2e/query_test.go @@ -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)) From b6fab45614e0afaa6c3be3acf17e6c1202e6a4f3 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Wed, 2 Mar 2022 14:07:39 +0100 Subject: [PATCH 2/2] Fix lint Signed-off-by: Matej Gera --- pkg/store/bucket.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index 098bed9928..679c245fe6 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -705,7 +705,6 @@ func (s *BucketStore) Info(context.Context, *storepb.InfoRequest) (*storepb.Info LabelSets: s.LabelSet(), } - return res, nil }