mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +00:00
app/vmselect/prometheus: treat match
query arg in the same way as match[]
query arg
This commit is contained in:
parent
9e88ff3075
commit
ee4288987b
1 changed files with 14 additions and 19 deletions
|
@ -266,9 +266,9 @@ func ExportHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
|
||||||
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 {
|
||||||
|
@ -524,10 +524,11 @@ func LabelValuesHandler(startTime time.Time, at *auth.Token, labelName string, w
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
matches := getMatchesFromRequest(r)
|
||||||
var labelValues []string
|
var labelValues []string
|
||||||
var isPartial bool
|
var isPartial bool
|
||||||
denyPartialResponse := searchutils.GetDenyPartialResponse(r)
|
denyPartialResponse := searchutils.GetDenyPartialResponse(r)
|
||||||
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, isPartial, err = netstorage.GetLabelValues(at, denyPartialResponse, labelName, deadline)
|
labelValues, isPartial, err = netstorage.GetLabelValues(at, denyPartialResponse, labelName, deadline)
|
||||||
|
@ -558,7 +559,6 @@ func LabelValuesHandler(startTime time.Time, at *auth.Token, labelName string, w
|
||||||
// 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)}
|
||||||
}
|
}
|
||||||
|
@ -749,10 +749,11 @@ func LabelsHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
matches := getMatchesFromRequest(r)
|
||||||
var labels []string
|
var labels []string
|
||||||
var isPartial bool
|
var isPartial bool
|
||||||
denyPartialResponse := searchutils.GetDenyPartialResponse(r)
|
denyPartialResponse := searchutils.GetDenyPartialResponse(r)
|
||||||
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, isPartial, err = netstorage.GetLabels(at, denyPartialResponse, deadline)
|
labels, isPartial, err = netstorage.GetLabels(at, denyPartialResponse, deadline)
|
||||||
|
@ -781,7 +782,6 @@ func LabelsHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
|
||||||
} 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__!=''}"}
|
||||||
}
|
}
|
||||||
|
@ -1346,9 +1346,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 {
|
||||||
|
@ -1362,16 +1362,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 {
|
||||||
|
|
Loading…
Reference in a new issue