…pec (#6262)
### **User description**
Clean up refactor of rate limits area:
- use rate limiter config object (apispec.GlobalConfig dropped)
- moved rate limiter key computation to happen before rate limiter
logic, deduplicate
- minimized passed arguments
Fixing bugs:
- fixes new rate limiter not proceeding to quota to maintain existing
behaviour
- key computation on new rate limiter now consistent with others
(`rate-` prefix)
https://tyktech.atlassian.net/browse/TT-11739
___
### **PR Type**
Bug fix, Enhancement
___
### **Description**
- Decoupled `GlobalConfig` from various rate limiting and quota
management functions across multiple files to enhance modularity.
- Centralized rate limiter key prefix usage and standardized key
generation logic.
- Removed redundant parameters and streamlined logic in session
management and rate limiting functions.
- Added new utility functions to manage rate limiter configurations and
key generation more effectively.
___
### **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>mw_api_rate_limit.go</strong><dd><code>Simplify API
Rate Limiting Logic and Decouple Global Config</code></dd></summary>
<hr>
gateway/mw_api_rate_limit.go
<li>Removed reference to <code>GlobalConfig</code> from rate limiting
logic.<br> <li> Simplified function arguments by removing unnecessary
parameters.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-46326b04f936c839922e970db5c2924156cc797070948f3dc9c589d04661d6d2">+0/-1</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>mw_organisation_activity.go</strong><dd><code>Refactor
Organisation Activity Rate Limiting</code>
</dd></summary>
<hr>
gateway/mw_organisation_activity.go
<li>Removed <code>GlobalConfig</code> references in rate limiting
checks.<br> <li> Streamlined function parameters to enhance clarity and
<br>maintainability.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-26dd955903317b085be06642ae3e76fe41c8c53844d8758a1a1c8bd05b0110a2">+0/-2</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>mw_rate_limiting.go</strong><dd><code>Refactor Rate
Limiting and Quota Checks</code>
</dd></summary>
<hr>
gateway/mw_rate_limiting.go
<li>Decoupled <code>GlobalConfig</code> from rate limiting and quota
checks.<br> <li> Consolidated rate limiting key computation logic.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-4bf8ae01ccab67bb786468f793f6bb4324c8f6b950b0e98e203effebe763a630">+0/-2</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>session_manager.go</strong><dd><code>Centralize Rate
Limiter Key Prefix and Optimize Session Limiter</code></dd></summary>
<hr>
gateway/session_manager.go
<li>Centralized rate limiter key prefix to
<code>rate.LimiterKeyPrefix</code>.<br> <li> Optimized session limiter
functions by removing redundant parameters <br>and simplifying
logic.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-e6b40a285464cd86736e970c4c0b320b44c75b18b363d38c200e9a9d36cdabb6">+42/-74</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>limiter.go</strong><dd><code>Enhance Rate Limiter
Configuration and Key Generation</code>
</dd></summary>
<hr>
internal/rate/limiter.go
<li>Added <code>LimiterKey</code> function to standardize rate limiter
key generation.<br> <li> Enhanced modularity by separating limiter
configuration logic.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-84e3fda0965028c6e464ae0916aaef0af63d0367fde6f910b513a610f2a34ee5">+16/-0</a>
</td>
</tr>
<tr>
<td>
<details>
<summary><strong>rate.go</strong><dd><code>Update Constants and Error
Handling for Rate Limiters</code>
</dd></summary>
<hr>
internal/rate/rate.go
<li>Introduced <code>LimiterKeyPrefix</code> for consistent key
naming.<br> <li> Updated constants and error handling for rate
limiters.<br>
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6262/files#diff-666e0b0c32c831ededfd6c780dbf916d10e4b7d9c8e02f157bf1dca1d58a360d">+10/-3</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 <[email protected]>
User description
Clean up refactor of rate limits area:
Fixing bugs:
rate-prefix)https://tyktech.atlassian.net/browse/TT-11739
PR Type
Bug fix, Enhancement
Description
GlobalConfigfrom various rate limiting and quota management functions across multiple files to enhance modularity.Changes walkthrough 📝
mw_api_rate_limit.go
Simplify API Rate Limiting Logic and Decouple Global Configgateway/mw_api_rate_limit.go
GlobalConfigfrom rate limiting logic.mw_organisation_activity.go
Refactor Organisation Activity Rate Limitinggateway/mw_organisation_activity.go
GlobalConfigreferences in rate limiting checks.maintainability.
mw_rate_limiting.go
Refactor Rate Limiting and Quota Checksgateway/mw_rate_limiting.go
GlobalConfigfrom rate limiting and quota checks.session_manager.go
Centralize Rate Limiter Key Prefix and Optimize Session Limitergateway/session_manager.go
rate.LimiterKeyPrefix.and simplifying logic.
limiter.go
Enhance Rate Limiter Configuration and Key Generationinternal/rate/limiter.go
LimiterKeyfunction to standardize rate limiter key generation.rate.go
Update Constants and Error Handling for Rate Limitersinternal/rate/rate.go
LimiterKeyPrefixfor consistent key naming.