mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-08 19:11:02 +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)
|
g.evalIterationFunc(ctx, g, evalTimestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreStartTime := time.Now()
|
g.RestoreForState(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -742,6 +737,12 @@ func (g *Group) cleanupStaleSeries(ctx context.Context, ts time.Time) {
|
|||||||
// RestoreForState restores the 'for' state of the alerts
|
// RestoreForState restores the 'for' state of the alerts
|
||||||
// by looking up last ActiveAt from storage.
|
// by looking up last ActiveAt from storage.
|
||||||
func (g *Group) RestoreForState(ts time.Time) {
|
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()))
|
maxtMS := int64(model.TimeFromUnixNano(ts.UnixNano()))
|
||||||
// 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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user