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 f2bff64933
commit 72011bcc45
2 changed files with 15 additions and 9 deletions

View File

@ -579,9 +579,12 @@ func LabelValuesHandler(startTime time.Time, at *auth.Token, labelName string, w
var labelValues []string
var isPartial bool
if len(r.Form["match[]"]) == 0 {
var err error
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error
labelValues, isPartial, err = netstorage.GetLabelValues(at, 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)
@ -597,9 +600,9 @@ func LabelValuesHandler(startTime time.Time, at *auth.Token, labelName string, w
MaxTimestamp: end,
}
labelValues, isPartial, err = netstorage.GetLabelValuesOnTimeRange(at, 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
@ -789,9 +792,12 @@ func LabelsHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
var labels []string
var isPartial bool
if len(r.Form["match[]"]) == 0 {
var err error
if len(r.Form["start"]) == 0 && len(r.Form["end"]) == 0 {
var err error
labels, isPartial, err = netstorage.GetLabels(at, deadline)
if err != nil {
return fmt.Errorf("cannot obtain labels: %w", err)
}
} else {
ct := startTime.UnixNano() / 1e6
end, err := searchutils.GetTime(r, "end", ct)
@ -807,9 +813,9 @@ func LabelsHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
MaxTimestamp: end,
}
labels, isPartial, err = netstorage.GetLabelsOnTimeRange(at, 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

@ -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
}