Merge pull request #1475 from prometheus/fabxc/targetsort

Sort exported targets
pull/1476/head
Brian Brazil 2016-03-08 16:24:55 +00:00
commit 84c421da8e
2 changed files with 7 additions and 3 deletions

View File

@ -15,6 +15,7 @@ package retrieval
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -134,11 +135,11 @@ func (tm *TargetManager) reload() {
} }
// Pools returns the targets currently being scraped bucketed by their job name. // 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() tm.mtx.RLock()
defer tm.mtx.RUnlock() defer tm.mtx.RUnlock()
pools := map[string][]*Target{} pools := map[string]Targets{}
// TODO(fabxc): this is just a hack to maintain compatibility for now. // TODO(fabxc): this is just a hack to maintain compatibility for now.
for _, ps := range tm.targetSets { for _, ps := range tm.targetSets {
@ -151,6 +152,9 @@ func (tm *TargetManager) Pools() map[string][]*Target {
ps.scrapePool.mtx.RUnlock() ps.scrapePool.mtx.RUnlock()
} }
for _, targets := range pools {
sort.Sort(targets)
}
return pools return pools
} }

View File

@ -92,7 +92,7 @@ type PrometheusStatus struct {
// A function that returns the current scrape targets pooled // A function that returns the current scrape targets pooled
// by their job name. // by their job name.
TargetPools func() map[string][]*retrieval.Target TargetPools func() map[string]retrieval.Targets
// A function that returns all loaded rules. // A function that returns all loaded rules.
Rules func() []rules.Rule Rules func() []rules.Rule