[TT-10856/TT-11593]fix quota limits not working with url rewrite to self#6133
Conversation
|
PR Description updated to latest commit (2f4d4fa) |
|
API Changes no api changes detected |
PR Review
Code feedback:
✨ Review tool usage guide:Overview: With a configuration file, use the following template:
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview: With a configuration file, use the following template:
See the improve usage page for a more comprehensive guide on using this tool. |
💥 CI tests failed 🙈git-stateall okPlease look at the run or in the Checks tab. |
|
API tests result - postgres15-sha256 env: success ✅ |
|
API tests result - mongo44-sha256 env: success ✅ |
2f4d4fa to
068630a
Compare
76b7449 to
b8c773e
Compare
💥 CI tests failed 🙈git-statediff --git a/gateway/reverse_proxy_test.go b/gateway/reverse_proxy_test.go
index 11ea2e0..7ebe94c 100644
--- a/gateway/reverse_proxy_test.go
+++ b/gateway/reverse_proxy_test.go
@@ -19,10 +19,11 @@ import (
textTemplate "text/template"
"time"
- "github.com/TykTechnologies/tyk/header"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/TykTechnologies/tyk/header"
+
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
Please look at the run or in the Checks tab. |
1 similar comment
💥 CI tests failed 🙈git-statediff --git a/gateway/reverse_proxy_test.go b/gateway/reverse_proxy_test.go
index 11ea2e0..7ebe94c 100644
--- a/gateway/reverse_proxy_test.go
+++ b/gateway/reverse_proxy_test.go
@@ -19,10 +19,11 @@ import (
textTemplate "text/template"
"time"
- "github.com/TykTechnologies/tyk/header"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/TykTechnologies/tyk/header"
+
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
Please look at the run or in the Checks tab. |
💥 CI tests failed 🙈git-statediff --git a/gateway/reverse_proxy_test.go b/gateway/reverse_proxy_test.go
index 11ea2e0..7ebe94c 100644
--- a/gateway/reverse_proxy_test.go
+++ b/gateway/reverse_proxy_test.go
@@ -19,10 +19,11 @@ import (
textTemplate "text/template"
"time"
- "github.com/TykTechnologies/tyk/header"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/TykTechnologies/tyk/header"
+
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
Please look at the run or in the Checks tab. |
1 similar comment
💥 CI tests failed 🙈git-statediff --git a/gateway/reverse_proxy_test.go b/gateway/reverse_proxy_test.go
index 11ea2e0..7ebe94c 100644
--- a/gateway/reverse_proxy_test.go
+++ b/gateway/reverse_proxy_test.go
@@ -19,10 +19,11 @@ import (
textTemplate "text/template"
"time"
- "github.com/TykTechnologies/tyk/header"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/TykTechnologies/tyk/header"
+
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
Please look at the run or in the Checks tab. |
b8c773e to
0565ec1
Compare
|
|
/release to release-5.3 |
|
/release to release-5.3.0 |
|
Working on it! Note that it can take a few minutes. |
1 similar comment
|
Working on it! Note that it can take a few minutes. |
…elf (#6133) ## **User description** fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` ## Description Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. ## Related Issue https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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 (cherry picked from commit 3a78b0d)
|
@jeffy-mathew Seems like there is conflict and it require manual merge. |
|
Still working... |
…elf (#6133) ## **User description** fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` ## Description Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. ## Related Issue https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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 (cherry picked from commit 3a78b0d)
…king with url rewrite to self (#6133) [TT-10856/TT-11593]fix quota limits not working with url rewrite to self (#6133) ## **User description** fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` ## Description Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. ## Related Issue https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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
|
@jeffy-mathew Succesfully merged PR |
…ng with url rewrite to self (#6133) (#6143) ## **User description** [TT-10856/TT-11593]fix quota limits not working with url rewrite to self (#6133) ## **User description** fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` ## Description Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. ## Related Issue https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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 ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not correctly applied when using URL rewrite to self (`tyk://self/<target-endpoint>/`). - Added tests to ensure quota limits are correctly applied and that the correct quota information is returned in response headers. - Refactored session update scheduling in the quota check to ensure correct behavior. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug_fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure correct session update for quota limits</code> </dd></summary> <hr> gateway/middleware.go <li>Update session before proceeding to the next middleware to ensure <br>quota limits are correctly applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6143/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>session_manager.go</strong><dd><code>Refactor session update scheduling for quota checks</code> </dd></summary> <hr> gateway/session_manager.go <li>Moved session update scheduling to ensure it's always executed when <br>checking for quota exceeded.<br> <li> This change ensures that quota renewal information is correctly <br>updated.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6143/files#diff-e6b40a285464cd86736e970c4c0b320b44c75b18b363d38c200e9a9d36cdabb6">+4/-1</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Test for quota limits with URL rewrite to self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Added a test to verify that quota limits are correctly applied when <br>URL rewrite to self is used.<br> <li> Introduced a helper function to create a session with quota limits for <br>testing.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6143/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>reverse_proxy_test.go</strong><dd><code>Test for correct quota information in response headers</code> </dd></summary> <hr> gateway/reverse_proxy_test.go <li>Added tests to verify correct quota information in response headers.<br> <li> Utilized helper function to create test sessions with quota.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6143/files#diff-ce040f6555143f760fba6059744bc600b6954f0966dfb0fa2832b5eabf7a3c3f">+49/-0</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: Jeffy Mathew <[email protected]>
|
/release to release-5-lts |
|
Working on it! Note that it can take a few minutes. |
|
Still working... |
…elf (#6133) fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 <!-- Why is this change required? What problem does it solve? --> <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ bug_fix, tests ___ - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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 (cherry picked from commit 3a78b0d)
|
@jeffy-mathew Succesfully merged PR |
…king with url rewrite to self (#6133) (#6168) [TT-10856/TT-11593]fix quota limits not working with url rewrite to self (#6133) ## **User description** fix an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<target-endpoint>/` ## Description Quota limits were not applied when URL rewrite middleware is enabled with target of format `tyk://self/<target-endpoint>/`. This was happening with keys created with `access_rights` specified for per API basis. Creating keys from policies also filled in `access_rights` in keys. Having `access_rights` filled in caused `quota_renews` to be set to 0 during URL rewrite. This caused quota limit resets everytime. Updating session before URL rewrite would fix this as the `quota_renews` is correctly applied. calling `mw.Base().UpdateRequestSession(r)` after every middleware execution is okay because it will update session only if a session update is scheduled. https://github.com/TykTechnologies/tyk/blob/53886d044c43930b332dbe4a73cf727069df0770/gateway/middleware.go#L329 The quota related values returned in API response headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` were wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers. ## Related Issue https://tyktech.atlassian.net/browse/TT-10856 https://tyktech.atlassian.net/browse/TT-11593 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** bug_fix, tests ___ ## **Description** - Fixed an issue where quota limits were not applied when URL rewrite middleware target is using `tyk://self/<endpoint>/`. - Added a test case to ensure quota limits are correctly enforced when using URL rewrite to self. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Ensure Session Updates After Middleware Execution</code> </dd></summary> <hr> gateway/middleware.go <li>Added call to <code>UpdateRequestSession</code> after middleware execution to <br>ensure session updates, particularly for quota limits, are applied.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add Test for Quota Limits with URL Rewrite to Self</code> </dd></summary> <hr> gateway/middleware_test.go <li>Imported <code>time</code> package for session creation.<br> <li> Added <code>createSession</code> helper function to simplify session creation for <br>tests.<br> <li> Added <code>TestQuotaNotAppliedWithURLRewrite</code> to validate quota limits are <br>correctly applied when using URL rewrite to self.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6133/files#diff-6a09a08e3f82cc5e9d8c6b5c8426d75ea1e5d85e15ab008fca1f512e7c49c1e6">+66/-0</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: Jeffy Mathew <[email protected]>



User description
fix an issue where quota limits were not applied when URL rewrite middleware target is using
tyk://self/<target-endpoint>/Description
Quota limits were not applied when URL rewrite middleware is enabled with target of format
tyk://self/<target-endpoint>/.This was happening with keys created with
access_rightsspecified for per API basis.Creating keys from policies also filled in
access_rightsin keys.Having
access_rightsfilled in causedquota_renewsto be set to 0 during URL rewrite. This caused quota limit resets everytime.Updating session before URL rewrite would fix this as the
quota_renewsis correctly applied.calling
mw.Base().UpdateRequestSession(r)after every middleware execution is okay because it will update session only if a session update is scheduled.tyk/gateway/middleware.go
Line 329 in 53886d0
The quota related values returned in API response headers
X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Resetwere wrong since a session update was scheduled only during the first hit after a quota reset. This PR also fixes this behaviour to report the correct quota information in those headers.Related Issue
https://tyktech.atlassian.net/browse/TT-10856
https://tyktech.atlassian.net/browse/TT-11593
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Type
bug_fix, tests
Description
tyk://self/<endpoint>/.Changes walkthrough
middleware.go
Ensure Session Updates After Middleware Executiongateway/middleware.go
UpdateRequestSessionafter middleware execution toensure session updates, particularly for quota limits, are applied.
middleware_test.go
Add Test for Quota Limits with URL Rewrite to Selfgateway/middleware_test.go
timepackage for session creation.createSessionhelper function to simplify session creation fortests.
TestQuotaNotAppliedWithURLRewriteto validate quota limits arecorrectly applied when using URL rewrite to self.