-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Improve EIS authorization to perform requests on a periodic basis instead of only once #123639
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
[ML] Improve EIS authorization to perform requests on a periodic basis instead of only once #123639
Conversation
| @@ -1,288 +0,0 @@ | |||
| /* | |||
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.
We're not revoking anymore so we don't need these tests.
| ); | ||
| } | ||
|
|
||
| private record DefaultModelConfig(Model model, MinimalServiceSettings settings) {} |
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.
Basically moved all this logic to the new ElasticInferenceServiceAuthorizationHandler class.
| return authorizedModels; | ||
| } | ||
|
|
||
| private void handleRevokedDefaultConfigs(Set<String> authorizedDefaultModelIds) { |
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.
This got removed since we're no longer revoking.
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.
@jonathan-buttner I think I was imprecise here and misunderstood how the endpoint configurations work. We still need to be able to revoke default endpoints if we disable EIS for a project. I thought a restart would still give us this behavior, but with periodic tries in place restarts do not do anything special.
I think we need to keep the revokations.
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.
Ah ok! Thanks for clarifying. I'll add the functionality back 👍
| responseString = responseString + " " + useChatCompletionUrlMessage(model); | ||
| } | ||
| listener.onFailure(new ElasticsearchStatusException(responseString, RestStatus.BAD_REQUEST)); | ||
| return; |
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.
Noticed we had a fall through bug that luckily is getting picked up by the if-block below but figured I'd fix it anyway.
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.ElasticsearchWrapperException; |
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.
I would just consider this class completely new and don't even look at the old code when reviewing.
| private synchronized void setAuthorizedContent(ElasticInferenceServiceAuthorizationModel auth) { | ||
| logger.debug("Received authorization response"); | ||
| var authorizedTaskTypesAndModels = authorizedContent.get().taskTypesAndModels.merge(auth) | ||
| .newLimitedToTaskTypes(EnumSet.copyOf(implementedTaskTypes)); |
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.
As a performance improvement we could check if the new authorization response is the same as the previous on and skip the rest of the logic here.
| @@ -0,0 +1,137 @@ | |||
| /* | |||
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.
This is the previous ElasticInferenceServiceAuthorizationHandler class.
| assertThat(limitedAuth, is(ElasticInferenceServiceAuthorizationModel.newDisabledService())); | ||
| } | ||
|
|
||
| public void testMerge_CombinesCorrectly() { |
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.
New merge method tests.
| @@ -0,0 +1,272 @@ | |||
| /* | |||
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.
This was renamed from ElasticInferenceServiceAuthorizationHandlerTests
|
|
||
| package org.elasticsearch.xpack.inference.services.elastic.authorization; | ||
|
|
||
| import org.apache.logging.log4j.Logger; |
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.
Just review this as a totally new file. Ignore the previous code.
|
Pinging @elastic/ml-core (Team:ML) |
| * @param waitTime the max time to wait | ||
| * @throws IllegalStateException if the wait time is exceeded or the call receives an {@link InterruptedException} | ||
| */ | ||
| public void waitForAuthorizationToComplete(TimeValue waitTime) { |
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.
This isn't called anywhere other than tests, right?
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.
Yeah correct, I'll make it package private
| this.threadPool = Objects.requireNonNull(threadPool); | ||
| logger = LogManager.getLogger(ElasticInferenceServiceAuthorizationHandler.class); | ||
| configuration = new AtomicReference<>( | ||
| new ElasticInferenceService.Configuration(authorizedContent.get().taskTypesAndModels.getAuthorizedTaskTypes()) |
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.
Won't this always return and set an empty set? If so, I see it's already in the previous iteration, maybe it's something we fix after this PR?
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.
At this point it'll always be an empty set, but when we get an authorization response back it updates it:
💔 Backport failed
You can use sqren/backport to manually backport by running |
…s instead of only once (elastic#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java
…s instead of only once (elastic#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…s instead of only once (elastic#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java
…ic basis instead of only once (#123639) (#123920) * [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java * Fixing tests
…c basis instead of only once (#123639) (#123918) * [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java * Fixing tests * Fixing task type any test
…c basis instead of only once (#123639) (#123916) * [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit a88d645) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java * Removing getFirst calls
…s instead of only once (elastic#123639) * Refactoring * Add internal cluster setting to aid testing * [CI] Auto commit changes from spotless * Allowing the auth interval to be configurable via a setting * Removing unused code * Adding revocation functionality back --------- Co-authored-by: elasticsearchmachine <[email protected]>
This PR refactors the authorization logic to accomplish a few things:
Testing
I manually tested by spinning up an EIS gateway and ensuring that the authorization requests were received to simulate success. I also tested by modifying the gateway to return an empty response to simulate revoking authorization.