Propagate timeout to alert listing via context
The context is created by the http.TimeoutHandler we use to set the timeout. I believe this is the only endpoint where propagating the timeout is feasible and needed. Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
parent
fc4b67ce80
commit
4747fd9b2f
|
@ -253,6 +253,7 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
|
|||
// are no alerts present
|
||||
res = []*Alert{}
|
||||
matchers = []*labels.Matcher{}
|
||||
ctx = r.Context()
|
||||
|
||||
showActive, showInhibited bool
|
||||
showSilenced, showUnprocessed bool
|
||||
|
@ -326,11 +327,13 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) {
|
|||
defer alerts.Close()
|
||||
|
||||
api.mtx.RLock()
|
||||
// TODO(fabxc): enforce a sensible timeout.
|
||||
for a := range alerts.Next() {
|
||||
if err = alerts.Err(); err != nil {
|
||||
break
|
||||
}
|
||||
if err = ctx.Err(); err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
routes := api.route.Match(a.Labels)
|
||||
receivers := make([]string, 0, len(routes))
|
||||
|
|
|
@ -195,6 +195,7 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re
|
|||
// are no alerts present
|
||||
res = open_api_models.GettableAlerts{}
|
||||
matchers = []*labels.Matcher{}
|
||||
ctx = params.HTTPRequest.Context()
|
||||
)
|
||||
|
||||
if params.Filter != nil {
|
||||
|
@ -224,11 +225,13 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re
|
|||
defer alerts.Close()
|
||||
|
||||
api.mtx.RLock()
|
||||
// TODO(fabxc): enforce a sensible timeout.
|
||||
for a := range alerts.Next() {
|
||||
if err = alerts.Err(); err != nil {
|
||||
break
|
||||
}
|
||||
if err = ctx.Err(); err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
routes := api.route.Match(a.Labels)
|
||||
receivers := make([]*open_api_models.Receiver, 0, len(routes))
|
||||
|
|
Loading…
Reference in New Issue