mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-07 10:31:03 +01:00
Merge pull request #16642 from rajagopalanand/restore-for-state-refactor
refactor: Move 'for' state restoration metric to defer block
This commit is contained in:
commit
5f28c6be62
@ -270,12 +270,7 @@ func (g *Group) run(ctx context.Context) {
|
||||
g.evalIterationFunc(ctx, g, evalTimestamp)
|
||||
}
|
||||
|
||||
restoreStartTime := time.Now()
|
||||
g.RestoreForState(restoreStartTime)
|
||||
totalRestoreTimeSeconds := time.Since(restoreStartTime).Seconds()
|
||||
g.metrics.GroupLastRestoreDuration.WithLabelValues(GroupKey(g.file, g.name)).Set(totalRestoreTimeSeconds)
|
||||
g.logger.Debug("'for' state restoration completed", "duration_seconds", totalRestoreTimeSeconds)
|
||||
g.shouldRestore = false
|
||||
g.RestoreForState(time.Now())
|
||||
}
|
||||
|
||||
for {
|
||||
@ -742,6 +737,12 @@ func (g *Group) cleanupStaleSeries(ctx context.Context, ts time.Time) {
|
||||
// RestoreForState restores the 'for' state of the alerts
|
||||
// by looking up last ActiveAt from storage.
|
||||
func (g *Group) RestoreForState(ts time.Time) {
|
||||
defer func() {
|
||||
totalRestoreTimeSeconds := time.Since(ts).Seconds()
|
||||
g.metrics.GroupLastRestoreDuration.WithLabelValues(GroupKey(g.file, g.name)).Set(totalRestoreTimeSeconds)
|
||||
g.logger.Debug("'for' state restoration completed", "duration_seconds", totalRestoreTimeSeconds)
|
||||
g.shouldRestore = false
|
||||
}()
|
||||
maxtMS := int64(model.TimeFromUnixNano(ts.UnixNano()))
|
||||
// We allow restoration only if alerts were active before after certain time.
|
||||
mint := ts.Add(-g.opts.OutageTolerance)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user