mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Merge pull request #2323 from prometheus/beorn7/retrieval
Retrieval: Avoid copying Target
This commit is contained in:
commit
3302bb1eb1
|
@ -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()
|
||||
|
|
|
@ -68,7 +68,7 @@ func (e *apiError) Error() string {
|
|||
}
|
||||
|
||||
type targetRetriever interface {
|
||||
Targets() []retrieval.Target
|
||||
Targets() []*retrieval.Target
|
||||
}
|
||||
|
||||
type response struct {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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…
Reference in a new issue