Browse Source

Merge pull request #2323 from prometheus/beorn7/retrieval

Retrieval: Avoid copying Target
pull/2327/head
Fabian Reinartz 8 years ago committed by GitHub
parent
commit
3302bb1eb1
  1. 6
      retrieval/targetmanager.go
  2. 2
      web/api/v1/api.go
  3. 10
      web/api/v1/api_test.go
  4. 4
      web/web.go

6
retrieval/targetmanager.go

@ -132,16 +132,16 @@ func (tm *TargetManager) reload() {
}
// 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()
defer tm.mtx.RUnlock()
targets := []Target{}
targets := []*Target{}
for _, ps := range tm.targetSets {
ps.sp.mtx.RLock()
for _, t := range ps.sp.targets {
targets = append(targets, *t)
targets = append(targets, t)
}
ps.sp.mtx.RUnlock()

2
web/api/v1/api.go

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

10
web/api/v1/api_test.go

@ -33,9 +33,9 @@ import (
"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()
}
@ -57,9 +57,9 @@ func TestEndpoints(t *testing.T) {
now := model.Now()
tr := targetRetrieverFunc(func() []retrieval.Target {
return []retrieval.Target{
*retrieval.NewTarget(
tr := targetRetrieverFunc(func() []*retrieval.Target {
return []*retrieval.Target{
retrieval.NewTarget(
model.LabelSet{
model.SchemeLabel: "http",
model.AddressLabel: "example.com:8080",

4
web/web.go

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

Loading…
Cancel
Save