Merge pull request #2323 from prometheus/beorn7/retrieval

Retrieval: Avoid copying Target
pull/2327/head
Fabian Reinartz 8 years ago committed by GitHub
commit 3302bb1eb1

@ -132,16 +132,16 @@ func (tm *TargetManager) reload() {
} }
// Targets returns the targets currently being scraped bucketed by their job name. // Targets returns the targets currently being scraped bucketed by their job name.
func (tm *TargetManager) Targets() []Target { func (tm *TargetManager) Targets() []*Target {
tm.mtx.RLock() tm.mtx.RLock()
defer tm.mtx.RUnlock() defer tm.mtx.RUnlock()
targets := []Target{} targets := []*Target{}
for _, ps := range tm.targetSets { for _, ps := range tm.targetSets {
ps.sp.mtx.RLock() ps.sp.mtx.RLock()
for _, t := range ps.sp.targets { for _, t := range ps.sp.targets {
targets = append(targets, *t) targets = append(targets, t)
} }
ps.sp.mtx.RUnlock() ps.sp.mtx.RUnlock()

@ -68,7 +68,7 @@ func (e *apiError) Error() string {
} }
type targetRetriever interface { type targetRetriever interface {
Targets() []retrieval.Target Targets() []*retrieval.Target
} }
type response struct { type response struct {

@ -33,9 +33,9 @@ import (
"github.com/prometheus/prometheus/retrieval" "github.com/prometheus/prometheus/retrieval"
) )
type targetRetrieverFunc func() []retrieval.Target type targetRetrieverFunc func() []*retrieval.Target
func (f targetRetrieverFunc) Targets() []retrieval.Target { func (f targetRetrieverFunc) Targets() []*retrieval.Target {
return f() return f()
} }
@ -57,9 +57,9 @@ func TestEndpoints(t *testing.T) {
now := model.Now() now := model.Now()
tr := targetRetrieverFunc(func() []retrieval.Target { tr := targetRetrieverFunc(func() []*retrieval.Target {
return []retrieval.Target{ return []*retrieval.Target{
*retrieval.NewTarget( retrieval.NewTarget(
model.LabelSet{ model.LabelSet{
model.SchemeLabel: "http", model.SchemeLabel: "http",
model.AddressLabel: "example.com:8080", model.AddressLabel: "example.com:8080",

@ -373,14 +373,14 @@ func (h *Handler) rules(w http.ResponseWriter, r *http.Request) {
func (h *Handler) targets(w http.ResponseWriter, r *http.Request) { func (h *Handler) targets(w http.ResponseWriter, r *http.Request) {
// Bucket targets by job label // Bucket targets by job label
tps := map[string][]retrieval.Target{} tps := map[string][]*retrieval.Target{}
for _, t := range h.targetManager.Targets() { for _, t := range h.targetManager.Targets() {
job := string(t.Labels()[model.JobLabel]) job := string(t.Labels()[model.JobLabel])
tps[job] = append(tps[job], t) tps[job] = append(tps[job], t)
} }
h.executeTemplate(w, "targets.html", struct { h.executeTemplate(w, "targets.html", struct {
TargetPools map[string][]retrieval.Target TargetPools map[string][]*retrieval.Target
}{ }{
TargetPools: tps, TargetPools: tps,
}) })

Loading…
Cancel
Save