Skip to content

Fix reuse slice in distributor.Push() #1898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down