mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 22:37:27 -08:00
Merge pull request #1625 from prometheus/series-api-time-bounds
Support time range in /api/v1/series endpoint.
This commit is contained in:
commit
54de6afd22
|
@ -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[]"] {
|
||||
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue