Skip to content
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
6 changes: 0 additions & 6 deletions docs/blocks-storage/store-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,6 @@ store_gateway:

query_protection:
rejection:
# EXPERIMENTAL: Enable query rejection feature, where the component return
# 503 to all incoming query requests when the configured thresholds are
# breached.
# CLI flag: -store-gateway.query-protection.rejection.enabled
[enabled: <boolean> | default = false]

threshold:
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
# rejecting new query request (across all tenants) in percentage,
Expand Down
12 changes: 0 additions & 12 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3731,12 +3731,6 @@ instance_limits:

query_protection:
rejection:
# EXPERIMENTAL: Enable query rejection feature, where the component return
# 503 to all incoming query requests when the configured thresholds are
# breached.
# CLI flag: -ingester.query-protection.rejection.enabled
[enabled: <boolean> | default = false]

threshold:
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
# rejecting new query request (across all tenants) in percentage, between
Expand Down Expand Up @@ -6472,12 +6466,6 @@ sharding_ring:

query_protection:
rejection:
# EXPERIMENTAL: Enable query rejection feature, where the component return
# 503 to all incoming query requests when the configured thresholds are
# breached.
# CLI flag: -store-gateway.query-protection.rejection.enabled
[enabled: <boolean> | default = false]

threshold:
# EXPERIMENTAL: Max CPU utilization that this ingester can reach before
# rejecting new query request (across all tenants) in percentage, between
Expand Down
2 changes: 0 additions & 2 deletions pkg/configs/query_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type QueryProtection struct {
}

type rejection struct {
Enabled bool `yaml:"enabled"`
Threshold threshold `yaml:"threshold"`
}

Expand All @@ -24,7 +23,6 @@ type threshold struct {
}

func (cfg *QueryProtection) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) {
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.")
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.")
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.")
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,10 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query
reason = reasonChunksLimitStoreGateway
} else if strings.Contains(errMsg, limitBytesStoreGateway) {
reason = reasonBytesLimitStoreGateway
} else if strings.Contains(errMsg, limiter.ErrResourceLimitReachedStr) {
}
} else if statusCode == http.StatusServiceUnavailable && error != nil {
errMsg := error.Error()
if strings.Contains(errMsg, limiter.ErrResourceLimitReachedStr) {
reason = reasonResourceExhausted
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/transport/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ func TestHandler_ServeHTTP(t *testing.T) {
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
resourceLimitReachedErr := &limiter.ResourceLimitReachedError{}
return &http.Response{
StatusCode: http.StatusUnprocessableEntity,
StatusCode: http.StatusServiceUnavailable,
Body: io.NopCloser(strings.NewReader(resourceLimitReachedErr.Error())),
}, nil
}),
additionalMetricsCheckFunc: func(h *Handler) {
v := promtest.ToFloat64(h.rejectedQueries.WithLabelValues(reasonResourceExhausted, requestmeta.SourceAPI, userID))
assert.Equal(t, float64(1), v)
},
expectedStatusCode: http.StatusUnprocessableEntity,
expectedStatusCode: http.StatusServiceUnavailable,
},
{
name: "test cortex_slow_queries_total",
Expand Down
13 changes: 6 additions & 7 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import (
"github.com/cortexproject/cortex/pkg/util/limiter"
logutil "github.com/cortexproject/cortex/pkg/util/log"
util_math "github.com/cortexproject/cortex/pkg/util/math"
"github.com/cortexproject/cortex/pkg/util/requestmeta"
"github.com/cortexproject/cortex/pkg/util/resource"
"github.com/cortexproject/cortex/pkg/util/services"
"github.com/cortexproject/cortex/pkg/util/spanlogger"
Expand Down Expand Up @@ -1697,7 +1696,7 @@ func (i *Ingester) QueryExemplars(ctx context.Context, req *client.ExemplarQuery
}

// We will report *this* request in the error too.
c, err := i.trackInflightQueryRequest(ctx)
c, err := i.trackInflightQueryRequest()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1805,7 +1804,7 @@ func (i *Ingester) labelsValuesCommon(ctx context.Context, req *client.LabelValu
q.Close()
}

c, err := i.trackInflightQueryRequest(ctx)
c, err := i.trackInflightQueryRequest()
if err != nil {
return nil, cleanup, err
}
Expand Down Expand Up @@ -1902,7 +1901,7 @@ func (i *Ingester) labelNamesCommon(ctx context.Context, req *client.LabelNamesR
q.Close()
}

c, err := i.trackInflightQueryRequest(ctx)
c, err := i.trackInflightQueryRequest()
if err != nil {
return nil, cleanup, err
}
Expand Down Expand Up @@ -2253,7 +2252,7 @@ func (i *Ingester) QueryStream(req *client.QueryRequest, stream client.Ingester_
return nil
}

func (i *Ingester) trackInflightQueryRequest(ctx context.Context) (func(), error) {
func (i *Ingester) trackInflightQueryRequest() (func(), error) {
gl := i.getInstanceLimits()
if gl != nil && gl.MaxInflightQueryRequests > 0 {
if i.inflightQueryRequests.Load() >= gl.MaxInflightQueryRequests {
Expand All @@ -2263,7 +2262,7 @@ func (i *Ingester) trackInflightQueryRequest(ctx context.Context) (func(), error

i.maxInflightQueryRequests.Track(i.inflightQueryRequests.Inc())

if i.resourceBasedLimiter != nil && !requestmeta.RequestFromRuler(ctx) {
if i.resourceBasedLimiter != nil {
if err := i.resourceBasedLimiter.AcceptNewRequest(); err != nil {
level.Warn(i.logger).Log("msg", "failed to accept request", "err", err)
return nil, httpgrpc.Errorf(http.StatusServiceUnavailable, "failed to query: %s", limiter.ErrResourceLimitReachedStr)
Expand All @@ -2283,7 +2282,7 @@ func (i *Ingester) queryStreamChunks(ctx context.Context, db *userTSDB, from, th
}
defer q.Close()

c, err := i.trackInflightQueryRequest(ctx)
c, err := i.trackInflightQueryRequest()
if err != nil {
return 0, 0, 0, 0, err
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import (
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/chunkcompat"
"github.com/cortexproject/cortex/pkg/util/limiter"
"github.com/cortexproject/cortex/pkg/util/requestmeta"
"github.com/cortexproject/cortex/pkg/util/resource"
"github.com/cortexproject/cortex/pkg/util/services"
"github.com/cortexproject/cortex/pkg/util/test"
Expand Down Expand Up @@ -3228,18 +3227,11 @@ func Test_Ingester_Query_ResourceThresholdBreached(t *testing.T) {
}

rreq := &client.QueryRequest{}
ctx = requestmeta.ContextWithRequestSource(ctx, requestmeta.SourceAPI)
s := &mockQueryStreamServer{ctx: ctx}
err = i.QueryStream(rreq, s)
require.Error(t, err)
exhaustedErr := limiter.ResourceLimitReachedError{}
require.ErrorContains(t, err, exhaustedErr.Error())

// we shouldn't reject queries from ruler
ctx = requestmeta.ContextWithRequestSource(ctx, requestmeta.SourceRuler)
s = &mockQueryStreamServer{ctx: ctx}
err = i.QueryStream(rreq, s)
require.Nil(t, err)
}

func TestIngester_LabelValues_ShouldNotCreateTSDBIfDoesNotExists(t *testing.T) {
Expand Down
Loading