Skip to content

Fix returning 5XX for limits errors in series API #5169

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 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* [BUGFIX] Ingester: Fix panic when querying metadata from blocks that are being deleted. #5119
* [BUGFIX] Ring: Fix case when dynamodb kv reaches the limit of 25 actions per batch call. #5136
* [BUGFIX] Query-frontend: Fix sorted queries do not produce sorted results for shardable queries. #5148
* [BUGFIX] Querier: Fix `/api/v1/series` returning 5XX instead of 4XX when limits are hit. #5169
* [FEATURE] Alertmanager: Add support for time_intervals. #5102

## 1.14.0 2022-12-02
Expand Down
8 changes: 4 additions & 4 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,11 @@ func (d *Distributor) MetricsForLabelMatchers(ctx context.Context, from, through
return nil, err
}
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
return nil, err
return nil, validation.LimitError(err.Error())
}
for _, m := range resp.Metric {
if err := queryLimiter.AddSeries(m.Labels); err != nil {
return nil, err
return nil, validation.LimitError(err.Error())
}
m := cortexpb.FromLabelAdaptersToMetric(m.Labels)
fingerprint := m.Fingerprint()
Expand All @@ -1065,7 +1065,7 @@ func (d *Distributor) MetricsForLabelMatchersStream(ctx context.Context, from, t
for {
resp, err := stream.Recv()
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
return nil, err
return nil, validation.LimitError(err.Error())
}

if err == io.EOF {
Expand All @@ -1078,7 +1078,7 @@ func (d *Distributor) MetricsForLabelMatchersStream(ctx context.Context, from, t
m := cortexpb.FromLabelAdaptersToMetricWithCopy(metric.Labels)

if err := queryLimiter.AddSeries(metric.Labels); err != nil {
return nil, err
return nil, validation.LimitError(err.Error())
}

fingerprint := m.Fingerprint()
Expand Down
4 changes: 2 additions & 2 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ func TestDistributor_MetricsForLabelMatchers(t *testing.T) {
metrics, err := ds[0].MetricsForLabelMatchers(ctx, now, now, testData.matchers...)

if testData.expectedErr != nil {
assert.EqualError(t, err, testData.expectedErr.Error())
assert.ErrorIs(t, err, testData.expectedErr)
return
}

Expand All @@ -2190,7 +2190,7 @@ func TestDistributor_MetricsForLabelMatchers(t *testing.T) {
{
metrics, err := ds[0].MetricsForLabelMatchersStream(ctx, now, now, testData.matchers...)
if testData.expectedErr != nil {
assert.EqualError(t, err, testData.expectedErr.Error())
assert.ErrorIs(t, err, testData.expectedErr)
return
}

Expand Down