Skip to content

Commit

Permalink
web/api: make target and alertmanager api responses consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz committed Jan 16, 2017
1 parent 389c6d0 commit bd92571
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,20 @@ type Target struct {
// Any labels that are added to this target and its metrics.
Labels model.LabelSet `json:"labels"`

ScrapeUrl string `json:"scrapeUrl"`
ScrapeURL string `json:"scrapeUrl"`

LastError string `json:"lastError"`
LastScrape time.Time `json:"lastScrape"`
Health retrieval.TargetHealth `json:"health"`
}

type TargetDiscovery struct {
ActiveTargets []*Target `json:"activeTargets"`
}

func (api *API) targets(r *http.Request) (interface{}, *apiError) {
targets := api.targetRetriever.Targets()
res := make([]*Target, len(targets))
res := &TargetDiscovery{ActiveTargets: make([]*Target, len(targets))}

for i, t := range targets {
lastErrStr := ""
Expand All @@ -369,10 +373,10 @@ func (api *API) targets(r *http.Request) (interface{}, *apiError) {
lastErrStr = lastErr.Error()
}

res[i] = &Target{
res.ActiveTargets[i] = &Target{
DiscoveredLabels: t.DiscoveredLabels(),
Labels: t.Labels(),
ScrapeUrl: t.URL().String(),
ScrapeURL: t.URL().String(),
LastError: lastErrStr,
LastScrape: t.LastScrape(),
Health: t.Health(),
Expand Down
14 changes: 8 additions & 6 deletions web/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,14 @@ func TestEndpoints(t *testing.T) {
}{2},
}, {
endpoint: api.targets,
response: []*Target{
&Target{
DiscoveredLabels: model.LabelSet{},
Labels: model.LabelSet{},
ScrapeUrl: "http://example.com:8080/metrics",
Health: "unknown",
response: &TargetDiscovery{
ActiveTargets: []*Target{
&Target{
DiscoveredLabels: model.LabelSet{},
Labels: model.LabelSet{},
ScrapeURL: "http://example.com:8080/metrics",
Health: "unknown",
},
},
},
}, {
Expand Down

0 comments on commit bd92571

Please sign in to comment.