TT-17100: Add core implementation of kv package#135
Conversation
|
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA 0 out of 2 committers have signed the CLA. |
|
This pull request introduces the core implementation of the new Files Changed Analysis
Architecture & Impact Assessment
Component Relationshipsgraph TD
subgraph Application [Application Consumer]
Resolver["kv.Resolver (Stubbed)"] -- Uses --> Registry[kv.registry.Registry]
end
subgraph KV_Package ["KV Package Core (This PR)"]
Registry -- Manages --> SecretStore[store.SecretStore]
SecretStore -- Wraps --> Provider[kv.Provider]
SecretStore -- Uses --> Cache[cache.Cache]
SecretStore -- Uses --> Singleflight[singleflight.Group]
end
subgraph ProviderImplementations ["Provider Implementations (Future)"]
Provider
end
Registry -- Uses Factory to Create --> Provider
Scope Discovery & Context ExpansionThis PR delivers the complete backend logic for the secret management system. The only remaining piece of the core framework is the The logical next steps for this feature are:
Metadata
Powered by Visor from Probelabs Last updated: 2026-05-25T12:40:32.421Z | Triggered by: pr_updated | Commit: 05403cd 💡 TIP: You can chat with Visor using |
Security Issues (3)
Security Issues (3)
Performance Issues (2)
Quality Issues (4)
Powered by Visor from Probelabs Last updated: 2026-05-25T12:39:56.241Z | Triggered by: pr_updated | Commit: 05403cd 💡 TIP: You can chat with Visor using |
|
* feat: add core interfaces * feat: add resolver interface * feat: add registry type with methods * feat: add config types, registry type with empty methods and resolver type and empty methods * feat: add errors and cache surface implementation * feat: update registry and secret store with base impl * feat: add get and set base impl for the cache * feat: update the errors with adding custom types for key not found and store unavailable that would be used by providers * feat: update cache implementation with a set of optimizations * chore: fixing linter errors * fix: move checking for expired keys to the get method with RLock * test: add concurrency test to the cache * chore: clear unused errors * fix: update errors file with linting fixes * feat: add secret store implementation * fix: replace batch approah on cache cleanup with write lock and clean in place to avoid race conditions and make code simpler * feat: update negative caching to avoid storing context errors * feat: update secret store implementation with correct handling of singleflight and add tests validating the logic * test: update store tests with missing edge cases and reworked tests structure to distinguish edge cases * docs: update config docs string * test: add missing tests for cache * refactor: separate logic for ttl selection * refactor: update tests with using parallel and testing context * docs: add docs to cache get method * refactor: split single package solution to multiple to apply better structure and readability * refactor: use t.Context() instead of background as we have >1.24 Go * feat: rework secret store to make it fit a Provider interface with Unwrap() method and unwrap helpers * refactor: move errors to kv package * fix: update the cache clenup interval to min ttl to avoid casees when ttl is set as too high to rely on * fix: updat foreground fetch with removing handling canceled context because it can be only timed out * feat: rework foreground fetch for secret to avoid blocking request goroutines until they're timeout * feat: rework cache cleanup with separate locks and adding condition to check if its expired between locks * chore: return errro value instead of nil for background fetch * test: update store tests with wrapping them with synctest * refactor: use wg.Go() instead of legacy pattern * refactor: move config to kv package * build: add test-kv to make sonarqube to get corrent coverage * refactor: decrease cognitive complexity for NewCache func * fix: return error intead of loggin * fix: add generic error if the provider returns a non-string which is unreal * fix: pass value instead of whole result type to error * docs: add comment explaining the logic behind a test * chore: make generic error less descriptive * chore: replace fmt.sprintf with string concat * feat: add close methods * feat: add conditions to avoid calling Get methods on secret store and avoid store or return value if its closed * feat: cleanup the cache entries when its closed * fix: add mu locks to the cache close method and tests * feat: add provider timeout enforcement * feat: add separate singleflight group to avoid name collision between foreground and background tasks * fix: add handling of empty ttl field on cache config * TT-17239: Imlement registry (#138) * feat: add implementation for Add and InitStores methods * feat: update init stores with secret store wrapper * feat: add close imlementation to registry * feat: add logger * feat: add initial registry impl * fix: update init stores logic with clearing defer and redundant mutex locks * test: update registry test for close method and init stores edge case * test: update concurrency test * refactor: update registry tests with changing structure * chore: update kv config name * test: add more tests for init stores func * test: add more tests covering edge cases * refactor: smash two defers to one as they reference similar condition * feat: rework Close method to run closing concurrently * feat: add provider type with constants to make code more documented and understandable * chore: update comment * test: add tests covering concurrent logic when close is called while init stores are running * chore: replace literals with constants on condition * feat: update return err logic to avoid redundant assigning with explanatory docs * test: add test to check circular dependency to avoid stack-overflow if self referencing * chore: replace dependency * refactor: simplify logic with isInitialize * refactor: add private func with init a single store to avoid boilerplate code * revert: isInitialized should be used with swap to prevent concurrent requests to initiStores * refactor: update init stores func * refactor: update init stores with detached func * feat: add direct provider interface to fixing open-closed principle * fix: typo * feat: update registry logic with using standalone and timeouter interfaces * feat: rework init stores and make it fully concurrent * chore: remove check for empty stores * chore: add t.Parallel() to tests * fix: distinguish init context with lifetime context and remove dependency between cache context cancelation and init ctx * fix: minor adjustments and comment clean-up --------- Co-authored-by: Vlad Zabolotnyi <vlad.z@tyk.io> --------- Co-authored-by: Vlad Zabolotnyi <vlad.z@tyk.io>
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
|



Description
The tickets below are the part of current change. Every PR was merged after review.
https://tyktech.atlassian.net/browse/TT-17100
https://tyktech.atlassian.net/browse/TT-17238
https://tyktech.atlassian.net/browse/TT-17239
Related Issue
Motivation and Context
Test Coverage For This Change
Screenshots (if appropriate)
Types of changes
Checklist
master!masterbranch (left side). Also, it would be best if you started your change off our latestmaster.go mod tidy && go mod vendorgofmt -s -w .go vet ./...Ticket Details
TT-17100
Generated at: 2026-05-25 12:40:11