Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public void init(Client client) {
}

public void onNodeStarted() {
services.values().forEach(InferenceService::onNodeStarted);
for (var service : services.values()) {
try {
service.onNodeStarted();
} catch (Exception e) {
// ignore
}
}
}

public Map<String, InferenceService> getServices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class BaseMockEISAuthServerTest extends ESRestTestCase {
.setting("xpack.security.enabled", "true")
// Adding both settings unless one feature flag is disabled in a particular environment
.setting("xpack.inference.elastic.url", mockEISServer::getUrl)
// If we don't disable this there's a very small chance that the authorization code could attempt to make two
// calls which would result in a test failure because the webserver is only expecting a single request
// So to ensure we avoid that all together, this flag indicates that we'll only perform a single authorization request
.setting("xpack.inference.elastic.periodic_authorization_enabled", "false")
// This plugin is located in the inference/qa/test-service-plugin package, look for TestInferenceServicePlugin
.plugin("inference-service-test")
.user("x_pack_rest_user", "x-pack-test-password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.elasticsearch.xpack.inference.logging.ThrottlerManager;
import org.elasticsearch.xpack.inference.registry.ModelRegistry;
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService;
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceComponents;
import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationHandler;
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceSettingsTests;
import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationRequestHandler;
import org.junit.After;
import org.junit.Before;

Expand Down Expand Up @@ -262,7 +262,7 @@ public void testRemoves_DefaultChatCompletion_V1_WhenAuthorizationDoesNotReturnA

private void ensureAuthorizationCallFinished(ElasticInferenceService service) {
service.onNodeStarted();
service.waitForAuthorizationToComplete(TIMEOUT);
service.waitForFirstAuthorizationToComplete(TIMEOUT);
}

private ElasticInferenceService createElasticInferenceService() {
Expand All @@ -272,9 +272,9 @@ private ElasticInferenceService createElasticInferenceService() {
return new ElasticInferenceService(
senderFactory,
createWithEmptySettings(threadPool),
ElasticInferenceServiceComponents.withNoRevokeDelay(gatewayUrl),
ElasticInferenceServiceSettingsTests.create(gatewayUrl),
modelRegistry,
new ElasticInferenceServiceAuthorizationHandler(gatewayUrl, threadPool)
new ElasticInferenceServiceAuthorizationRequestHandler(gatewayUrl, threadPool)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService;
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceComponents;
import org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceServiceSettings;
import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationHandler;
import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationRequestHandler;
import org.elasticsearch.xpack.inference.services.elasticsearch.ElasticsearchInternalService;
import org.elasticsearch.xpack.inference.services.googleaistudio.GoogleAiStudioService;
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiService;
Expand Down Expand Up @@ -273,14 +273,11 @@ public Collection<?> createComponents(PluginServices services) {
);
elasicInferenceServiceFactory.set(elasticInferenceServiceRequestSenderFactory);

ElasticInferenceServiceSettings inferenceServiceSettings = new ElasticInferenceServiceSettings(settings);
String elasticInferenceUrl = inferenceServiceSettings.getElasticInferenceServiceUrl();
var inferenceServiceSettings = new ElasticInferenceServiceSettings(settings);
inferenceServiceSettings.init(services.clusterService());

var elasticInferenceServiceComponentsInstance = ElasticInferenceServiceComponents.withDefaultRevokeDelay(elasticInferenceUrl);
elasticInferenceServiceComponents.set(elasticInferenceServiceComponentsInstance);

var authorizationHandler = new ElasticInferenceServiceAuthorizationHandler(
elasticInferenceServiceComponentsInstance.elasticInferenceServiceUrl(),
var authorizationHandler = new ElasticInferenceServiceAuthorizationRequestHandler(
inferenceServiceSettings.getElasticInferenceServiceUrl(),
services.threadPool()
);

Expand All @@ -289,7 +286,7 @@ public Collection<?> createComponents(PluginServices services) {
context -> new ElasticInferenceService(
elasicInferenceServiceFactory.get(),
serviceComponents.get(),
elasticInferenceServiceComponentsInstance,
inferenceServiceSettings,
modelRegistry,
authorizationHandler
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,20 @@ public boolean containsDefaultConfigId(String inferenceEntityId) {
return defaultConfigIds.containsKey(inferenceEntityId);
}

/**
* Adds the default configuration information if it does not already exist internally.
* @param defaultConfigId the default endpoint information
*/
public synchronized void putDefaultIdIfAbsent(InferenceService.DefaultConfigId defaultConfigId) {
defaultConfigIds.putIfAbsent(defaultConfigId.inferenceId(), defaultConfigId);
}

/**
* Set the default inference ids provided by the services
* @param defaultConfigId The default
* @param defaultConfigId The default endpoint information
* @throws IllegalStateException if the {@link InferenceService.DefaultConfigId#inferenceId()} already exists internally
*/
public synchronized void addDefaultIds(InferenceService.DefaultConfigId defaultConfigId) {
public synchronized void addDefaultIds(InferenceService.DefaultConfigId defaultConfigId) throws IllegalStateException {
var config = defaultConfigIds.get(defaultConfigId.inferenceId());
if (config != null) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.inference.services.elastic;

import org.elasticsearch.inference.MinimalServiceSettings;
import org.elasticsearch.inference.Model;

public record DefaultModelConfig(Model model, MinimalServiceSettings settings) {

}
Loading