From 3314ffe83384582359d88e0a0a9b3a167942f82b Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Sat, 4 Jul 2015 13:02:49 +0200 Subject: [PATCH] return GetAll alerts sorted by time --- manager/state.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/manager/state.go b/manager/state.go index b0c1a67c..a01201fb 100644 --- a/manager/state.go +++ b/manager/state.go @@ -2,6 +2,7 @@ package manager import ( "fmt" + "sort" "sync" "github.com/prometheus/common/model" @@ -104,11 +105,15 @@ func (s *memAlerts) GetAll() ([]*Alert, error) { s.mtx.RLock() defer s.mtx.RUnlock() - alerts := make([]*Alert, len(s.alerts)) - for i, a := range s.alerts { - alerts[i] = a + alerts := make([]*Alert, 0, len(s.alerts)) + for _, a := range s.alerts { + alerts = append(alerts, a) } + // TODO(fabxc): specify whether time sorting is an interface + // requirement. + sort.Sort(alertTimeline(alerts)) + return alerts, nil }