Skip to content

Commit b394050

Browse files
authored
[Inference API] Put back legacy EIS URL setting (#121207) (#121239)
* Put back legacy EIS URL setting * Update docs/changelog/121207.yaml * Fallback logic to legacy URL * Add unit tests
1 parent 258013a commit b394050

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

docs/changelog/121207.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121207
2+
summary: "[Inference API] Put back legacy EIS URL setting"
3+
area: Inference
4+
type: bug
5+
issues: []

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceSettings.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

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

10+
import org.elasticsearch.common.Strings;
1011
import org.elasticsearch.common.settings.Setting;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.xpack.core.ssl.SSLConfigurationSettings;
@@ -22,14 +23,21 @@ public class ElasticInferenceServiceSettings {
2223

2324
public static final String ELASTIC_INFERENCE_SERVICE_SSL_CONFIGURATION_PREFIX = "xpack.inference.elastic.http.ssl.";
2425

26+
@Deprecated
27+
static final Setting<String> EIS_GATEWAY_URL = Setting.simpleString("xpack.inference.eis.gateway.url", Setting.Property.NodeScope);
28+
2529
static final Setting<String> ELASTIC_INFERENCE_SERVICE_URL = Setting.simpleString(
2630
"xpack.inference.elastic.url",
2731
Setting.Property.NodeScope
2832
);
2933

34+
@Deprecated
35+
private final String eisGatewayUrl;
36+
3037
private final String elasticInferenceServiceUrl;
3138

3239
public ElasticInferenceServiceSettings(Settings settings) {
40+
eisGatewayUrl = EIS_GATEWAY_URL.get(settings);
3341
elasticInferenceServiceUrl = ELASTIC_INFERENCE_SERVICE_URL.get(settings);
3442
}
3543

@@ -46,6 +54,7 @@ public ElasticInferenceServiceSettings(Settings settings) {
4654

4755
public static List<Setting<?>> getSettingsDefinitions() {
4856
ArrayList<Setting<?>> settings = new ArrayList<>();
57+
settings.add(EIS_GATEWAY_URL);
4958
settings.add(ELASTIC_INFERENCE_SERVICE_URL);
5059
settings.add(ELASTIC_INFERENCE_SERVICE_SSL_ENABLED);
5160
settings.addAll(ELASTIC_INFERENCE_SERVICE_SSL_CONFIGURATION_SETTINGS.getEnabledSettings());
@@ -54,7 +63,7 @@ public static List<Setting<?>> getSettingsDefinitions() {
5463
}
5564

5665
public String getElasticInferenceServiceUrl() {
57-
return elasticInferenceServiceUrl;
66+
return Strings.isEmpty(elasticInferenceServiceUrl) ? eisGatewayUrl : elasticInferenceServiceUrl;
5867
}
5968

6069
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.elastic;
9+
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.test.ESTestCase;
12+
13+
import static org.hamcrest.Matchers.equalTo;
14+
15+
public class ElasticInferenceServiceSettingsTests extends ESTestCase {
16+
17+
private static final String ELASTIC_INFERENCE_SERVICE_URL = "http://elastic-inference-service";
18+
private static final String ELASTIC_INFERENCE_SERVICE_LEGACY_URL = "http://elastic-inference-service-legacy";
19+
20+
public void testGetElasticInferenceServiceUrl_WithUrlSetting() {
21+
var settings = Settings.builder()
22+
.put(ElasticInferenceServiceSettings.ELASTIC_INFERENCE_SERVICE_URL.getKey(), ELASTIC_INFERENCE_SERVICE_URL)
23+
.build();
24+
25+
var eisSettings = new ElasticInferenceServiceSettings(settings);
26+
27+
assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_URL));
28+
}
29+
30+
public void testGetElasticInferenceServiceUrl_WithLegacyUrlSetting() {
31+
var settings = Settings.builder()
32+
.put(ElasticInferenceServiceSettings.EIS_GATEWAY_URL.getKey(), ELASTIC_INFERENCE_SERVICE_LEGACY_URL)
33+
.build();
34+
35+
var eisSettings = new ElasticInferenceServiceSettings(settings);
36+
37+
assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_LEGACY_URL));
38+
}
39+
40+
public void testGetElasticInferenceServiceUrl_WithUrlSetting_TakesPrecedenceOverLegacyUrlSetting() {
41+
var settings = Settings.builder()
42+
.put(ElasticInferenceServiceSettings.EIS_GATEWAY_URL.getKey(), ELASTIC_INFERENCE_SERVICE_LEGACY_URL)
43+
.put(ElasticInferenceServiceSettings.ELASTIC_INFERENCE_SERVICE_URL.getKey(), ELASTIC_INFERENCE_SERVICE_URL)
44+
.build();
45+
46+
var eisSettings = new ElasticInferenceServiceSettings(settings);
47+
48+
assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(ELASTIC_INFERENCE_SERVICE_URL));
49+
}
50+
51+
public void testGetElasticInferenceServiceUrl_WithoutUrlSetting() {
52+
var eisSettings = new ElasticInferenceServiceSettings(Settings.EMPTY);
53+
54+
assertThat(eisSettings.getElasticInferenceServiceUrl(), equalTo(""));
55+
}
56+
57+
}

0 commit comments

Comments
 (0)