app/vmselect: properly handle errors in GetLabelsOnTimeRange and GetLabelValuesOnTimeRange

This commit is contained in:
Aliaksandr Valialkin 2020-11-05 01:36:13 +02:00
parent 1cb78ba1a0
commit 368b69b4c4
3 changed files with 16 additions and 10 deletions

View File

@ -512,9 +512,12 @@ func LabelValuesHandler(startTime time.Time, labelName string, w http.ResponseWr
}
var labelValues []string
if len(r.Form["match[]"]) == 0 {
var err error
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error
labelValues, err = netstorage.GetLabelValues(labelName, deadline)
if err != nil {
return fmt.Errorf(`cannot obtain label values for %q: %w`, labelName, err)
}
} else {
ct := startTime.UnixNano() / 1e6
end, err := searchutils.GetTime(r, "end", ct)
@ -530,9 +533,9 @@ func LabelValuesHandler(startTime time.Time, labelName string, w http.ResponseWr
MaxTimestamp: end,
}
labelValues, err = netstorage.GetLabelValuesOnTimeRange(labelName, tr, deadline)
}
if err != nil {
return fmt.Errorf(`cannot obtain label values for %q: %w`, labelName, err)
if err != nil {
return fmt.Errorf(`cannot obtain label values on time range for %q: %w`, labelName, err)
}
}
} else {
// Extended functionality that allows filtering by label filters and time range
@ -710,9 +713,12 @@ func LabelsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
}
var labels []string
if len(r.Form["match[]"]) == 0 {
var err error
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error
labels, err = netstorage.GetLabels(deadline)
if err != nil {
return fmt.Errorf("cannot obtain labels: %w", err)
}
} else {
ct := startTime.UnixNano() / 1e6
end, err := searchutils.GetTime(r, "end", ct)
@ -728,9 +734,9 @@ func LabelsHandler(startTime time.Time, w http.ResponseWriter, r *http.Request)
MaxTimestamp: end,
}
labels, err = netstorage.GetLabelsOnTimeRange(tr, deadline)
}
if err != nil {
return fmt.Errorf("cannot obtain labels: %w", err)
if err != nil {
return fmt.Errorf("cannot obtain labels on time range: %w", err)
}
}
} else {
// Extended functionality that allows filtering by label filters and time range

View File

@ -1577,7 +1577,7 @@ func TestSearchTSIDWithTimeRange(t *testing.T) {
// Check SearchTagValuesOnTimeRange.
tvs, err := db.SearchTagValuesOnTimeRange([]byte(""), TimeRange{
MinTimestamp: int64(now)-msecPerDay,
MinTimestamp: int64(now) - msecPerDay,
MaxTimestamp: int64(now),
}, 10000, noDeadline)
if err != nil {

View File

@ -182,7 +182,7 @@ func skipSamplesOutsideRetention(b *Block, retentionDeadline int64, rowsDeleted
for nextIdx < len(timestamps) && timestamps[nextIdx] < retentionDeadline {
nextIdx++
}
atomic.AddUint64(rowsDeleted, uint64(nextIdx - b.nextIdx))
atomic.AddUint64(rowsDeleted, uint64(nextIdx-b.nextIdx))
b.nextIdx = nextIdx
}