Timeout if populating iterators takes too long (#4291)

Right now promql won't time out a request if populating the iterators
takes a long time.

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

Fixes #4289
This commit is contained in:
Thomas Jackson 2018-06-21 00:14:51 -07:00 committed by Brian Brazil
parent fb695fb435
commit 630f42fcf1

View File

@ -493,7 +493,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
level.Error(ng.logger).Log("msg", "error selecting series set", "err", err)
return err
}
n.series, err = expandSeriesSet(set)
n.series, err = expandSeriesSet(ctx, set)
if err != nil {
// TODO(fabxc): use multi-error.
level.Error(ng.logger).Log("msg", "error expanding series set", "err", err)
@ -508,7 +508,7 @@ func (ng *Engine) populateSeries(ctx context.Context, q storage.Queryable, s *Ev
level.Error(ng.logger).Log("msg", "error selecting series set", "err", err)
return err
}
n.series, err = expandSeriesSet(set)
n.series, err = expandSeriesSet(ctx, set)
if err != nil {
level.Error(ng.logger).Log("msg", "error expanding series set", "err", err)
return err
@ -538,8 +538,13 @@ func extractFuncFromPath(p []Node) string {
return extractFuncFromPath(p[:len(p)-1])
}
func expandSeriesSet(it storage.SeriesSet) (res []storage.Series, err error) {
func expandSeriesSet(ctx context.Context, it storage.SeriesSet) (res []storage.Series, err error) {
for it.Next() {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
res = append(res, it.At())
}
return res, it.Err()