mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/prometheus: improve performance for /api/v1/labels
and /api/v1/label/<labelName>/values
on time ranges exceeding one day when match[]
query arg is set
This commit is contained in:
parent
e969346e3e
commit
852aed62f7
2 changed files with 66 additions and 37 deletions
|
@ -662,12 +662,28 @@ func labelValuesWithMatches(at *auth.Token, denyPartialResponse bool, labelName
|
||||||
MaxTimestamp: end,
|
MaxTimestamp: end,
|
||||||
TagFilterss: tagFilterss,
|
TagFilterss: tagFilterss,
|
||||||
}
|
}
|
||||||
rss, isPartial, err := netstorage.ProcessSearchQuery(at, denyPartialResponse, sq, false, deadline)
|
m := make(map[string]struct{})
|
||||||
|
isPartial := false
|
||||||
|
if end-start > 24*3600*1000 {
|
||||||
|
// It is cheaper to call SearchMetricNames on time ranges exceeding a day.
|
||||||
|
mns, isPartialResponse, err := netstorage.SearchMetricNames(at, denyPartialResponse, sq, deadline)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, fmt.Errorf("cannot fetch time series for %q: %w", sq, err)
|
||||||
|
}
|
||||||
|
isPartial = isPartialResponse
|
||||||
|
for _, mn := range mns {
|
||||||
|
labelValue := mn.GetTagValue(labelName)
|
||||||
|
if len(labelValue) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m[string(labelValue)] = struct{}{}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rss, isPartialResponse, err := netstorage.ProcessSearchQuery(at, denyPartialResponse, sq, false, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("cannot fetch data for %q: %w", sq, err)
|
return nil, false, fmt.Errorf("cannot fetch data for %q: %w", sq, err)
|
||||||
}
|
}
|
||||||
|
isPartial = isPartialResponse
|
||||||
m := make(map[string]struct{})
|
|
||||||
var mLock sync.Mutex
|
var mLock sync.Mutex
|
||||||
err = rss.RunParallel(func(rs *netstorage.Result, workerID uint) error {
|
err = rss.RunParallel(func(rs *netstorage.Result, workerID uint) error {
|
||||||
labelValue := rs.MetricName.GetTagValue(labelName)
|
labelValue := rs.MetricName.GetTagValue(labelName)
|
||||||
|
@ -682,7 +698,7 @@ func labelValuesWithMatches(at *auth.Token, denyPartialResponse bool, labelName
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("error when data fetching: %w", err)
|
return nil, false, fmt.Errorf("error when data fetching: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
labelValues := make([]string, 0, len(m))
|
labelValues := make([]string, 0, len(m))
|
||||||
for labelValue := range m {
|
for labelValue := range m {
|
||||||
labelValues = append(labelValues, labelValue)
|
labelValues = append(labelValues, labelValue)
|
||||||
|
@ -856,19 +872,31 @@ func labelsWithMatches(at *auth.Token, denyPartialResponse bool, matches []strin
|
||||||
MaxTimestamp: end,
|
MaxTimestamp: end,
|
||||||
TagFilterss: tagFilterss,
|
TagFilterss: tagFilterss,
|
||||||
}
|
}
|
||||||
rss, isPartial, err := netstorage.ProcessSearchQuery(at, denyPartialResponse, sq, false, deadline)
|
m := make(map[string]struct{})
|
||||||
|
isPartial := false
|
||||||
|
if end-start > 24*3600*1000 {
|
||||||
|
// It is cheaper to call SearchMetricNames on time ranges exceeding a day.
|
||||||
|
mns, isPartialResponse, err := netstorage.SearchMetricNames(at, denyPartialResponse, sq, deadline)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, fmt.Errorf("cannot fetch time series for %q: %w", sq, err)
|
||||||
|
}
|
||||||
|
isPartial = isPartialResponse
|
||||||
|
for _, mn := range mns {
|
||||||
|
for _, tag := range mn.Tags {
|
||||||
|
m[string(tag.Key)] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rss, isPartialResponse, err := netstorage.ProcessSearchQuery(at, denyPartialResponse, sq, false, deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("cannot fetch data for %q: %w", sq, err)
|
return nil, false, fmt.Errorf("cannot fetch data for %q: %w", sq, err)
|
||||||
}
|
}
|
||||||
|
isPartial = isPartialResponse
|
||||||
m := make(map[string]struct{})
|
|
||||||
var mLock sync.Mutex
|
var mLock sync.Mutex
|
||||||
err = rss.RunParallel(func(rs *netstorage.Result, workerID uint) error {
|
err = rss.RunParallel(func(rs *netstorage.Result, workerID uint) error {
|
||||||
mLock.Lock()
|
mLock.Lock()
|
||||||
tags := rs.MetricName.Tags
|
for _, tag := range rs.MetricName.Tags {
|
||||||
for i := range tags {
|
m[string(tag.Key)] = struct{}{}
|
||||||
t := &tags[i]
|
|
||||||
m[string(t.Key)] = struct{}{}
|
|
||||||
}
|
}
|
||||||
m["__name__"] = struct{}{}
|
m["__name__"] = struct{}{}
|
||||||
mLock.Unlock()
|
mLock.Unlock()
|
||||||
|
@ -877,6 +905,7 @@ func labelsWithMatches(at *auth.Token, denyPartialResponse bool, matches []strin
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("error when data fetching: %w", err)
|
return nil, false, fmt.Errorf("error when data fetching: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
labels := make([]string, 0, len(m))
|
labels := make([]string, 0, len(m))
|
||||||
for label := range m {
|
for label := range m {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* FEATURE: vmselect: add `"isPartial":{true|false}` field in JSON output for `/api/v1/*` functions
|
* FEATURE: vmselect: add `"isPartial":{true|false}` field in JSON output for `/api/v1/*` functions
|
||||||
from [Prometheus querying API](https://prometheus.io/docs/prometheus/latest/querying/api/). `"isPartial":true` is set if the response contains partial data
|
from [Prometheus querying API](https://prometheus.io/docs/prometheus/latest/querying/api/). `"isPartial":true` is set if the response contains partial data
|
||||||
because of a part of `vmstorage` nodes were unavailable during query processing.
|
because of a part of `vmstorage` nodes were unavailable during query processing.
|
||||||
* FEATURE: improve performance for `/api/v1/series` on time ranges exceeding one day.
|
* FEATURE: improve performance for `/api/v1/series`, `/api/v1/labels` and `/api/v1/label/<labelName>/values` on time ranges exceeding one day.
|
||||||
* FEATURE: vmagent: reduce memory usage when service discovery detects big number of scrape targets and the set of discovered targets changes over time.
|
* FEATURE: vmagent: reduce memory usage when service discovery detects big number of scrape targets and the set of discovered targets changes over time.
|
||||||
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825
|
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825
|
||||||
* FEATURE: vmagent: add `-promscrape.dropOriginalLabels` command-line option, which can be used for reducing memory usage when scraping big number of targets.
|
* FEATURE: vmagent: add `-promscrape.dropOriginalLabels` command-line option, which can be used for reducing memory usage when scraping big number of targets.
|
||||||
|
|
Loading…
Reference in a new issue