app/vmselect/prometheus: treat match query arg in the same way as match[] query arg

This commit is contained in:
Aliaksandr Valialkin 2021-02-11 15:00:12 +02:00
parent 1e38ad6d20
commit acdb401585

View File

@ -260,9 +260,9 @@ func ExportHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
return fmt.Errorf("cannot parse request form values: %w", err) return fmt.Errorf("cannot parse request form values: %w", err)
} }
matches, err := getMatchesFromRequest(r) matches := getMatchesFromRequest(r)
if err != nil { if len(matches) == 0 {
return err return fmt.Errorf("missing `match[]` query arg")
} }
start, err := searchutils.GetTime(r, "start", 0) start, err := searchutils.GetTime(r, "start", 0)
if err != nil { if err != nil {
@ -476,8 +476,9 @@ func LabelValuesHandler(startTime time.Time, labelName string, w http.ResponseWr
if err != nil { if err != nil {
return err return err
} }
matches := getMatchesFromRequest(r)
var labelValues []string var labelValues []string
if len(r.Form["match[]"]) == 0 && len(etf) == 0 { if len(matches) == 0 && len(etf) == 0 {
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 { if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error var err error
labelValues, err = netstorage.GetLabelValues(labelName, deadline) labelValues, err = netstorage.GetLabelValues(labelName, deadline)
@ -508,7 +509,6 @@ func LabelValuesHandler(startTime time.Time, labelName string, w http.ResponseWr
// i.e. /api/v1/label/foo/values?match[]=foobar{baz="abc"}&start=...&end=... // i.e. /api/v1/label/foo/values?match[]=foobar{baz="abc"}&start=...&end=...
// is equivalent to `label_values(foobar{baz="abc"}, foo)` call on the selected // is equivalent to `label_values(foobar{baz="abc"}, foo)` call on the selected
// time range in Grafana templating. // time range in Grafana templating.
matches := r.Form["match[]"]
if len(matches) == 0 { if len(matches) == 0 {
matches = []string{fmt.Sprintf("{%s!=''}", labelName)} matches = []string{fmt.Sprintf("{%s!=''}", labelName)}
} }
@ -691,8 +691,9 @@ func LabelsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
if err != nil { if err != nil {
return err return err
} }
matches := getMatchesFromRequest(r)
var labels []string var labels []string
if len(r.Form["match[]"]) == 0 && len(etf) == 0 { if len(matches) == 0 && len(etf) == 0 {
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 { if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error var err error
labels, err = netstorage.GetLabels(deadline) labels, err = netstorage.GetLabels(deadline)
@ -721,7 +722,6 @@ func LabelsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
} else { } else {
// Extended functionality that allows filtering by label filters and time range // Extended functionality that allows filtering by label filters and time range
// i.e. /api/v1/labels?match[]=foobar{baz="abc"}&start=...&end=... // i.e. /api/v1/labels?match[]=foobar{baz="abc"}&start=...&end=...
matches := r.Form["match[]"]
if len(matches) == 0 { if len(matches) == 0 {
matches = []string{"{__name__!=''}"} matches = []string{"{__name__!=''}"}
} }
@ -1274,9 +1274,9 @@ func getTagFilterssFromMatches(matches []string) ([][]storage.TagFilter, error)
} }
func getTagFilterssFromRequest(r *http.Request) ([][]storage.TagFilter, error) { func getTagFilterssFromRequest(r *http.Request) ([][]storage.TagFilter, error) {
matches, err := getMatchesFromRequest(r) matches := getMatchesFromRequest(r)
if err != nil { if len(matches) == 0 {
return nil, err return nil, fmt.Errorf("missing `match[]` query arg")
} }
tagFilterss, err := getTagFilterssFromMatches(matches) tagFilterss, err := getTagFilterssFromMatches(matches)
if err != nil { if err != nil {
@ -1290,16 +1290,11 @@ func getTagFilterssFromRequest(r *http.Request) ([][]storage.TagFilter, error) {
return tagFilterss, nil return tagFilterss, nil
} }
func getMatchesFromRequest(r *http.Request) ([]string, error) { func getMatchesFromRequest(r *http.Request) []string {
matches := r.Form["match[]"] matches := r.Form["match[]"]
if len(matches) > 0 { // This is needed for backwards compatibility
return matches, nil matches = append(matches, r.Form["match"]...)
} return matches
match := r.Form.Get("match")
if len(match) == 0 {
return nil, fmt.Errorf("missing `match[]` query arg")
}
return []string{match}, nil
} }
func getLatencyOffsetMilliseconds() int64 { func getLatencyOffsetMilliseconds() int64 {