fix: use O(n) map lookups to associate credentials with consumers#7889
Open
Abhicodeitout wants to merge 1 commit intoKong:mainfrom
Open
fix: use O(n) map lookups to associate credentials with consumers#7889Abhicodeitout wants to merge 1 commit intoKong:mainfrom
Abhicodeitout wants to merge 1 commit intoKong:mainfrom
Conversation
KongRawStateToKongState previously used O(n²) nested loops to match
credential records to their consumers. With large consumer counts
(e.g. 6,912 KongConsumers each with a JWT credential) this produced
~48M comparisons and caused the last-valid-config fallback to time out,
resulting in an empty/partial config being pushed to Kong and causing
JWT auth failures ('401 Invalid Signature').
Fix by pre-building consumer-ID-keyed maps for all 7 credential types
before the consumer loop, then replacing the inner scans with O(1)
map lookups.
Fixes Kong#7128
Signed-off-by: Abhishek Kumar Kushwaha <abhithegabbar@gmail.com>
Author
|
@subicura i need review |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7889 +/- ##
========================================
- Coverage 78.5% 58.6% -19.9%
========================================
Files 222 222
Lines 20791 20801 +10
========================================
- Hits 16323 12204 -4119
- Misses 3433 7890 +4457
+ Partials 1035 707 -328 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KongRawStateToKongState previously used O(n²) nested loops to match credential records to their consumers. With large consumer counts (e.g. 6,912 KongConsumers each with a JWT credential) this produced ~48M comparisons and caused the last-valid-config fallback to time out, resulting in an empty/partial config being pushed to Kong and causing JWT auth failures ('401 Invalid Signature').
Fix by pre-building consumer-ID-keyed maps for all 7 credential types before the consumer loop, then replacing the inner scans with O(1) map lookups.
Fixes #7128
What this PR does / why we need it
This PR eliminates a critical performance bottleneck in the Kong configuration reconciliation pipeline. The
KongRawStateToKongStatefunction is responsible for converting raw Kong state (from the Kong Admin API) to the internal KongState representation used by the KIC.In deployments with thousands of consumers and credentials, the previous O(n²) algorithm caused:
The fix maintains backward compatibility while dramatically improving performance by:
Which issue this PR fixes
Fixes #7128 - Configuration reconciliation timeouts causing JWT auth failures in large-scale deployments
Special notes for your reviewer
Performance Impact:
Testing:
TestKongRawStateToKongStatevalidates credential association correctness)Implementation Details:
sanitizeAuth()calls remain in the pre-building phase as originally designedKongRawStateToKongStatePR Readiness Checklist
Complete these before marking the PR as
ready to review:CHANGELOG.mdrelease notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR