From a3a53647bad97f83eea10691669429f691b1abb9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 20 Jun 2019 14:05:07 +0300 Subject: [PATCH] app/vmselect/prometheus: return better error messages on missing args to `/api/v1/*` --- app/vmselect/prometheus/prometheus.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 83dfd8a02..cdb292977 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -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) } matches := r.Form["match[]"] + if len(matches) == 0 { + return fmt.Errorf("missing `match[]` arg") + } maxLookback, err := getDuration(r, "max_lookback", defaultStep) if err != nil { return err @@ -112,6 +115,9 @@ func ExportHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) error if len(matches) == 0 { // Maintain backwards compatibility match := r.FormValue("match") + if len(match) == 0 { + return fmt.Errorf("missing `match[]` arg") + } matches = []string{match} } 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") } matches := r.Form["match[]"] + if len(matches) == 0 { + return fmt.Errorf("missing `match[]` arg") + } deadline := getDeadline(r) tagFilterss, err := getTagFilterssFromMatches(matches) 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) } matches := r.Form["match[]"] + if len(matches) == 0 { + return fmt.Errorf("missing `match[]` arg") + } start, err := getTime(r, "start", ct-defaultStep) if err != nil { return err @@ -415,6 +427,9 @@ func QueryHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) error ct := currentTime() query := r.FormValue("query") + if len(query) == 0 { + return fmt.Errorf("missing `query` arg") + } start, err := getTime(r, "time", ct) if err != nil { return err @@ -486,6 +501,9 @@ func QueryRangeHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) e ct := currentTime() query := r.FormValue("query") + if len(query) == 0 { + return fmt.Errorf("missing `query` arg") + } start, err := getTime(r, "start", ct-defaultStep) if err != nil { return err