Skip to content

Commit

Permalink
Merge pull request prometheus#1625 from prometheus/series-api-time-bo…
Browse files Browse the repository at this point in the history
…unds

Support time range in /api/v1/series endpoint.
  • Loading branch information
fabxc committed May 12, 2016
2 parents 68aaea6 + 0c1e7a5 commit 54de6af
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
25 changes: 24 additions & 1 deletion web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,29 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
if len(r.Form["match[]"]) == 0 {
return nil, &apiError{errorBadData, fmt.Errorf("no match[] parameter provided")}
}

var start model.Time
if t := r.FormValue("start"); t != "" {
var err error
start, err = parseTime(t)
if err != nil {
return nil, &apiError{errorBadData, err}
}
} else {
start = model.Earliest
}

var end model.Time
if t := r.FormValue("end"); t != "" {
var err error
end, err = parseTime(t)
if err != nil {
return nil, &apiError{errorBadData, err}
}
} else {
end = model.Latest
}

res := map[model.Fingerprint]metric.Metric{}

for _, lm := range r.Form["match[]"] {
Expand All @@ -240,7 +263,7 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
return nil, &apiError{errorBadData, err}
}
for fp, met := range api.Storage.MetricsForLabelMatchers(
model.Earliest, model.Latest, // Get every series.
start, end,
matchers...,
) {
res[fp] = met
Expand Down
80 changes: 80 additions & 0 deletions web/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,86 @@ func TestEndpoints(t *testing.T) {
},
},
},
// Start and end before series starts.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"-2"},
"end": []string{"-1"},
},
response: []model.Metric{},
},
// Start and end after series ends.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"100000"},
"end": []string{"100001"},
},
response: []model.Metric{},
},
// Start before series starts, end after series ends.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"-1"},
"end": []string{"100000"},
},
response: []model.Metric{
{
"__name__": "test_metric2",
"foo": "boo",
},
},
},
// Start and end within series.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"1"},
"end": []string{"100"},
},
response: []model.Metric{
{
"__name__": "test_metric2",
"foo": "boo",
},
},
},
// Start within series, end after.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"1"},
"end": []string{"100000"},
},
response: []model.Metric{
{
"__name__": "test_metric2",
"foo": "boo",
},
},
},
// Start before series, end within series.
{
endpoint: api.series,
query: url.Values{
"match[]": []string{`test_metric2`},
"start": []string{"-1"},
"end": []string{"1"},
},
response: []model.Metric{
{
"__name__": "test_metric2",
"foo": "boo",
},
},
},
// Missing match[] query params in series requests.
{
endpoint: api.series,
Expand Down

0 comments on commit 54de6af

Please sign in to comment.