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
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