From 947c83be3b864ed2517dd8a0979ba1c343f45785 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 30 Mar 2017 22:45:18 +0200 Subject: [PATCH] Sort targets by instance within a job Fixes https://github.com/prometheus/prometheus/issues/2536 --- retrieval/targetmanager.go | 2 +- web/web.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 28e387a96..1798355a5 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -131,7 +131,7 @@ func (tm *TargetManager) reload() { } } -// Targets returns the targets currently being scraped bucketed by their job name. +// Targets returns the targets currently being scraped. func (tm *TargetManager) Targets() []*Target { tm.mtx.RLock() defer tm.mtx.RUnlock() diff --git a/web/web.go b/web/web.go index fd5369ecf..ac947d5eb 100644 --- a/web/web.go +++ b/web/web.go @@ -379,6 +379,12 @@ func (h *Handler) targets(w http.ResponseWriter, r *http.Request) { tps[job] = append(tps[job], t) } + for _, targets := range tps { + sort.Slice(targets, func(i, j int) bool { + return targets[i].Labels()[model.InstanceLabel] < targets[j].Labels()[model.InstanceLabel] + }) + } + h.executeTemplate(w, "targets.html", struct { TargetPools map[string][]*retrieval.Target }{