Skip to content
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

Handle context.Canceled in active series requests #7102

Merged
merged 3 commits into from
Jan 11, 2024
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
21 changes: 17 additions & 4 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,20 @@ func (d *Distributor) ActiveSeries(ctx context.Context, matchers []*labels.Match
res := newActiveSeriesResponse(d.hashCollisionCount, maxResponseSize)

ingesterQuery := func(ctx context.Context, client ingester_client.IngesterClient) (any, error) {
// This function is invoked purely for its side effects on the captured
// activeSeriesResponse, its return value is never used.
type ignored struct{}

log, ctx := spanlogger.NewWithLogger(ctx, d.log, "Distributor.ActiveSeries.queryIngester")
defer log.Finish()

stream, err := client.ActiveSeries(ctx, req)
if err != nil {
if errors.Is(err, context.Canceled) {
return ignored{}, nil
}
level.Error(log).Log("msg", "error creating active series response stream", "err", err)
ext.Error.Set(log.Span, true)
return nil, err
}

Expand All @@ -1849,9 +1858,13 @@ func (d *Distributor) ActiveSeries(ctx context.Context, matchers []*labels.Match

for {
msg, err := stream.Recv()
if errors.Is(err, io.EOF) {
break
} else if err != nil {
if err != nil {
if errors.Is(err, io.EOF) {
break
}
if errors.Is(err, context.Canceled) {
return ignored{}, nil
}
level.Error(log).Log("msg", "error receiving active series response", "err", err)
ext.Error.Set(log.Span, true)
return nil, err
Expand All @@ -1863,7 +1876,7 @@ func (d *Distributor) ActiveSeries(ctx context.Context, matchers []*labels.Match
}
}

return nil, nil
return ignored{}, nil
}

_, err = forReplicationSet(ctx, d, replicationSet, ingesterQuery)
Expand Down
Loading