From 1c33b5937ea252e1ea5bd8830dc1ec1d583b8da6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 11 Jun 2019 01:02:56 +0300 Subject: [PATCH] app/vmselect/promql: prevent from `count_values` explosion of timeseries, which could result in OOM --- app/vmselect/promql/aggr.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/vmselect/promql/aggr.go b/app/vmselect/promql/aggr.go index 8f6d5a7a7..bce21a095 100644 --- a/app/vmselect/promql/aggr.go +++ b/app/vmselect/promql/aggr.go @@ -100,10 +100,18 @@ func aggrFuncExt(afe func(tss []*timeseries) []*timeseries, argOrig []*timeserie } bbPool.Put(bb) + srcTssCount := 0 + dstTssCount := 0 rvs := make([]*timeseries, 0, len(m)) for _, tss := range m { rv := afe(tss) rvs = append(rvs, rv...) + srcTssCount += len(tss) + dstTssCount += len(rv) + if dstTssCount > 2000 && dstTssCount > 16*srcTssCount { + // This looks like count_values explosion. + return nil, fmt.Errorf(`too many timeseries after aggragation; got %d; want less than %d`, dstTssCount, 16*srcTssCount) + } } return rvs, nil }