Skip to content

Commit 2ef5de0

Browse files
authored
Resource based throttling bug fixes (#7001)
* remove limiting query rejection to only adhoc queries for ingester. This shouldn't have been included as discussed in PR #6947 Signed-off-by: Erlan Zholdubai uulu <[email protected]> * bug fixes for query rejection. fix metric and remove unused enabled flag. Signed-off-by: Erlan Zholdubai uulu <[email protected]> --------- Signed-off-by: Erlan Zholdubai uulu <[email protected]>
1 parent 0d89bb5 commit 2ef5de0

File tree

5 files changed

+6
-23
lines changed

5 files changed

+6
-23
lines changed

docs/blocks-storage/store-gateway.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,6 @@ store_gateway:
357357

358358
query_protection:
359359
rejection:
360-
# EXPERIMENTAL: Enable query rejection feature, where the component return
361-
# 503 to all incoming query requests when the configured thresholds are
362-
# breached.
363-
# CLI flag: -store-gateway.query-protection.rejection.enabled
364-
[enabled: <boolean> | default = false]
365-
366360
threshold:
367361
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
368362
# rejecting new query request (across all tenants) in percentage,

docs/configuration/config-file-reference.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,12 +3731,6 @@ instance_limits:
37313731
37323732
query_protection:
37333733
rejection:
3734-
# EXPERIMENTAL: Enable query rejection feature, where the component return
3735-
# 503 to all incoming query requests when the configured thresholds are
3736-
# breached.
3737-
# CLI flag: -ingester.query-protection.rejection.enabled
3738-
[enabled: <boolean> | default = false]
3739-
37403734
threshold:
37413735
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
37423736
# rejecting new query request (across all tenants) in percentage, between
@@ -6472,12 +6466,6 @@ sharding_ring:
64726466
64736467
query_protection:
64746468
rejection:
6475-
# EXPERIMENTAL: Enable query rejection feature, where the component return
6476-
# 503 to all incoming query requests when the configured thresholds are
6477-
# breached.
6478-
# CLI flag: -store-gateway.query-protection.rejection.enabled
6479-
[enabled: <boolean> | default = false]
6480-
64816469
threshold:
64826470
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
64836471
# rejecting new query request (across all tenants) in percentage, between

pkg/configs/query_protection.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type QueryProtection struct {
1414
}
1515

1616
type rejection struct {
17-
Enabled bool `yaml:"enabled"`
1817
Threshold threshold `yaml:"threshold"`
1918
}
2019

@@ -24,7 +23,6 @@ type threshold struct {
2423
}
2524

2625
func (cfg *QueryProtection) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) {
27-
f.BoolVar(&cfg.Rejection.Enabled, prefix+"query-protection.rejection.enabled", false, "EXPERIMENTAL: Enable query rejection feature, where the component return 503 to all incoming query requests when the configured thresholds are breached.")
2826
f.Float64Var(&cfg.Rejection.Threshold.CPUUtilization, prefix+"query-protection.rejection.threshold.cpu-utilization", 0, "EXPERIMENTAL: Max CPU utilization that this ingester can reach before rejecting new query request (across all tenants) in percentage, between 0 and 1. monitored_resources config must include the resource type. 0 to disable.")
2927
f.Float64Var(&cfg.Rejection.Threshold.HeapUtilization, prefix+"query-protection.rejection.threshold.heap-utilization", 0, "EXPERIMENTAL: Max heap utilization that this ingester can reach before rejecting new query request (across all tenants) in percentage, between 0 and 1. monitored_resources config must include the resource type. 0 to disable.")
3028
}

pkg/frontend/transport/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,10 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query
584584
reason = reasonChunksLimitStoreGateway
585585
} else if strings.Contains(errMsg, limitBytesStoreGateway) {
586586
reason = reasonBytesLimitStoreGateway
587-
} else if strings.Contains(errMsg, limiter.ErrResourceLimitReachedStr) {
587+
}
588+
} else if statusCode == http.StatusServiceUnavailable && error != nil {
589+
errMsg := error.Error()
590+
if strings.Contains(errMsg, limiter.ErrResourceLimitReachedStr) {
588591
reason = reasonResourceExhausted
589592
}
590593
}

pkg/frontend/transport/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ func TestHandler_ServeHTTP(t *testing.T) {
390390
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
391391
resourceLimitReachedErr := &limiter.ResourceLimitReachedError{}
392392
return &http.Response{
393-
StatusCode: http.StatusUnprocessableEntity,
393+
StatusCode: http.StatusServiceUnavailable,
394394
Body: io.NopCloser(strings.NewReader(resourceLimitReachedErr.Error())),
395395
}, nil
396396
}),
397397
additionalMetricsCheckFunc: func(h *Handler) {
398398
v := promtest.ToFloat64(h.rejectedQueries.WithLabelValues(reasonResourceExhausted, requestmeta.SourceAPI, userID))
399399
assert.Equal(t, float64(1), v)
400400
},
401-
expectedStatusCode: http.StatusUnprocessableEntity,
401+
expectedStatusCode: http.StatusServiceUnavailable,
402402
},
403403
{
404404
name: "test cortex_slow_queries_total",

0 commit comments

Comments
 (0)