Skip to content
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 @@ -270,7 +270,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 @@ -280,9 +280,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 @@ -274,14 +274,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 @@ -290,7 +287,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
@@ -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