Skip to content

Commit fd52ee4

Browse files
committed
ruler: add restore-new-rule-groups flag
1 parent 0210859 commit fd52ee4

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

cmd/thanos/rule.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,19 @@ type ruleConfig struct {
101101

102102
rwConfig *extflag.PathOrContent
103103

104-
resendDelay time.Duration
105-
evalInterval time.Duration
106-
queryOffset time.Duration
107-
outageTolerance time.Duration
108-
forGracePeriod time.Duration
109-
ruleFiles []string
110-
objStoreConfig *extflag.PathOrContent
111-
dataDir string
112-
lset labels.Labels
113-
ignoredLabelNames []string
114-
storeRateLimits store.SeriesSelectLimits
115-
ruleConcurrentEval int64
104+
resendDelay time.Duration
105+
evalInterval time.Duration
106+
queryOffset time.Duration
107+
outageTolerance time.Duration
108+
forGracePeriod time.Duration
109+
ruleFiles []string
110+
objStoreConfig *extflag.PathOrContent
111+
dataDir string
112+
lset labels.Labels
113+
ignoredLabelNames []string
114+
storeRateLimits store.SeriesSelectLimits
115+
ruleConcurrentEval int64
116+
restoreNewRuleGroups bool
116117

117118
extendedFunctionsEnabled bool
118119
EnableFeatures []string
@@ -166,6 +167,8 @@ func registerRule(app *extkingpin.App) {
166167
cmd.Flag("restore-ignored-label", "Label names to be ignored when restoring alerts from the remote storage. This is only used in stateless mode.").
167168
StringsVar(&conf.ignoredLabelNames)
168169
cmd.Flag("rule-concurrent-evaluation", "How many rules can be evaluated concurrently. Default is 1.").Default("1").Int64Var(&conf.ruleConcurrentEval)
170+
cmd.Flag("restore-new-rule-groups", "Enable restoring the 'for' state of new rule groups added via config reload by querying ALERTS_FOR_STATE series.").
171+
Default("false").BoolVar(&conf.restoreNewRuleGroups)
169172

170173
cmd.Flag("grpc-query-endpoint", "Addresses of Thanos gRPC query API servers (repeatable). The scheme may be prefixed with 'dns+' or 'dnssrv+' to detect Thanos API servers through respective DNS lookups.").
171174
PlaceHolder("<endpoint>").StringsVar(&conf.grpcQueryEndpoints)
@@ -640,6 +643,7 @@ func runRule(
640643
OutageTolerance: conf.outageTolerance,
641644
ForGracePeriod: conf.forGracePeriod,
642645
DefaultRuleQueryOffset: func() time.Duration { return conf.queryOffset },
646+
RestoreNewRuleGroups: conf.restoreNewRuleGroups,
643647
}
644648
if conf.ruleConcurrentEval > 1 {
645649
managerOpts.MaxConcurrentEvals = conf.ruleConcurrentEval

test/e2e/e2ethanos/services.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ type RulerBuilder struct {
815815
evalInterval string
816816
forGracePeriod string
817817
restoreIgnoredLabels []string
818+
restoreNewRuleGroups bool
818819
nativeHistograms bool
819820
}
820821

@@ -866,6 +867,11 @@ func (r *RulerBuilder) WithRestoreIgnoredLabels(labels ...string) *RulerBuilder
866867
return r
867868
}
868869

870+
func (r *RulerBuilder) WithRestoreNewRuleGroups() *RulerBuilder {
871+
r.restoreNewRuleGroups = true
872+
return r
873+
}
874+
869875
func (r *RulerBuilder) WithNativeHistograms() *RulerBuilder {
870876
r.nativeHistograms = true
871877
return r
@@ -938,6 +944,10 @@ func (r *RulerBuilder) initRule(internalRuleDir string, queryCfg []clientconfig.
938944
ruleArgs["--remote-write.config"] = string(rwCfgBytes)
939945
}
940946

947+
if r.restoreNewRuleGroups {
948+
ruleArgs["--restore-new-rule-groups"] = ""
949+
}
950+
941951
if r.nativeHistograms {
942952
ruleArgs["--tsdb.enable-native-histograms"] = ""
943953
}

0 commit comments

Comments
 (0)