-
Notifications
You must be signed in to change notification settings - Fork 820
Add nativeHistograms IngestionRate limit #6794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PaurushGarg
wants to merge
7
commits into
cortexproject:master
Choose a base branch
from
PaurushGarg:native-histograms-ingestion-rate-limit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+292
−60
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e7d86bc
Add native histograms ingestion rate limit
PaurushGarg be1d61b
Adding Tests and Updating Docs
PaurushGarg 0b4cb0d
Resolving failed testcase
PaurushGarg 822cb4d
Resolving comments
PaurushGarg f2e4c1f
Resolving comments
PaurushGarg 55896c8
Updating doc
PaurushGarg ff78e59
Changing NativeHistograms default ingestion limits
PaurushGarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"flag" | ||
"fmt" | ||
"io" | ||
"math" | ||
"net/http" | ||
"sort" | ||
"strings" | ||
|
@@ -95,7 +96,8 @@ type Distributor struct { | |
HATracker *ha.HATracker | ||
|
||
// Per-user rate limiter. | ||
ingestionRateLimiter *limiter.RateLimiter | ||
ingestionRateLimiter *limiter.RateLimiter | ||
nativeHistogramsIngestionRateLimiter *limiter.RateLimiter | ||
|
||
// Manager for subservices (HA Tracker, distributor ring and client pool) | ||
subservices *services.Manager | ||
|
@@ -267,11 +269,13 @@ func New(cfg Config, clientConfig ingester_client.Config, limits *validation.Ove | |
// it's an internal dependency and can't join the distributors ring, we skip rate | ||
// limiting. | ||
var ingestionRateStrategy limiter.RateLimiterStrategy | ||
var nativeHistogramsIngestionRateStrategy limiter.RateLimiterStrategy | ||
var distributorsLifeCycler *ring.Lifecycler | ||
var distributorsRing *ring.Ring | ||
|
||
if !canJoinDistributorsRing { | ||
ingestionRateStrategy = newInfiniteIngestionRateStrategy() | ||
nativeHistogramsIngestionRateStrategy = newInfiniteIngestionRateStrategy() | ||
} else if limits.IngestionRateStrategy() == validation.GlobalIngestionRateStrategy { | ||
distributorsLifeCycler, err = ring.NewLifecycler(cfg.DistributorRing.ToLifecyclerConfig(), nil, "distributor", ringKey, true, true, log, prometheus.WrapRegistererWithPrefix("cortex_", reg)) | ||
if err != nil { | ||
|
@@ -285,21 +289,24 @@ func New(cfg Config, clientConfig ingester_client.Config, limits *validation.Ove | |
subservices = append(subservices, distributorsLifeCycler, distributorsRing) | ||
|
||
ingestionRateStrategy = newGlobalIngestionRateStrategy(limits, distributorsLifeCycler) | ||
nativeHistogramsIngestionRateStrategy = newGlobalNativeHistogramsIngestionRateStrategy(limits, distributorsLifeCycler) | ||
} else { | ||
ingestionRateStrategy = newLocalIngestionRateStrategy(limits) | ||
nativeHistogramsIngestionRateStrategy = newLocalNativeHistogramsIngestionRateStrategy(limits) | ||
} | ||
|
||
d := &Distributor{ | ||
cfg: cfg, | ||
log: log, | ||
ingestersRing: ingestersRing, | ||
ingesterPool: NewPool(cfg.PoolConfig, ingestersRing, cfg.IngesterClientFactory, log), | ||
distributorsLifeCycler: distributorsLifeCycler, | ||
distributorsRing: distributorsRing, | ||
limits: limits, | ||
ingestionRateLimiter: limiter.NewRateLimiter(ingestionRateStrategy, 10*time.Second), | ||
HATracker: haTracker, | ||
ingestionRate: util_math.NewEWMARate(0.2, instanceIngestionRateTickInterval), | ||
cfg: cfg, | ||
log: log, | ||
ingestersRing: ingestersRing, | ||
ingesterPool: NewPool(cfg.PoolConfig, ingestersRing, cfg.IngesterClientFactory, log), | ||
distributorsLifeCycler: distributorsLifeCycler, | ||
distributorsRing: distributorsRing, | ||
limits: limits, | ||
ingestionRateLimiter: limiter.NewRateLimiter(ingestionRateStrategy, 10*time.Second), | ||
nativeHistogramsIngestionRateLimiter: limiter.NewRateLimiter(nativeHistogramsIngestionRateStrategy, 10*time.Second), | ||
HATracker: haTracker, | ||
ingestionRate: util_math.NewEWMARate(0.2, instanceIngestionRateTickInterval), | ||
|
||
queryDuration: instrument.NewHistogramCollector(promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "cortex", | ||
|
@@ -774,16 +781,32 @@ func (d *Distributor) Push(ctx context.Context, req *cortexpb.WriteRequest) (*co | |
|
||
totalSamples := validatedFloatSamples + validatedHistogramSamples | ||
totalN := totalSamples + validatedExemplars + len(validatedMetadata) | ||
if !d.ingestionRateLimiter.AllowN(now, userID, totalN) { | ||
|
||
nhRateLimited := false | ||
if limits.NativeHistogramsIngestionRate != math.MaxFloat64 { | ||
nhRateLimited = !d.nativeHistogramsIngestionRateLimiter.AllowN(now, userID, validatedHistogramSamples) | ||
} | ||
rateLimited := !d.ingestionRateLimiter.AllowN(now, userID, totalN) | ||
|
||
// Return a 429 here to tell the client it is going too fast. | ||
// Client may discard the data or slow down and re-send. | ||
// Prometheus v2.26 added a remote-write option 'retry_on_http_429'. | ||
if nhRateLimited { | ||
// Ensure the request slice is reused if the request is rate limited. | ||
cortexpb.ReuseSlice(req.Timeseries) | ||
d.validateMetrics.DiscardedSamples.WithLabelValues(validation.NativeHistogramsRateLimited, userID).Add(float64(totalSamples)) | ||
d.validateMetrics.DiscardedExemplars.WithLabelValues(validation.NativeHistogramsRateLimited, userID).Add(float64(validatedExemplars)) | ||
d.validateMetrics.DiscardedMetadata.WithLabelValues(validation.NativeHistogramsRateLimited, userID).Add(float64(len(validatedMetadata))) | ||
|
||
return nil, httpgrpc.Errorf(http.StatusTooManyRequests, "native histograms ingestion rate limit (%v) exceeded while adding %d samples and %d metadata", d.nativeHistogramsIngestionRateLimiter.Limit(now, userID), totalSamples, len(validatedMetadata)) | ||
} | ||
if rateLimited { | ||
// Ensure the request slice is reused if the request is rate limited. | ||
cortexpb.ReuseSlice(req.Timeseries) | ||
d.validateMetrics.DiscardedSamples.WithLabelValues(validation.RateLimited, userID).Add(float64(totalSamples)) | ||
d.validateMetrics.DiscardedExemplars.WithLabelValues(validation.RateLimited, userID).Add(float64(validatedExemplars)) | ||
d.validateMetrics.DiscardedMetadata.WithLabelValues(validation.RateLimited, userID).Add(float64(len(validatedMetadata))) | ||
// Return a 429 here to tell the client it is going too fast. | ||
// Client may discard the data or slow down and re-send. | ||
// Prometheus v2.26 added a remote-write option 'retry_on_http_429'. | ||
|
||
return nil, httpgrpc.Errorf(http.StatusTooManyRequests, "ingestion rate limit (%v) exceeded while adding %d samples and %d metadata", d.ingestionRateLimiter.Limit(now, userID), totalSamples, len(validatedMetadata)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR. We should mention number of dropped exemplars as well. |
||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we always returning
NativeHistogramsRateLimited
? Can't this be trigger only byrateLimited
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much.
I needed to set label value validation.RateLimited in case it is
rateLimited
due to IngestionRate limit, and set label value validation.NativeHistogramsRateLimited in case it isnhRateLimited
due to nativeHistogramsIngestionRate limit.Updated now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need to drop all samples, exemplars and metadata if native histograms are rate limited?
The default ingestion rate drop everything today because it passes all to the rate limiter. But NH limiter we only check native histograms so it should only throttle native histograms.
I think it doesn't make sense for this limit to impact the existing ingestion rate limit if NH limit is set very small but there is still big room for the default ingestion rate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. we can just block NH