-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[TT-12285] Add smoothing, fix duplicate x-go-name #6346
[TT-12285] Add smoothing, fix duplicate x-go-name #6346
Conversation
API Changes --- prev.txt 2024-06-17 13:23:20.652887754 +0000
+++ current.txt 2024-06-17 13:23:17.416863277 +0000
@@ -1670,16 +1670,16 @@
// Enabled indicates if rate limit smoothing is active.
Enabled bool `json:"enabled" bson:"enabled"`
- // Threshold is the request rate above which smoothing is applied.
+ // Threshold is the initial rate limit beyond which smoothing will be applied. It is a count of requests during the `per` interval and should be less than the maximum configured `rate`.
Threshold int64 `json:"threshold" bson:"threshold"`
- // Trigger is the step factor determining when smoothing events trigger.
+ // Trigger is a fraction (typically in the range 0.1-1.0) of the step at which point a smoothing event will be emitted as the request rate approaches the current allowance.
Trigger float64 `json:"trigger" bson:"trigger"`
- // Step is the increment/decrement for adjusting the rate limit.
+ // Step is the increment by which the current allowance will be increased or decreased each time a smoothing event is emitted.
Step int64 `json:"step" bson:"step"`
- // Delay is the minimum time between rate limit changes (in seconds).
+ // Delay is a hold-off between smoothing events and controls how frequently the current allowance will step up or down (in seconds).
Delay int64 `json:"delay" bson:"delay"`
}
RateLimitSmoothing holds the rate smoothing configuration.
@@ -1701,17 +1701,23 @@
`threshold` after which to apply smoothing (minimum rate for window) -
`trigger` configures at which fraction of a step a smoothing event is
emitted - `step` is the value by which the rate allowance will get adjusted
- - `delay` is the amount of seconds between smoothing updates
+ - `delay` is a hold-off in seconds providing a minimum period between rate
+ allowance adjustments
- This is used to compute a request allowance. The request allowance will
- be smoothed between `threshold`, and the defined rate limits (maximum).
- The request allowance will be updated internally every `delay` seconds.
-
- The `step * trigger` value is substracted from the request allowance, and
- if your request rate goes above that, then a RateLimitSmoothingUp event is
- emitted and the allowance is increased by `step`. A RateLimitSmoothingDown
- event is emitted when the request rate drops one step below that, and the
- allowance then decreases by step.
+ To determine if the request rate is growing and needs to be smoothed,
+ the `step * trigger` value is subtracted from the request allowance and,
+ if the request rate goes above that, then a RateLimitSmoothingUp event is
+ emitted and the rate allowance is increased by `step`.
+
+ Once the request allowance has been increased above the `threshold`,
+ Tyk will start to check for decreasing request rate. When the request
+ rate drops `step * (1 + trigger)` below the request allowance,
+ a `RateLimitSmoothingDown` event is emitted and the rate allowance is
+ decreased by `step`.
+
+ After the request allowance has been adjusted (up or down), the request
+ rate will be checked again over the next `delay` seconds and, if required,
+ further adjustment made to the rate allowance after the hold-off.
For any allowance, events are emitted based on the following calculations:
@@ -1721,17 +1727,28 @@
a RateLimitSmoothingDown event is emitted and allowance decreases by
`step`.
- Example: Allowance: 600, Current rate: 500, Step: 100, Trigger: 0.5
+ Example: Threshold: 400, Request allowance: 600, Current rate: 500, Step:
+ 100, Trigger: 0.5.
- - To trigger a RateLimitSmoothingUp event, the request rate must exceed:
- Allowance - (Step * Trigger) Calculation: 600 - (100 * 0.5) = 550
- Exceeding a request rate of 550 will increase the allowance to 700
- (Allowance + Step).
-
- - To trigger a RateLimitSmoothingDown event, the request rate must fall
- below: Allowance - (Step + (Step * Trigger)) Calculation: 600 - (100
- + (100 * 0.5)) = 450 As the request rate falls below 450, that will
- decrease the allowance to 500 (Allowance - Step).
+ To trigger a RateLimitSmoothingUp event, the request rate must exceed:
+
+ - Calculation: Allowance - (Step * Trigger).
+ - Example: 600 - (100 * 0.5) = `550`.
+
+ Exceeding a request rate of `550` will increase the allowance to 700
+ (Allowance + Step).
+
+ To trigger a RateLimitSmoothingDown event, the request rate must fall below:
+
+ - Calculation: Allowance - (Step + (Step * Trigger)).
+ - Example: 600 - (100 + (100 * 0.5)) = 450.
+
+ As the request rate falls below 450, that will decrease the allowance to 500
+ (Allowance - Step).
+
+ The request allowance will be smoothed between `threshold`, and the defined
+ `rate` limit (maximum). The request allowance will be updated internally
+ every `delay` seconds.
func (r *RateLimitSmoothing) Err() error
Err checks the rate limit smoothing configuration for validity and returns |
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
1 similar comment
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
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.
Suggested changes to improve consistency
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 for the changes. 🙏
Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com>
cfc28cf
to
653d40c
Compare
Quality Gate passedIssues Measures |
/release to release-5.4 |
Working on it! Note that it can take a few minutes. |
### **User description** Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name. ___ ### **PR Type** enhancement, documentation ___ ### **Description** - Added a new `RateLimitSmoothing` schema to define rate limit smoothing settings, including properties like `delay`, `enabled`, `step`, `threshold`, and `trigger`. - Updated the `Policy` and `SessionState` definitions to include the `smoothing` property referencing the new `RateLimitSmoothing` schema. - Changed the `x-go-name` for the `_id` property in the `Policy` definition from `ID` to `MID` to fix a duplicate name issue. - Provided detailed descriptions and titles for the new `RateLimitSmoothing` schema and its properties. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>swagger.yml</strong><dd><code>Add rate limit smoothing and update Policy schema</code> </dd></summary> <hr> swagger.yml <li>Added <code>smoothing</code> property to <code>Policy</code> and <code>SessionState</code> definitions.<br> <li> Introduced <code>RateLimitSmoothing</code> schema with detailed description and <br>properties.<br> <li> Changed <code>x-go-name</code> for <code>_id</code> property in <code>Policy</code> definition to <code>MID</code>.<br> <li> Added titles and descriptions for new and existing components.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6346/files#diff-8f3c4cb253eee09ae2401daa7279a8bbfbfd4168bb579c3ac0ee5c672d63bb2c">+89/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io> Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com> (cherry picked from commit e10e7ef)
@titpetric Succesfully merged PR |
…name (#6346) [TT-12285] Add smoothing, fix duplicate x-go-name (#6346) ### **User description** Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name. ___ ### **PR Type** enhancement, documentation ___ ### **Description** - Added a new `RateLimitSmoothing` schema to define rate limit smoothing settings, including properties like `delay`, `enabled`, `step`, `threshold`, and `trigger`. - Updated the `Policy` and `SessionState` definitions to include the `smoothing` property referencing the new `RateLimitSmoothing` schema. - Changed the `x-go-name` for the `_id` property in the `Policy` definition from `ID` to `MID` to fix a duplicate name issue. - Provided detailed descriptions and titles for the new `RateLimitSmoothing` schema and its properties. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>swagger.yml</strong><dd><code>Add rate limit smoothing and update Policy schema</code> </dd></summary> <hr> swagger.yml <li>Added <code>smoothing</code> property to <code>Policy</code> and <code>SessionState</code> definitions.<br> <li> Introduced <code>RateLimitSmoothing</code> schema with detailed description and <br>properties.<br> <li> Changed <code>x-go-name</code> for <code>_id</code> property in <code>Policy</code> definition to <code>MID</code>.<br> <li> Added titles and descriptions for new and existing components.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6346/files#diff-8f3c4cb253eee09ae2401daa7279a8bbfbfd4168bb579c3ac0ee5c672d63bb2c">+89/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io> Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com>
/release to release-5.4.0 |
Working on it! Note that it can take a few minutes. |
### **User description** Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name. ___ ### **PR Type** enhancement, documentation ___ ### **Description** - Added a new `RateLimitSmoothing` schema to define rate limit smoothing settings, including properties like `delay`, `enabled`, `step`, `threshold`, and `trigger`. - Updated the `Policy` and `SessionState` definitions to include the `smoothing` property referencing the new `RateLimitSmoothing` schema. - Changed the `x-go-name` for the `_id` property in the `Policy` definition from `ID` to `MID` to fix a duplicate name issue. - Provided detailed descriptions and titles for the new `RateLimitSmoothing` schema and its properties. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>swagger.yml</strong><dd><code>Add rate limit smoothing and update Policy schema</code> </dd></summary> <hr> swagger.yml <li>Added <code>smoothing</code> property to <code>Policy</code> and <code>SessionState</code> definitions.<br> <li> Introduced <code>RateLimitSmoothing</code> schema with detailed description and <br>properties.<br> <li> Changed <code>x-go-name</code> for <code>_id</code> property in <code>Policy</code> definition to <code>MID</code>.<br> <li> Added titles and descriptions for new and existing components.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6346/files#diff-8f3c4cb253eee09ae2401daa7279a8bbfbfd4168bb579c3ac0ee5c672d63bb2c">+89/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io> Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com> (cherry picked from commit e10e7ef)
@titpetric Succesfully merged PR |
…o-name (#6346) [TT-12285] Add smoothing, fix duplicate x-go-name (#6346) ### **User description** Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name. ___ ### **PR Type** enhancement, documentation ___ ### **Description** - Added a new `RateLimitSmoothing` schema to define rate limit smoothing settings, including properties like `delay`, `enabled`, `step`, `threshold`, and `trigger`. - Updated the `Policy` and `SessionState` definitions to include the `smoothing` property referencing the new `RateLimitSmoothing` schema. - Changed the `x-go-name` for the `_id` property in the `Policy` definition from `ID` to `MID` to fix a duplicate name issue. - Provided detailed descriptions and titles for the new `RateLimitSmoothing` schema and its properties. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>swagger.yml</strong><dd><code>Add rate limit smoothing and update Policy schema</code> </dd></summary> <hr> swagger.yml <li>Added <code>smoothing</code> property to <code>Policy</code> and <code>SessionState</code> definitions.<br> <li> Introduced <code>RateLimitSmoothing</code> schema with detailed description and <br>properties.<br> <li> Changed <code>x-go-name</code> for <code>_id</code> property in <code>Policy</code> definition to <code>MID</code>.<br> <li> Added titles and descriptions for new and existing components.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6346/files#diff-8f3c4cb253eee09ae2401daa7279a8bbfbfd4168bb579c3ac0ee5c672d63bb2c">+89/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io> Co-authored-by: andyo-tyk <99968932+andyo-tyk@users.noreply.github.com>
User description
Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name.
PR Type
enhancement, documentation
Description
RateLimitSmoothing
schema to define rate limit smoothing settings, including properties likedelay
,enabled
,step
,threshold
, andtrigger
.Policy
andSessionState
definitions to include thesmoothing
property referencing the newRateLimitSmoothing
schema.x-go-name
for the_id
property in thePolicy
definition fromID
toMID
to fix a duplicate name issue.RateLimitSmoothing
schema and its properties.Changes walkthrough 📝
swagger.yml
Add rate limit smoothing and update Policy schema
swagger.yml
smoothing
property toPolicy
andSessionState
definitions.RateLimitSmoothing
schema with detailed description andproperties.
x-go-name
for_id
property inPolicy
definition toMID
.