Merge pull request #2323 from prometheus/beorn7/retrieval

Retrieval: Avoid copying Target
This commit is contained in:
Fabian Reinartz 2017-01-08 06:49:47 +01:00 committed by GitHub
commit 3302bb1eb1
4 changed files with 11 additions and 11 deletions

View File

@ -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()

View File

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

View File

@ -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",

View File

@ -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,
})