app/vmselect/prometheus: return better error messages on missing args to /api/v1/*

This commit is contained in:
Aliaksandr Valialkin 2019-06-20 14:05:07 +03:00
parent a0c22a6830
commit a3a53647ba

View file

@ -41,6 +41,9 @@ func FederateHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) err
return fmt.Errorf("cannot parse request form values: %s", err) return fmt.Errorf("cannot parse request form values: %s", err)
} }
matches := r.Form["match[]"] matches := r.Form["match[]"]
if len(matches) == 0 {
return fmt.Errorf("missing `match[]` arg")
}
maxLookback, err := getDuration(r, "max_lookback", defaultStep) maxLookback, err := getDuration(r, "max_lookback", defaultStep)
if err != nil { if err != nil {
return err return err
@ -112,6 +115,9 @@ func ExportHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) error
if len(matches) == 0 { if len(matches) == 0 {
// Maintain backwards compatibility // Maintain backwards compatibility
match := r.FormValue("match") match := r.FormValue("match")
if len(match) == 0 {
return fmt.Errorf("missing `match[]` arg")
}
matches = []string{match} matches = []string{match}
} }
start, err := getTime(r, "start", 0) start, err := getTime(r, "start", 0)
@ -207,6 +213,9 @@ func DeleteHandler(at *auth.Token, r *http.Request) error {
return fmt.Errorf("start and end aren't supported. Remove these args from the query in order to delete all the matching metrics") return fmt.Errorf("start and end aren't supported. Remove these args from the query in order to delete all the matching metrics")
} }
matches := r.Form["match[]"] matches := r.Form["match[]"]
if len(matches) == 0 {
return fmt.Errorf("missing `match[]` arg")
}
deadline := getDeadline(r) deadline := getDeadline(r)
tagFilterss, err := getTagFilterssFromMatches(matches) tagFilterss, err := getTagFilterssFromMatches(matches)
if err != nil { if err != nil {
@ -348,6 +357,9 @@ func SeriesHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) error
return fmt.Errorf("cannot parse form values: %s", err) return fmt.Errorf("cannot parse form values: %s", err)
} }
matches := r.Form["match[]"] matches := r.Form["match[]"]
if len(matches) == 0 {
return fmt.Errorf("missing `match[]` arg")
}
start, err := getTime(r, "start", ct-defaultStep) start, err := getTime(r, "start", ct-defaultStep)
if err != nil { if err != nil {
return err return err
@ -415,6 +427,9 @@ func QueryHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) error
ct := currentTime() ct := currentTime()
query := r.FormValue("query") query := r.FormValue("query")
if len(query) == 0 {
return fmt.Errorf("missing `query` arg")
}
start, err := getTime(r, "time", ct) start, err := getTime(r, "time", ct)
if err != nil { if err != nil {
return err return err
@ -486,6 +501,9 @@ func QueryRangeHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) e
ct := currentTime() ct := currentTime()
query := r.FormValue("query") query := r.FormValue("query")
if len(query) == 0 {
return fmt.Errorf("missing `query` arg")
}
start, err := getTime(r, "start", ct-defaultStep) start, err := getTime(r, "start", ct-defaultStep)
if err != nil { if err != nil {
return err return err