return GetAll alerts sorted by time
This commit is contained in:
parent
4aa5dcccf3
commit
3314ffe833
|
@ -2,6 +2,7 @@ package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -104,11 +105,15 @@ func (s *memAlerts) GetAll() ([]*Alert, error) {
|
||||||
s.mtx.RLock()
|
s.mtx.RLock()
|
||||||
defer s.mtx.RUnlock()
|
defer s.mtx.RUnlock()
|
||||||
|
|
||||||
alerts := make([]*Alert, len(s.alerts))
|
alerts := make([]*Alert, 0, len(s.alerts))
|
||||||
for i, a := range s.alerts {
|
for _, a := range s.alerts {
|
||||||
alerts[i] = a
|
alerts = append(alerts, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(fabxc): specify whether time sorting is an interface
|
||||||
|
// requirement.
|
||||||
|
sort.Sort(alertTimeline(alerts))
|
||||||
|
|
||||||
return alerts, nil
|
return alerts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue