From 11db11682b89b580fef60c69ba4058be3dcf1bbf Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Mon, 9 Dec 2019 12:12:11 +0100 Subject: [PATCH] Fixed reuse slice in distributor.Push() Signed-off-by: Marco Pracucci --- pkg/distributor/distributor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index c89d012de1..30b3ff3a8f 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -353,6 +353,10 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie // These samples have been deduped. dedupedSamples.WithLabelValues(userID, cluster).Add(float64(numSamples)) } + + // Ensure the request slice is reused if the series get deduped. + client.ReuseSlice(req.Timeseries) + return nil, err } // If there wasn't an error but removeReplica is false that means we didn't find both HA labels. @@ -401,11 +405,17 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie receivedSamples.WithLabelValues(userID).Add(float64(validatedSamples)) if len(keys) == 0 { + // Ensure the request slice is reused if there's no series passing the validation. + client.ReuseSlice(req.Timeseries) + return &client.WriteResponse{}, lastPartialErr } limiter := d.getOrCreateIngestLimiter(userID) if !limiter.AllowN(time.Now(), validatedSamples) { + // Ensure the request slice is reused if the request is rate limited. + client.ReuseSlice(req.Timeseries) + // Return a 4xx here to have the client discard the data and not retry. If a client // is sending too much data consistently we will unlikely ever catch up otherwise. validation.DiscardedSamples.WithLabelValues(validation.RateLimited, userID).Add(float64(validatedSamples))