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 labelValues []string
var isPartial bool var isPartial bool
if len(r.Form["match[]"]) == 0 { if len(r.Form["match[]"]) == 0 {
var err error
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
labelValues, isPartial, err = netstorage.GetLabelValues(at, labelName, deadline) labelValues, isPartial, err = netstorage.GetLabelValues(at, labelName, deadline)
if err != nil {
return fmt.Errorf(`cannot obtain label values for %q: %w`, labelName, err)
}
} else { } else {
ct := startTime.UnixNano() / 1e6 ct := startTime.UnixNano() / 1e6
end, err := searchutils.GetTime(r, "end", ct) end, err := searchutils.GetTime(r, "end", ct)
@ -597,9 +600,9 @@ func LabelValuesHandler(startTime time.Time, at *auth.Token, labelName string, w
MaxTimestamp: end, MaxTimestamp: end,
} }
labelValues, isPartial, err = netstorage.GetLabelValuesOnTimeRange(at, labelName, tr, deadline) labelValues, isPartial, err = netstorage.GetLabelValuesOnTimeRange(at, labelName, tr, deadline)
}
if err != nil { if err != nil {
return fmt.Errorf(`cannot obtain label values for %q: %w`, labelName, err) return fmt.Errorf(`cannot obtain label values on time range for %q: %w`, labelName, err)
}
} }
} else { } else {
// Extended functionality that allows filtering by label filters and time range // 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 labels []string
var isPartial bool var isPartial bool
if len(r.Form["match[]"]) == 0 { if len(r.Form["match[]"]) == 0 {
var err error
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
labels, isPartial, err = netstorage.GetLabels(at, deadline) labels, isPartial, err = netstorage.GetLabels(at, deadline)
if err != nil {
return fmt.Errorf("cannot obtain labels: %w", err)
}
} else { } else {
ct := startTime.UnixNano() / 1e6 ct := startTime.UnixNano() / 1e6
end, err := searchutils.GetTime(r, "end", ct) 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, MaxTimestamp: end,
} }
labels, isPartial, err = netstorage.GetLabelsOnTimeRange(at, tr, deadline) labels, isPartial, err = netstorage.GetLabelsOnTimeRange(at, tr, deadline)
}
if err != nil { if err != nil {
return fmt.Errorf("cannot obtain labels: %w", err) return fmt.Errorf("cannot obtain labels on time range: %w", err)
}
} }
} else { } else {
// Extended functionality that allows filtering by label filters and time range // Extended functionality that allows filtering by label filters and time range