vmalert: check if remoteRead object was initied before calling Restore (#473)

The check for non-nil remoteRead was mistakenly dropped
during refactoring which caused panics when `vmalert`
wasn't configured with `remoteRead` flag.
This commit is contained in:
Roman Khavronenko 2020-05-13 19:32:58 +01:00 committed by Aliaksandr Valialkin
parent 1523890742
commit e208e76222
2 changed files with 5 additions and 1 deletions

View File

@ -57,7 +57,7 @@ func (m *manager) close() {
} }
func (m *manager) startGroup(ctx context.Context, group Group, restore bool) { func (m *manager) startGroup(ctx context.Context, group Group, restore bool) {
if restore { if restore && m.rr != nil {
err := group.Restore(ctx, m.rr, *remoteReadLookBack) err := group.Restore(ctx, m.rr, *remoteReadLookBack)
if err != nil { if err != nil {
logger.Errorf("error while restoring state for group %q: %s", group.Name, err) logger.Errorf("error while restoring state for group %q: %s", group.Name, err)

View File

@ -295,6 +295,10 @@ func newTimeSeries(value float64, labels map[string]string, timestamp time.Time)
// Restore restores only Start field. Field State will be always Pending and supposed // Restore restores only Start field. Field State will be always Pending and supposed
// to be updated on next Eval, as well as Value field. // to be updated on next Eval, as well as Value field.
func (r *Rule) Restore(ctx context.Context, q datasource.Querier, lookback time.Duration) error { func (r *Rule) Restore(ctx context.Context, q datasource.Querier, lookback time.Duration) error {
if q == nil {
return fmt.Errorf("querier is nil")
}
// Get the last datapoint in range via MetricsQL `last_over_time`. // Get the last datapoint in range via MetricsQL `last_over_time`.
// We don't use plain PromQL since Prometheus doesn't support // We don't use plain PromQL since Prometheus doesn't support
// remote write protocol which is used for state persistence in vmalert. // remote write protocol which is used for state persistence in vmalert.