Skip to content

Commit f8a5843

Browse files
committed
Return HTTP 503 on hitting distributor instance limits
Signed-off-by: Anna Tran <[email protected]>
1 parent 39161ca commit f8a5843

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

pkg/distributor/distributor.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ var (
5151
// Validation errors.
5252
errInvalidShardingStrategy = errors.New("invalid sharding strategy")
5353
errInvalidTenantShardSize = errors.New("invalid tenant shard size. The value must be greater than or equal to 0")
54-
55-
// Distributor instance limits errors.
56-
errTooManyInflightPushRequests = errors.New("too many inflight push requests in distributor")
57-
errMaxSamplesPushRateLimitReached = errors.New("distributor's samples push rate limit reached")
5854
)
5955

6056
const (
@@ -667,12 +663,12 @@ func (d *Distributor) Push(ctx context.Context, req *cortexpb.WriteRequest) (*co
667663
d.incomingMetadata.WithLabelValues(userID).Add(float64(len(req.Metadata)))
668664

669665
if d.cfg.InstanceLimits.MaxInflightPushRequests > 0 && inflight > int64(d.cfg.InstanceLimits.MaxInflightPushRequests) {
670-
return nil, errTooManyInflightPushRequests
666+
return nil, httpgrpc.Errorf(http.StatusServiceUnavailable, "too many inflight push requests in distributor")
671667
}
672668

673669
if d.cfg.InstanceLimits.MaxIngestionRate > 0 {
674670
if rate := d.ingestionRate.Rate(); rate >= d.cfg.InstanceLimits.MaxIngestionRate {
675-
return nil, errMaxSamplesPushRateLimitReached
671+
return nil, httpgrpc.Errorf(http.StatusServiceUnavailable, "distributor's samples push rate limit reached")
676672
}
677673
}
678674

pkg/distributor/distributor_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
840840
preInflight: 101,
841841
inflightLimit: 101,
842842
pushes: []testPush{
843-
{samples: 100, expectedError: errTooManyInflightPushRequests},
843+
{samples: 100, expectedError: httpgrpc.Errorf(http.StatusServiceUnavailable, "too many inflight push requests in distributor")},
844844
},
845845
},
846846
"below inflight client limit": {
@@ -893,7 +893,7 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
893893
ingestionRateLimit: 1000,
894894

895895
pushes: []testPush{
896-
{samples: 100, expectedError: errMaxSamplesPushRateLimitReached},
896+
{samples: 100, expectedError: httpgrpc.Errorf(http.StatusServiceUnavailable, "distributor's samples push rate limit reached")},
897897
{samples: 100, expectedError: nil},
898898
},
899899
},
@@ -903,10 +903,10 @@ func TestDistributor_PushInstanceLimits(t *testing.T) {
903903
ingestionRateLimit: 1000,
904904

905905
pushes: []testPush{
906-
{samples: 5000, expectedError: nil}, // after push, rate = 500 + 0.2*(5000-500) = 1400
907-
{samples: 5000, expectedError: errMaxSamplesPushRateLimitReached}, // after push, rate = 1400 + 0.2*(0 - 1400) = 1120
908-
{samples: 5000, expectedError: errMaxSamplesPushRateLimitReached}, // after push, rate = 1120 + 0.2*(0 - 1120) = 896
909-
{samples: 5000, expectedError: nil}, // 896 is below 1000, so this push succeeds, new rate = 896 + 0.2*(5000-896) = 1716.8
906+
{samples: 5000, expectedError: nil}, // after push, rate = 500 + 0.2*(5000-500) = 1400
907+
{samples: 5000, expectedError: httpgrpc.Errorf(http.StatusServiceUnavailable, "distributor's samples push rate limit reached")}, // after push, rate = 1400 + 0.2*(0 - 1400) = 1120
908+
{samples: 5000, expectedError: httpgrpc.Errorf(http.StatusServiceUnavailable, "distributor's samples push rate limit reached")}, // after push, rate = 1120 + 0.2*(0 - 1120) = 896
909+
{samples: 5000, expectedError: nil}, // 896 is below 1000, so this push succeeds, new rate = 896 + 0.2*(5000-896) = 1716.8
910910
},
911911
},
912912
}

0 commit comments

Comments
 (0)