Enables a stateless version of Tyk Gateway
User description
This PR uses the new "local" storage driver and is dependent on the in-mem-kv branch/PR in the storage repo to enable Tyk to run without Redis.
Description
This PR enables a new "local" storage type configuration option which swaps the Redis driver to a local non-locking hash map. It also mocks the Queue interface to provide error-free pubsub (obviously it won't work in an actual cluster).
To test it, simply disable analytics, and set the storage type from "redis" to "local".
The local store does all complex operations in-memory, and does not rely on any underlying k/v data store capability (which means it could be used for more data stores even if they don't support Lists, Sets, or Sorted Sets).
Related Issue
Motivation and Context
Providing a stateless gateway that can be deployed without a dependency makes time-to-initial-value faster for end-users. As it supports in-memory operations, quotas, rate-limits, and local tokens all work without any change. This is also useful for our own developers running tests, and existing customers that are spinning up test environments for their own engineers.
How This Has Been Tested
Manually tested the gateway (rate limit and quota only)
Underlying library passes all storage tests (keyvalue, set, sortedset, list, and queue)
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] 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
- [x] I ensured that the documentation is up to date
- [x] 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
PR Type
Enhancement
Description
- Added support for a new "local" storage type configuration option which swaps the Redis driver to a local non-locking hash map.
- Modified gateway initialization to handle "local" storage type for analytics and general storage connection.
- Updated
NewConnectorfunction to handle "local" storage type. - Added a replacement directive in
go.modfor the local storage module.
Changes walkthrough 📝
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Configuration changes |
|
💡 PR-Agent usage: Comment
/helpon the PR to get a list of all available PR-Agent tools and their descriptions
API Changes
no api changes detected
PR Reviewer Guide 🔍
| ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
| ⚡ Key issues to review Configuration Validation Connector Initialization |
PR Code Suggestions ✨
| Category | Suggestion | Score |
| Possible bug |
Handle potential nil pointer dereference by checking if
| 10 |
| Enhancement |
Add a conditional check for analytics enablement before storage type validationAdd a check to ensure that analytics are enabled before checking the storage type,
Suggestion importance[1-10]: 9Why: Adding the conditional check ensures that the storage type validation is only performed when analytics are enabled, preventing unnecessary log errors and improving code efficiency. | 9 |
Improve the error message for unsupported storage typesConsider adding a more specific error message for when neither 'redis' nor 'local'
Suggestion importance[1-10]: 7Why: The suggestion improves the clarity of the error message, making it more specific about the supported storage types. This enhances user understanding and debugging. | 7 | |
| Maintainability |
Refactor storage type validation into a separate functionRefactor the condition to check the storage type to a separate function to improve
Suggestion importance[1-10]: 8Why: Refactoring the storage type validation into a separate function improves code readability and maintainability, making the codebase easier to manage and extend. | 8 |
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code