-
Notifications
You must be signed in to change notification settings - Fork 250
CredentialsProvider optimized lookup by id
#1003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces optimized credential lookup methods to address performance issues when searching for credentials by ID, particularly when using remote vault providers like HashiCorp Vault. The optimization allows providers to implement direct ID-based lookups instead of retrieving all credentials and filtering, enabling early termination when a matching credential is found.
Key changes:
- Added new static lookup methods
findCredentialByIdInItemGroupandfindCredentialByIdInItemthat search providers sequentially and return on first match - Added overridable provider-level methods
getCredentialByIdInItemGroupandgetCredentialByIdInItemwith default implementations that fall back to existing list-based methods - Refactored
findCredentialById(Run)to use the new optimized lookup methods
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java | Added optimized credential lookup infrastructure with four new methods (two static, two instance) and refactored existing findCredentialById to use new optimized paths; added debug logging for lookup operations |
| src/main/java/com/cloudbees/plugins/credentials/CredentialsMatchers.java | Added cross-references to new lookup methods in the javadoc for withId matcher |
| src/test/java/com/cloudbees/plugins/credentials/ByIdTest.java | Added comprehensive test suite with test providers to verify lazy evaluation behavior and optimization effectiveness |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java
Show resolved
Hide resolved
src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java
Show resolved
Hide resolved
src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java
Show resolved
Hide resolved
src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java
Show resolved
Hide resolved
| static void addCredential(IdCredentials credential) { | ||
| credentials.add(credential); | ||
| } | ||
|
|
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static credential lists in LazyProvider2 and LazyProvider3 are never cleared between tests, which could lead to test interference. Consider adding methods to clear these credentials and calling them in a setup or teardown method (e.g., @beforeeach or @AfterEach) to ensure test isolation.
| static void clearCredentials() { | |
| credentials.clear(); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(should avoid static fields, use lookupSingleton and instance fields)
| private static final List<IdCredentials> credentials = new java.util.concurrent.CopyOnWriteArrayList<>(); | ||
| static final AtomicInteger listCalls = new AtomicInteger(0); | ||
|
|
||
| static void addCredential(IdCredentials credential) { | ||
| credentials.add(credential); | ||
| } |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static credential list in LazyProvider3 is never cleared between tests, which could lead to test interference. Consider adding a method to clear these credentials and calling it in a setup or teardown method (e.g., @beforeeach or @AfterEach) to ensure test isolation.
The basis of #980 (a full fix will require some downstream changes).
Prior cleanup: #1001.