mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
app/vmselect/graphite: follow-up after 529d7be26b
This commit is contained in:
parent
8807410a00
commit
799461d8bf
2 changed files with 29 additions and 22 deletions
|
@ -230,24 +230,33 @@ func MetricsIndexHandler(startTime time.Time, at *auth.Token, w http.ResponseWri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// metricsFind searches for label values that match the given head and tail.
|
// metricsFind searches for label values that match the given qHead and qTail.
|
||||||
func metricsFind(at *auth.Token, denyPartialResponse bool, tr storage.TimeRange, label, head, tail string, delimiter byte,
|
func metricsFind(at *auth.Token, denyPartialResponse bool, tr storage.TimeRange, label, qHead, qTail string, delimiter byte,
|
||||||
isExpand bool, deadline searchutils.Deadline) ([]string, bool, error) {
|
isExpand bool, deadline searchutils.Deadline) ([]string, bool, error) {
|
||||||
n := strings.IndexAny(tail, "*{[")
|
n := strings.IndexAny(qTail, "*{[")
|
||||||
// fast path.
|
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
res, isPartial, err := netstorage.GetTagValueSuffixes(at, denyPartialResponse, tr, label, head+tail, delimiter, deadline)
|
query := qHead + qTail
|
||||||
|
suffixes, isPartial, err := netstorage.GetTagValueSuffixes(at, denyPartialResponse, tr, label, query, delimiter, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if len(res) == 0 {
|
if len(suffixes) == 0 {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
return []string{head + tail}, isPartial, nil
|
if len(query) > 0 && query[len(query)-1] == delimiter {
|
||||||
|
return []string{query}, isPartial, nil
|
||||||
|
}
|
||||||
|
results := make([]string, 0, len(suffixes))
|
||||||
|
for _, suffix := range suffixes {
|
||||||
|
if len(suffix) == 0 || len(suffix) == 1 && suffix[0] == delimiter {
|
||||||
|
results = append(results, query+suffix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results, isPartial, nil
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(head, "*") {
|
if n == len(qTail)-1 && strings.HasSuffix(qTail, "*") {
|
||||||
head = head[:len(head)-1]
|
query := qHead + qTail[:len(qTail)-1]
|
||||||
suffixes, isPartial, err := netstorage.GetTagValueSuffixes(at, denyPartialResponse, tr, label, head, delimiter, deadline)
|
suffixes, isPartial, err := netstorage.GetTagValueSuffixes(at, denyPartialResponse, tr, label, query, delimiter, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
@ -256,25 +265,22 @@ func metricsFind(at *auth.Token, denyPartialResponse bool, tr storage.TimeRange,
|
||||||
}
|
}
|
||||||
results := make([]string, 0, len(suffixes))
|
results := make([]string, 0, len(suffixes))
|
||||||
for _, suffix := range suffixes {
|
for _, suffix := range suffixes {
|
||||||
results = append(results, head+suffix)
|
results = append(results, query+suffix)
|
||||||
}
|
}
|
||||||
return results, isPartial, nil
|
return results, isPartial, nil
|
||||||
}
|
}
|
||||||
|
qHead += qTail[:n]
|
||||||
head += tail[:n]
|
paths, isPartial, err := metricsFind(at, denyPartialResponse, tr, label, qHead, "*", delimiter, isExpand, deadline)
|
||||||
subquery := head + "*"
|
|
||||||
// execute subquery with the given head.
|
|
||||||
paths, isPartial, err := metricsFind(at, denyPartialResponse, tr, label, subquery, "*", delimiter, isExpand, deadline)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
tailNew := ""
|
suffix := qTail[n:]
|
||||||
suffix := tail[n:]
|
qTail = ""
|
||||||
if m := strings.IndexByte(suffix, delimiter); m >= 0 {
|
if m := strings.IndexByte(suffix, delimiter); m >= 0 {
|
||||||
tailNew = suffix[m+1:]
|
qTail = suffix[m+1:]
|
||||||
suffix = suffix[:m+1]
|
suffix = suffix[:m+1]
|
||||||
}
|
}
|
||||||
qPrefix := head + suffix
|
qPrefix := qHead + suffix
|
||||||
rePrefix, err := getRegexpForQuery(qPrefix, delimiter)
|
rePrefix, err := getRegexpForQuery(qPrefix, delimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("cannot convert query %q to regexp: %w", qPrefix, err)
|
return nil, false, fmt.Errorf("cannot convert query %q to regexp: %w", qPrefix, err)
|
||||||
|
@ -284,11 +290,11 @@ func metricsFind(at *auth.Token, denyPartialResponse bool, tr storage.TimeRange,
|
||||||
if !rePrefix.MatchString(path) {
|
if !rePrefix.MatchString(path) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if tailNew == "" {
|
if qTail == "" {
|
||||||
results = append(results, path)
|
results = append(results, path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fullPaths, isPartialLocal, err := metricsFind(at, denyPartialResponse, tr, label, path, tailNew, delimiter, isExpand, deadline)
|
fullPaths, isPartialLocal, err := metricsFind(at, denyPartialResponse, tr, label, path, qTail, delimiter, isExpand, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
* `process_virtual_memory_peak_bytes` - peak virtual memory usage for the process.
|
* `process_virtual_memory_peak_bytes` - peak virtual memory usage for the process.
|
||||||
|
|
||||||
* BUGFIX: prevent from infinite loop on `{__graphite__="..."}` filters when a metric name contains `*`, `{` or `[` chars.
|
* BUGFIX: prevent from infinite loop on `{__graphite__="..."}` filters when a metric name contains `*`, `{` or `[` chars.
|
||||||
|
* BUGFIX: prevent from infinite loop in `/metrics/find` and `/metrics/expand` [Graphite Metrics API handlers](https://victoriametrics.github.io/#graphite-metrics-api-usage) when they match metric names or labels with `*`, `{` or `[` chars.
|
||||||
|
|
||||||
|
|
||||||
# [v1.56.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.56.0)
|
# [v1.56.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.56.0)
|
||||||
|
|
Loading…
Reference in a new issue