[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.
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.
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.
This got removed since we're no longer revoking.
There was a problem hiding this comment.
@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.
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.
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.
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.
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.
This is the previous ElasticInferenceServiceAuthorizationHandler class.
| assertThat(limitedAuth, is(ElasticInferenceServiceAuthorizationModel.newDisabledService())); | ||
| } | ||
|
|
||
| public void testMerge_CombinesCorrectly() { |
There was a problem hiding this comment.
New merge method tests.
| @@ -0,0 +1,272 @@ | |||
| /* | |||
There was a problem hiding this comment.
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.
Just review this as a totally new file. Ignore the previous code.
|
Pinging @elastic/ml-core (Team:ML) |
| @@ -307,32 +167,22 @@ public void onNodeStarted() { | |||
| * @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.
This isn't called anywhere other than tests, right?
There was a problem hiding this comment.
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.
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.
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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co> (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 <infra-root+elasticsearchmachine@elastic.co>
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.