web/api: fix min/max timestamps to valid range

This commit is contained in:
Fabian Reinartz 2017-01-16 14:09:59 +01:00
parent c691895a0f
commit 157e698958
3 changed files with 17 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import (
"testing"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
"github.com/prometheus/prometheus/pkg/labels"
@ -209,8 +210,13 @@ func TestTemplateExpansion(t *testing.T) {
t.Fatalf("get appender: %s", err)
}
app.Add(labels.FromStrings(labels.MetricName, "metric", "instance", "a"), 0, 11)
app.Add(labels.FromStrings(labels.MetricName, "metric", "instance", "b"), 0, 21)
aref, err := app.SetSeries(labels.FromStrings(labels.MetricName, "metric", "instance", "a"))
require.NoError(t, err)
bref, err := app.SetSeries(labels.FromStrings(labels.MetricName, "metric", "instance", "b"))
require.NoError(t, err)
app.Add(aref, 0, 11)
app.Add(bref, 0, 21)
if err := app.Commit(); err != nil {
t.Fatalf("commit samples: %s", err)

View File

@ -258,6 +258,11 @@ func (api *API) labelValues(r *http.Request) (interface{}, *apiError) {
return vals, nil
}
var (
minTime = time.Unix(math.MinInt64/1000+62135596801, 0)
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999)
)
func (api *API) series(r *http.Request) (interface{}, *apiError) {
r.ParseForm()
if len(r.Form["match[]"]) == 0 {
@ -272,7 +277,7 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
return nil, &apiError{errorBadData, err}
}
} else {
start = time.Unix(math.MinInt64, 0)
start = minTime
}
var end time.Time
@ -283,8 +288,9 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
return nil, &apiError{errorBadData, err}
}
} else {
end = time.Unix(math.MaxInt64, 0)
end = maxTime
}
fmt.Println("q range", timestamp.FromTime(start), timestamp.FromTime(end), r.FormValue("start"), r.FormValue("end"))
var matcherSets [][]*labels.Matcher
for _, s := range r.Form["match[]"] {

View File

@ -429,6 +429,7 @@ func TestEndpoints(t *testing.T) {
api.context = func(r *http.Request) context.Context {
return ctx
}
t.Logf("run query %q", test.query.Encode())
req, err := http.NewRequest("ANY", fmt.Sprintf("http://example.com?%s", test.query.Encode()), nil)
if err != nil {