lib/streamaggr: explicitly call resetSeries after flushSeries

This makes the code less fragile
This commit is contained in:
Aliaksandr Valialkin 2024-03-04 06:01:14 +02:00
parent 48a425898a
commit c2dae136b3
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -674,6 +674,7 @@ func (a *aggregator) flush(pushFunc PushFunc) {
ctx := getFlushCtx(a, pushFunc) ctx := getFlushCtx(a, pushFunc)
as.flushState(ctx) as.flushState(ctx)
ctx.flushSeries() ctx.flushSeries()
ctx.resetSeries()
putFlushCtx(ctx) putFlushCtx(ctx)
}(as) }(as)
} }
@ -925,8 +926,6 @@ func (ctx *flushCtx) flushSeries() {
} }
auxLabels.Labels = dstLabels auxLabels.Labels = dstLabels
promutils.PutLabels(auxLabels) promutils.PutLabels(auxLabels)
ctx.resetSeries()
} }
func (ctx *flushCtx) appendSeries(key, suffix string, timestamp int64, value float64) { func (ctx *flushCtx) appendSeries(key, suffix string, timestamp int64, value float64) {
@ -948,6 +947,7 @@ func (ctx *flushCtx) appendSeries(key, suffix string, timestamp int64, value flo
// Limit the maximum length of ctx.tss in order to limit memory usage. // Limit the maximum length of ctx.tss in order to limit memory usage.
if len(ctx.tss) >= 10_000 { if len(ctx.tss) >= 10_000 {
ctx.flushSeries() ctx.flushSeries()
ctx.resetSeries()
} }
} }