diff --git a/go.mod b/go.mod index 7cbc26413d..77e336e4f4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 82b7cc7f14..f1859f3523 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/rules/manager.go b/pkg/rules/manager.go index 969f055b4b..b6c1f420a5 100644 --- a/pkg/rules/manager.go +++ b/pkg/rules/manager.go @@ -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() } } @@ -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 { diff --git a/pkg/rules/manager_test.go b/pkg/rules/manager_test.go index 71265c0f51..da6b0220c4 100644 --- a/pkg/rules/manager_test.go +++ b/pkg/rules/manager_test.go @@ -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)) }() @@ -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) { @@ -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) } @@ -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) { @@ -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) { diff --git a/pkg/store/storepb/testutil/series.go b/pkg/store/storepb/testutil/series.go index 3f28ec2c3c..3347b518ba 100644 --- a/pkg/store/storepb/testutil/series.go +++ b/pkg/store/storepb/testutil/series.go @@ -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() diff --git a/pkg/store/tsdb_test.go b/pkg/store/tsdb_test.go index 75f82cdd54..d6fb2009ff 100644 --- a/pkg/store/tsdb_test.go +++ b/pkg/store/tsdb_test.go @@ -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", @@ -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