Skip to content

Commit 335210d

Browse files
pracuccigouthamve
authored andcommitted
Fixed reuse slice in distributor.Push() (#1898)
Signed-off-by: Marco Pracucci <[email protected]>
1 parent b65d8bc commit 335210d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/distributor/distributor.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie
334334
// These samples have been deduped.
335335
dedupedSamples.WithLabelValues(userID, cluster).Add(float64(numSamples))
336336
}
337+
338+
// Ensure the request slice is reused if the series get deduped.
339+
client.ReuseSlice(req.Timeseries)
340+
337341
return nil, err
338342
}
339343
// If there wasn't an error but removeReplica is false that means we didn't find both HA labels.
@@ -400,11 +404,17 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie
400404
receivedSamples.WithLabelValues(userID).Add(float64(validatedSamples))
401405

402406
if len(keys) == 0 {
407+
// Ensure the request slice is reused if there's no series passing the validation.
408+
client.ReuseSlice(req.Timeseries)
409+
403410
return &client.WriteResponse{}, lastPartialErr
404411
}
405412

406413
limiter := d.getOrCreateIngestLimiter(userID)
407414
if !limiter.AllowN(time.Now(), validatedSamples) {
415+
// Ensure the request slice is reused if the request is rate limited.
416+
client.ReuseSlice(req.Timeseries)
417+
408418
// Return a 4xx here to have the client discard the data and not retry. If a client
409419
// is sending too much data consistently we will unlikely ever catch up otherwise.
410420
validation.DiscardedSamples.WithLabelValues(validation.RateLimited, userID).Add(float64(validatedSamples))

0 commit comments

Comments
 (0)