mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Allow the result map for the series set before hand with a hint.
Signed-off-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
parent
6cfc584308
commit
2de2fee035
|
@ -542,6 +542,13 @@ func (r *AlertingRule) ForEachActiveAlert(f func(*Alert)) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *AlertingRule) ActiveAlertsCount() int {
|
||||
r.activeMtx.Lock()
|
||||
defer r.activeMtx.Unlock()
|
||||
|
||||
return len(r.active)
|
||||
}
|
||||
|
||||
func (r *AlertingRule) sendAlerts(ctx context.Context, ts time.Time, resendDelay, interval time.Duration, notifyFunc NotifyFunc) {
|
||||
alerts := []*Alert{}
|
||||
r.ForEachActiveAlert(func(alert *Alert) {
|
||||
|
|
|
@ -1027,3 +1027,22 @@ func TestAlertingRule_SetNoDependencyRules(t *testing.T) {
|
|||
rule.SetNoDependencyRules(true)
|
||||
require.True(t, rule.NoDependencyRules())
|
||||
}
|
||||
|
||||
func TestAlertingRule_ActiveAlertsCount(t *testing.T) {
|
||||
rule := NewAlertingRule(
|
||||
"TestRule",
|
||||
nil,
|
||||
time.Minute,
|
||||
0,
|
||||
labels.FromStrings("severity", "critical"),
|
||||
labels.EmptyLabels(), labels.EmptyLabels(), "", true, nil,
|
||||
)
|
||||
|
||||
// Set an active alert.
|
||||
lbls := labels.FromStrings("a1", "1")
|
||||
h := lbls.Hash()
|
||||
al := &Alert{State: StateFiring, Labels: lbls, ActiveAt: time.Now()}
|
||||
rule.active[h] = al
|
||||
|
||||
require.Equal(t, 1, t rule.ActiveAlertsCount())
|
||||
}
|
||||
|
|
|
@ -681,7 +681,8 @@ func (g *Group) RestoreForState(ts time.Time) {
|
|||
continue
|
||||
}
|
||||
|
||||
seriesByLabels := map[string]storage.Series{}
|
||||
// While not technically the same number of series we expect, it's as good of an approximation as any.
|
||||
seriesByLabels := make(map[string]storage.Series, alertRule.ActiveAlertsCount())
|
||||
for sset.Next() {
|
||||
seriesByLabels[sset.At().Labels().DropMetricName().String()] = sset.At()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue