Closed jeffy-mathew closed 2 months ago
API Changes
no api changes detected
β±οΈ Estimated effort to review: 4 π΅π΅π΅π΅βͺ |
π§ͺ PR contains tests |
π No security concerns identified |
β‘ Key issues to review Endpoint Limits Logic The logic for applying endpoint level limits (`ApplyEndpointLevelLimits`) needs careful review to ensure that it correctly handles overlapping endpoints and respects the most restrictive limits. The merging strategy should be verified against expected behaviors, especially in complex scenarios with multiple overlapping policies. Test Coverage Ensure that the new test cases added for handling combined endpoint rate limits (`combinedEndpointRLTCs`) are comprehensive and cover all edge cases, particularly for scenarios where policies might conflict or require complex merging logic. |
Category | Suggestion | Score |
Possible bug |
Ensure updates are tracked by setting the
___
**Ensure that the | 9 |
Enhancement |
Simplify slice cloning and reversing using
___
**Replace the manual copying and reversing of slices with the | 8 |
Maintainability |
Refactor to handle empty current endpoints at the start of the function___ **Refactor theApplyEndpointLevelLimits function to avoid redundant checks and improve readability by handling the case where currEPMap is empty at the start of the function.** [internal/policy/apply.go [573-576]](https://github.com/TykTechnologies/tyk/pull/6494/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1R573-R576) ```diff -currEPMap := currEndpoints.Map() -if len(currEPMap) == 0 { +if len(currEndpoints) == 0 { return policyEndpoints } +currEPMap := currEndpoints.Map() ``` Suggestion importance[1-10]: 7Why: The refactor improves code readability and efficiency by handling the empty case early, reducing unnecessary operations and making the function logic clearer. | 7 |
Best practice |
Improve variable naming for clarity___ **Use a more descriptive variable name thanok in the ApplyEndpointLevelLimits function to enhance code readability and maintainability.** [internal/policy/apply.go [584-585]](https://github.com/TykTechnologies/tyk/pull/6494/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1R584-R585) ```diff -policyRL, ok := result[currEP] -if !ok { +policyRL, exists := result[currEP] +if !exists { ``` Suggestion importance[1-10]: 6Why: Using a more descriptive variable name enhances code readability and maintainability, which is a good practice, although it is a minor improvement. | 6 |
Failed conditions
0.0% Coverage on New Code (required β₯ 80%)
Description
This PR would allow combining endpoint rate limits by combining multiple non partitioned policies.
Related Issue
Jira: https://tyktech.atlassian.net/browse/TT-13011
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Tests, Enhancement
Description
applyAPILevelLimits
function to ensure correct updating ofSetBy
andAllowanceScope
attributes.Changes walkthrough π
policy_test.go
Enhance policy tests to include endpoint rate limits
gateway/policy_test.go
reverseOrder
field totestApplyPoliciesData
struct.rate limits.
apply_test.go
Add tests for endpoint level limits application
internal/policy/apply_test.go
TestApplyEndpointLevelLimits
.policies.json
Update test policies with endpoint rate limits
gateway/testdata/policies.json
apply_endpoint_rl.json
Add test data for endpoint rate limits application
internal/policy/testdata/apply_endpoint_rl.json - Added test cases for applying endpoint rate limits.
apply.go
Implement endpoint level limits application in policies
internal/policy/apply.go
applyAPILevelLimits
to updateSetBy
andAllowanceScope
.applyEndpointLevelLimits
toApplyEndpointLevelLimits
.