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 3, 2020
1 parent b37482f commit 73f8907
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ require (
// See https://github.com/thanos-io/thanos/issues/1415
replace (
// Make sure Cortex is not forcing us to some other Prometheus version.
// TODO: This points to https://github.com/prometheus/prometheus/pull/7069. Remove and point to master once merged.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20200802085738-31929b83d50e
// TODO: This points to https://github.com/prometheus/prometheus/pull/7069. Remove and point to master once it's merged.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20200803103256-28c5cfaf0d41
k8s.io/klog => k8s.io/klog v0.3.1
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx
github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/prometheus v1.8.2-0.20200802085738-31929b83d50e h1:g6GmYlaCAw5nM9RCQDpKnp3A4Wd9wYnMyp48o/V+JLg=
github.com/prometheus/prometheus v1.8.2-0.20200802085738-31929b83d50e/go.mod h1:i1KZsZmyDTJRvnR7zE8z/u2v+tkpPjoiPpnWp6nwhr0=
github.com/prometheus/prometheus v1.8.2-0.20200803103256-28c5cfaf0d41 h1:B8N7vJYp54bfHYlmzmPLhZ6UGX+JS/+gxO212qCauYQ=
github.com/prometheus/prometheus v1.8.2-0.20200803103256-28c5cfaf0d41/go.mod h1:i1KZsZmyDTJRvnR7zE8z/u2v+tkpPjoiPpnWp6nwhr0=
github.com/rafaeljusto/redigomock v0.0.0-20190202135759-257e089e14a1/go.mod h1:JaY6n2sDr+z2WTsXkOmNRUfDy6FN0L6Nk7x06ndm4tY=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
Expand Down
5 changes: 3 additions & 2 deletions pkg/rules/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ func NewManager(
return m
}

// Run is non blocking, in opposite to TSDB manager, which is blocking.
func (m *Manager) Run() {
for _, mgr := range m.mgrs {
mgr.Run()
go mgr.Run()
}
}

Expand All @@ -155,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
20 changes: 14 additions & 6 deletions pkg/rules/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ func (n nopAppender) Commit() error {
func (n nopAppender) Rollback() error { return nil }
func (n nopAppender) Appender() (storage.Appender, error) { return n, 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 All @@ -65,6 +71,7 @@ groups:
Logger: log.NewLogfmtLogger(os.Stderr),
Context: context.Background(),
Appendable: nopAppendable{},
Queryable: nopQueryable{},
},
func(partialResponseStrategy storepb.PartialResponseStrategy) rules.QueryFunc {
return func(ctx context.Context, q string, t time.Time) (vectors promql.Vector, e error) {
Expand All @@ -77,17 +84,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 Expand Up @@ -160,7 +166,8 @@ groups:
nil,
dir,
rules.ManagerOptions{
Logger: log.NewLogfmtLogger(os.Stderr),
Logger: log.NewLogfmtLogger(os.Stderr),
Queryable: nopQueryable{},
},
func(partialResponseStrategy storepb.PartialResponseStrategy) rules.QueryFunc {
return func(ctx context.Context, q string, t time.Time) (promql.Vector, error) {
Expand Down Expand Up @@ -287,7 +294,8 @@ func TestManager_Rules(t *testing.T) {
nil,
dir,
rules.ManagerOptions{
Logger: log.NewLogfmtLogger(os.Stderr),
Logger: log.NewLogfmtLogger(os.Stderr),
Queryable: nopQueryable{},
},
func(partialResponseStrategy storepb.PartialResponseStrategy) rules.QueryFunc {
return func(ctx context.Context, q string, t time.Time) (promql.Vector, error) {
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()
Expand Down
7 changes: 2 additions & 5 deletions pkg/store/tsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ func TestTSDBStore_LabelNames(t *testing.T) {
}

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

for _, tc := range []struct {
title string
labels []string
expectedNames []string
}{
{
title: "no label in tsdb",
labels: []string{},
expectedNames: []string{},
title: "no label in tsdb",
labels: []string{},
},
{
title: "add one label",
Expand Down Expand Up @@ -251,7 +249,6 @@ func TestTSDBStore_LabelValues(t *testing.T) {
}

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

for _, tc := range []struct {
title string
addedLabels []string
Expand Down

0 comments on commit 73f8907

Please sign in to comment.