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
pull/4300/head
Thomas Jackson 7 years ago committed by Brian Brazil
parent fb695fb435
commit 630f42fcf1

@ -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) level.Error(ng.logger).Log("msg", "error selecting series set", "err", err)
return err return err
} }
n.series, err = expandSeriesSet(set) n.series, err = expandSeriesSet(ctx, set)
if err != nil { if err != nil {
// TODO(fabxc): use multi-error. // TODO(fabxc): use multi-error.
level.Error(ng.logger).Log("msg", "error expanding series set", "err", err) 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) level.Error(ng.logger).Log("msg", "error selecting series set", "err", err)
return err return err
} }
n.series, err = expandSeriesSet(set) n.series, err = expandSeriesSet(ctx, set)
if err != nil { if err != nil {
level.Error(ng.logger).Log("msg", "error expanding series set", "err", err) level.Error(ng.logger).Log("msg", "error expanding series set", "err", err)
return err return err
@ -538,8 +538,13 @@ func extractFuncFromPath(p []Node) string {
return extractFuncFromPath(p[:len(p)-1]) 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() { for it.Next() {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
res = append(res, it.At()) res = append(res, it.At())
} }
return res, it.Err() return res, it.Err()

Loading…
Cancel
Save