Skip to content

Commit

Permalink
Updated TSDB with fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Aug 7, 2020
1 parent 76edd0f commit 8f317a1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/rules/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (m *Manager) Stop() {
mgr.Stop()
}
}

func (m *Manager) protoRuleGroups() []*rulespb.RuleGroup {

rg := m.RuleGroups()
res := make([]*rulespb.RuleGroup, 0, len(rg))
for _, g := range rg {
Expand Down
13 changes: 9 additions & 4 deletions pkg/rules/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ func (n nopQueryable) Querier(_ context.Context, _, _ int64) (storage.Querier, e
return storage.NoopQuerier(), nil
}

type nopQueryable struct{}

func (n nopQueryable) Querier(_ context.Context, _, _ int64) (storage.Querier, error) {
return storage.NoopQuerier(), nil
}

// Regression test against https://github.com/thanos-io/thanos/issues/1779.
func TestRun(t *testing.T) {
func TestRun_Subqueries(t *testing.T) {
dir, err := ioutil.TempDir("", "test_rule_run")
testutil.Ok(t, err)
defer func() { testutil.Ok(t, os.RemoveAll(dir)) }()
Expand Down Expand Up @@ -84,17 +90,16 @@ groups:
},
labels.FromStrings("replica", "1"),
)
testutil.Ok(t, thanosRuleMgr.Update(10*time.Second, []string{filepath.Join(dir, "rule.yaml")}))
testutil.Ok(t, thanosRuleMgr.Update(1*time.Second, []string{filepath.Join(dir, "rule.yaml")}))

thanosRuleMgr.Run()
defer thanosRuleMgr.Stop()

select {
case <-time.After(2 * time.Minute):
case <-time.After(1 * time.Minute):
t.Fatal("timeout while waiting on rule manager query evaluation")
case <-queryDone:
}

testutil.Equals(t, "rate(some_metric[1h:5m] offset 1d)", query)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/store/storepb/testutil/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func CreateHeadWithSeries(t testing.TB, j int, opts HeadGenOptions) (*tsdb.Head,
testutil.Ok(t, err)
}

h, err := tsdb.NewHead(nil, nil, w, 10000000, tsdbDir, nil, tsdb.DefaultStripeSize, nil)
h, err := tsdb.NewHead(nil, nil, w, tsdb.DefaultBlockDuration, tsdbDir, nil, tsdb.DefaultStripeSize, nil)
testutil.Ok(t, err)

app := h.Appender(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions pkg/store/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (s *TSDBStore) translateAndExtendLabels(m, extend labels.Labels) []storepb.
func (s *TSDBStore) LabelNames(ctx context.Context, r *storepb.LabelNamesRequest) (
*storepb.LabelNamesResponse, error,
) {
q, err := s.db.Querier(ctx, r.Start, r.End)
q, err := s.db.ChunkQuerier(ctx, r.Start, r.End)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand All @@ -230,7 +230,7 @@ func (s *TSDBStore) LabelNames(ctx context.Context, r *storepb.LabelNamesRequest
func (s *TSDBStore) LabelValues(ctx context.Context, r *storepb.LabelValuesRequest) (
*storepb.LabelValuesResponse, error,
) {
q, err := s.db.Querier(ctx, r.Start, r.End)
q, err := s.db.ChunkQuerier(ctx, r.Start, r.End)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
1 change: 0 additions & 1 deletion pkg/store/tsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ func TestTSDBStore_LabelValues(t *testing.T) {
}

tsdbStore := NewTSDBStore(nil, nil, db, component.Rule, labels.FromStrings("region", "eu-west"))

now := time.Now()
head := db.Head()
for _, tc := range []struct {
Expand Down

0 comments on commit 8f317a1

Please sign in to comment.