Skip to content

Commit 72d9b92

Browse files
authored
Fix error from resource based throttling to be retryable (#6992)
* Fix error from resource based throttling to be retryable Signed-off-by: Justin Jung <[email protected]> * lint Signed-off-by: Justin Jung <[email protected]> --------- Signed-off-by: Justin Jung <[email protected]>
1 parent 3d92801 commit 72d9b92

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

pkg/querier/blocks_store_queryable_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/cortexproject/cortex/pkg/util"
4545
"github.com/cortexproject/cortex/pkg/util/limiter"
4646
util_log "github.com/cortexproject/cortex/pkg/util/log"
47+
"github.com/cortexproject/cortex/pkg/util/resource"
4748
"github.com/cortexproject/cortex/pkg/util/services"
4849
"github.com/cortexproject/cortex/pkg/util/validation"
4950
)
@@ -2498,6 +2499,22 @@ func TestBlocksStoreQuerier_PromQLExecution(t *testing.T) {
24982499
}
24992500
}
25002501

2502+
func TestBlocksStoreQuerier_ShouldRetryResourceBasedThrottlingError(t *testing.T) {
2503+
limits := map[resource.Type]float64{
2504+
resource.CPU: 0.5,
2505+
resource.Heap: 0.5,
2506+
}
2507+
2508+
resourceBasedLimiter, err := limiter.NewResourceBasedLimiter(&limiter.MockMonitor{
2509+
CpuUtilization: 0.7,
2510+
HeapUtilization: 0.7,
2511+
}, limits, prometheus.DefaultRegisterer, "ingester")
2512+
require.NoError(t, err)
2513+
2514+
err = resourceBasedLimiter.AcceptNewRequest()
2515+
require.True(t, isRetryableError(err))
2516+
}
2517+
25012518
type blocksStoreSetMock struct {
25022519
services.Service
25032520

pkg/util/limiter/resource_based_limiter.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ func (l *ResourceBasedLimiter) AcceptNewRequest() error {
6464

6565
if utilization >= limit {
6666
l.limitBreachedCount.WithLabelValues(string(resType)).Inc()
67-
return fmt.Errorf("%s utilization limit reached (limit: %.3f, utilization: %.3f)", resType, limit, utilization)
67+
return fmt.Errorf("%s utilization limit reached (limit: %.3f, utilization: %.3f): %w", resType, limit, utilization, &ResourceLimitReachedError{})
6868
}
6969
}
7070

7171
return nil
7272
}
73+
74+
type MockMonitor struct {
75+
CpuUtilization float64
76+
HeapUtilization float64
77+
}
78+
79+
func (m *MockMonitor) GetCPUUtilization() float64 {
80+
return m.CpuUtilization
81+
}
82+
83+
func (m *MockMonitor) GetHeapUtilization() float64 {
84+
return m.HeapUtilization
85+
}

pkg/util/limiter/resource_based_limiter_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ func Test_ResourceBasedLimiter(t *testing.T) {
1515
resource.Heap: 0.5,
1616
}
1717

18-
_, err := NewResourceBasedLimiter(&mockMonitor{}, limits, prometheus.DefaultRegisterer, "ingester")
18+
limiter, err := NewResourceBasedLimiter(&MockMonitor{
19+
CpuUtilization: 0.2,
20+
HeapUtilization: 0.2,
21+
}, limits, prometheus.DefaultRegisterer, "ingester")
1922
require.NoError(t, err)
20-
}
21-
22-
type mockMonitor struct{}
2323

24-
func (m *mockMonitor) GetCPUUtilization() float64 {
25-
return 0
26-
}
27-
28-
func (m *mockMonitor) GetHeapUtilization() float64 {
29-
return 0
24+
err = limiter.AcceptNewRequest()
25+
require.NoError(t, err)
3026
}

0 commit comments

Comments
 (0)