Skip to content

Commit 6c4d909

Browse files
committed
Perform ingester pushes in a background context rather than the request context
1 parent 6191d41 commit 6c4d909

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/distributor/distributor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"golang.org/x/time/rate"
1515

1616
"github.com/go-kit/kit/log/level"
17+
opentracing "github.com/opentracing/opentracing-go"
1718
"github.com/prometheus/client_golang/prometheus"
1819
"github.com/prometheus/common/model"
1920
"github.com/prometheus/prometheus/pkg/labels"
@@ -350,7 +351,14 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie
350351
defer cancel() // cancel the timeout to release resources
351352
for ingester, samples := range samplesByIngester {
352353
go func(ingester *ring.IngesterDesc, samples []*sampleTracker) {
353-
d.sendSamples(ctx, ingester, samples, &pushTracker)
354+
// Use a background context to make sure all ingesters get samples even if we return early
355+
localCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
356+
defer cancel()
357+
localCtx = user.InjectOrgID(localCtx, userID)
358+
if sp := opentracing.SpanFromContext(ctx); sp != nil {
359+
localCtx = opentracing.ContextWithSpan(localCtx, sp)
360+
}
361+
d.sendSamples(localCtx, ingester, samples, &pushTracker)
354362
}(ingester, samples)
355363
}
356364
select {

0 commit comments

Comments
 (0)