rules: Use narrower interface for rule manager loading of for state (#7472)

To load ALERT_FOR_STATE only `storage.Queryable` interface is required,
so this patch uses this narrower interface for to perform this.

Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
This commit is contained in:
Frederic Branczyk 2020-06-26 20:06:36 +02:00 committed by GitHub
parent d2e631041e
commit d17d88935c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View file

@ -379,7 +379,7 @@ func main() {
ruleManager = rules.NewManager(&rules.ManagerOptions{ ruleManager = rules.NewManager(&rules.ManagerOptions{
Appendable: fanoutStorage, Appendable: fanoutStorage,
TSDB: localStorage, Queryable: localStorage,
QueryFunc: rules.EngineQueryFunc(queryEngine, fanoutStorage), QueryFunc: rules.EngineQueryFunc(queryEngine, fanoutStorage),
NotifyFunc: sendAlerts(notifierManager, cfg.web.ExternalURL.String()), NotifyFunc: sendAlerts(notifierManager, cfg.web.ExternalURL.String()),
Context: ctxRule, Context: ctxRule,

View file

@ -670,7 +670,7 @@ func (g *Group) RestoreForState(ts time.Time) {
// We allow restoration only if alerts were active before after certain time. // We allow restoration only if alerts were active before after certain time.
mint := ts.Add(-g.opts.OutageTolerance) mint := ts.Add(-g.opts.OutageTolerance)
mintMS := int64(model.TimeFromUnixNano(mint.UnixNano())) mintMS := int64(model.TimeFromUnixNano(mint.UnixNano()))
q, err := g.opts.TSDB.Querier(g.opts.Context, mintMS, maxtMS) q, err := g.opts.Queryable.Querier(g.opts.Context, mintMS, maxtMS)
if err != nil { if err != nil {
level.Error(g.logger).Log("msg", "Failed to get Querier", "err", err) level.Error(g.logger).Log("msg", "Failed to get Querier", "err", err)
return return
@ -846,7 +846,7 @@ type ManagerOptions struct {
NotifyFunc NotifyFunc NotifyFunc NotifyFunc
Context context.Context Context context.Context
Appendable storage.Appendable Appendable storage.Appendable
TSDB storage.Storage Queryable storage.Queryable
Logger log.Logger Logger log.Logger
Registerer prometheus.Registerer Registerer prometheus.Registerer
OutageTolerance time.Duration OutageTolerance time.Duration

View file

@ -359,7 +359,7 @@ func TestForStateRestore(t *testing.T) {
opts := &ManagerOptions{ opts := &ManagerOptions{
QueryFunc: EngineQueryFunc(suite.QueryEngine(), suite.Storage()), QueryFunc: EngineQueryFunc(suite.QueryEngine(), suite.Storage()),
Appendable: suite.Storage(), Appendable: suite.Storage(),
TSDB: suite.Storage(), Queryable: suite.Storage(),
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
NotifyFunc: func(ctx context.Context, expr string, alerts ...*Alert) {}, NotifyFunc: func(ctx context.Context, expr string, alerts ...*Alert) {},
@ -524,7 +524,7 @@ func TestStaleness(t *testing.T) {
opts := &ManagerOptions{ opts := &ManagerOptions{
QueryFunc: EngineQueryFunc(engine, st), QueryFunc: EngineQueryFunc(engine, st),
Appendable: st, Appendable: st,
TSDB: st, Queryable: st,
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
} }
@ -711,7 +711,7 @@ func TestUpdate(t *testing.T) {
engine := promql.NewEngine(opts) engine := promql.NewEngine(opts)
ruleManager := NewManager(&ManagerOptions{ ruleManager := NewManager(&ManagerOptions{
Appendable: st, Appendable: st,
TSDB: st, Queryable: st,
QueryFunc: EngineQueryFunc(engine, st), QueryFunc: EngineQueryFunc(engine, st),
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
@ -847,7 +847,7 @@ func TestNotify(t *testing.T) {
opts := &ManagerOptions{ opts := &ManagerOptions{
QueryFunc: EngineQueryFunc(engine, storage), QueryFunc: EngineQueryFunc(engine, storage),
Appendable: storage, Appendable: storage,
TSDB: storage, Queryable: storage,
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
NotifyFunc: notifyFunc, NotifyFunc: notifyFunc,
@ -917,7 +917,7 @@ func TestMetricsUpdate(t *testing.T) {
engine := promql.NewEngine(opts) engine := promql.NewEngine(opts)
ruleManager := NewManager(&ManagerOptions{ ruleManager := NewManager(&ManagerOptions{
Appendable: storage, Appendable: storage,
TSDB: storage, Queryable: storage,
QueryFunc: EngineQueryFunc(engine, storage), QueryFunc: EngineQueryFunc(engine, storage),
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
@ -991,7 +991,7 @@ func TestGroupStalenessOnRemoval(t *testing.T) {
engine := promql.NewEngine(opts) engine := promql.NewEngine(opts)
ruleManager := NewManager(&ManagerOptions{ ruleManager := NewManager(&ManagerOptions{
Appendable: storage, Appendable: storage,
TSDB: storage, Queryable: storage,
QueryFunc: EngineQueryFunc(engine, storage), QueryFunc: EngineQueryFunc(engine, storage),
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),
@ -1068,7 +1068,7 @@ func TestMetricsStalenessOnManagerShutdown(t *testing.T) {
engine := promql.NewEngine(opts) engine := promql.NewEngine(opts)
ruleManager := NewManager(&ManagerOptions{ ruleManager := NewManager(&ManagerOptions{
Appendable: storage, Appendable: storage,
TSDB: storage, Queryable: storage,
QueryFunc: EngineQueryFunc(engine, storage), QueryFunc: EngineQueryFunc(engine, storage),
Context: context.Background(), Context: context.Background(),
Logger: log.NewNopLogger(), Logger: log.NewNopLogger(),