From f2e359962c44edebd739f757d3b1294c10aacdac Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 8 Mar 2016 17:12:27 +0100 Subject: [PATCH] Sort exported targets --- retrieval/targetmanager.go | 8 ++++++-- web/web.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 8eecc67d2..5ce1e98f8 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -15,6 +15,7 @@ package retrieval import ( "fmt" + "sort" "strings" "sync" "time" @@ -134,11 +135,11 @@ func (tm *TargetManager) reload() { } // Pools returns the targets currently being scraped bucketed by their job name. -func (tm *TargetManager) Pools() map[string][]*Target { +func (tm *TargetManager) Pools() map[string]Targets { tm.mtx.RLock() defer tm.mtx.RUnlock() - pools := map[string][]*Target{} + pools := map[string]Targets{} // TODO(fabxc): this is just a hack to maintain compatibility for now. for _, ps := range tm.targetSets { @@ -151,6 +152,9 @@ func (tm *TargetManager) Pools() map[string][]*Target { ps.scrapePool.mtx.RUnlock() } + for _, targets := range pools { + sort.Sort(targets) + } return pools } diff --git a/web/web.go b/web/web.go index bfcbdb639..8ce45cb26 100644 --- a/web/web.go +++ b/web/web.go @@ -92,7 +92,7 @@ type PrometheusStatus struct { // A function that returns the current scrape targets pooled // by their job name. - TargetPools func() map[string][]*retrieval.Target + TargetPools func() map[string]retrieval.Targets // A function that returns all loaded rules. Rules func() []rules.Rule