-
Notifications
You must be signed in to change notification settings - Fork 825
Add nativeHistogram 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
Add nativeHistogram IngestionRate limit #6794
Conversation
Signed-off-by: Paurush Garg <[email protected]>
6c2fcba
to
e7d86bc
Compare
Why do we need new limits for nativeHistogram? cortex/pkg/distributor/distributor.go Line 775 in 844fa55
|
NH samples are much more expensive that float samples. |
I think this is more an timeseries limit, no? I am not sure the mem impact ingestionRate. But @PaurushGarg talked to me offline. It seems there are good reason for this. Lets just update the description |
Signed-off-by: Paurush Garg <[email protected]>
There is one test failure related to this change.
|
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.
Overall the change looks good.
Signed-off-by: Paurush Garg <[email protected]>
bb248fa
to
0b4cb0d
Compare
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.
LGTM!
pkg/distributor/distributor.go
Outdated
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))) |
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 by rateLimited
?
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 is nhRateLimited
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
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.
This is still the same. no? Ben suggested we drop only validatedHistogramSamples
and dont fail the request right away
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.
Is there a use case for ingesting partial samples? I feel it's simpler to drop everything.
Also, we don't do partial ingestion for float samples. For example, in a remote write request with 10K samples, even if ingesting 9K samples is within the rate limit, we still reject the entire request.
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.
For me this seems a different type of rejection. For the ones we have today is a global limiter which if we want to accept until the limit we need to "choose" what goes through and what is rejected. This seems more complicated.
For a new limit as specific for nh we can just limit nh samples at all even if we could accept part of it, but allow the rest to go.
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. Updated now.
I want to confirm on below two points:
Even when the NH samples are dropped by the NHRateLimiter, this PR does not reduce the totalN
value (by removing the NH Samples count that were dropped by NHRateLimiter).
This is to keep the existing rate limiter behaviour untouched.
So, basically, where NH Samples were discarded by the NHRateLimiter, the existing rateLimiter would still rateLimit on the basis of total samples received in the request, regardless of whether they were already discarded by NHRateLimiter or not. And similarly, the dropped NH samples (dropped by NH Rate Limiter) would still exhaust the tokens of current RateLimiter.
Incase of NHRateLimiting, this CR doesn't return any error message or 429 to Client. It only publishes the discarded samples metric with label value exclusive for NHRateLimiter.
pkg/distributor/distributor.go
Outdated
// 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 { |
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.
nit: this can still be in the previous if
for sending metrics? any reason to remove from inside it?
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. Updated.
Signed-off-by: Paurush Garg <[email protected]>
@@ -3427,6 +3427,10 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s | |||
# CLI flag: -distributor.ingestion-rate-limit | |||
[ingestion_rate: <float> | default = 25000] | |||
|
|||
# Per-user nativeHistograms ingestion rate limit in samples per second. | |||
# CLI flag: -distributor.native-histograms-ingestion-rate-limit | |||
[native_histograms_ingestion_rate: <float> | default = 25000] |
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.
I am worry that we are deploying this as 25k default. This can cause impact for users who are using NH and override their ingester_rate but are not aware of new limit when deploying. i think i prefer this being 0 which means disabled as default. It will be limited by ingestion_rate if disabled by default.
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 Daniel. I have now implemented this.
Signed-off-by: Paurush Garg <[email protected]>
Signed-off-by: Paurush Garg <[email protected]>
pkg/distributor/distributor.go
Outdated
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))) |
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
pkg/distributor/distributor.go
Outdated
|
||
return nil, httpgrpc.Errorf(http.StatusTooManyRequests, "nativeHistograms ingestion rate limit (%v) exceeded while adding %d samples and %d metadata", d.nativeHistogramsIngestionRateLimiter.Limit(now, userID), totalSamples, len(validatedMetadata)) |
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.
Let's not use camel case for nativeHistograms
. How about
native histogram ingestion rate limit (%v) exceeded while adding %d native histogram samples`
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. I have updated now.
pkg/distributor/distributor.go
Outdated
if limits.NativeHistogramsIngestionRate > 0 && limits.NativeHistogramsIngestionBurstSize > 0 { | ||
nhRateLimited = !d.nativeHistogramsIngestionRateLimiter.AllowN(now, userID, validatedHistogramSamples) | ||
} |
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.
Hm i am not sure this is how was imagining it. I think the limiter could handle this 0 as disabled.
Looking at the rate documentation, 0 is a valid value meaning all will be blocked. MaxFloat is disabling it. We might can add the default as maxFloat and see if it will work
https://github.com/cortexproject/cortex/blob/master/vendor/golang.org/x/time/rate/rate.go#L40
@yeya24 opinion?
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.
That's a good catch.
If ingestion rate is set to 0 then we just don't run d.nativeHistogramsIngestionRateLimiter.AllowN
. Or as Daniel said we use a very big value.
Let's set default to max float.
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. I have updated now.
Signed-off-by: Paurush Garg <[email protected]>
pkg/distributor/distributor.go
Outdated
if !d.ingestionRateLimiter.AllowN(now, userID, totalN) { | ||
|
||
nhRateLimited := false | ||
if limits.NativeHistogramsIngestionRate != math.MaxFloat64 { |
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.
We can remove the if
. Lets leave the library do its job. I dont expect it to be resource intensive
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 updated.
After removing this if condition, the Push tests failed for global strategy (when histograms were enabled). That was b/c the global rate strategy divide inf by num of distributors, and then its not a special value any more for rate lib.
pkg/distributor/distributor.go
Outdated
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))) |
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.
This is still the same. no? Ben suggested we drop only validatedHistogramSamples
and dont fail the request right away
Signed-off-by: Paurush Garg <[email protected]>
Signed-off-by: Paurush Garg <[email protected]>
@@ -3436,6 +3441,10 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s | |||
# CLI flag: -distributor.ingestion-burst-size | |||
[ingestion_burst_size: <int> | default = 50000] | |||
|
|||
# Per-user allowed native histogram ingestion burst size (in number of samples) |
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.
Shouldn't the burst also be MaxFloat? Would it work if the burst is 0?
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.
Burst is int as per the Rate lib we are using for this throttling: https://github.com/cortexproject/cortex/blob/master/vendor/golang.org/x/time/rate/rate.go#L78
0 and Inf are handled as special cases in this lib: https://github.com/cortexproject/cortex/blob/master/vendor/golang.org/x/time/rate/rate.go#L37
* Add native histograms ingestion rate limit Signed-off-by: Paurush Garg <[email protected]> * Adding Tests and Updating Docs Signed-off-by: Paurush Garg <[email protected]> * Resolving failed testcase Signed-off-by: Paurush Garg <[email protected]> * Resolving comments Signed-off-by: Paurush Garg <[email protected]> * Resolving comments Signed-off-by: Paurush Garg <[email protected]> * Updating doc Signed-off-by: Paurush Garg <[email protected]> * Changing NativeHistograms default ingestion limits Signed-off-by: Paurush Garg <[email protected]> * Discard only NH Samples for NH Rate Limiter Signed-off-by: Paurush Garg <[email protected]> * Adding more test coverage Signed-off-by: Paurush Garg <[email protected]> --------- Signed-off-by: Paurush Garg <[email protected]>
What this PR does:
As the ingestion of native histogram samples is much more CPU intensive than that of float samples - adding nativeHistogram samples specific IngestionRate limit to protect the service and to allow clients to adjust the NH series ingestion.
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]