Skip to content

Commit 8ccfb22

Browse files
authored
Revert "[EIS] Validate EIS Gateway URL if set (#114600)" (#114867)
This reverts commit 39168e1.
1 parent 69054ac commit 8ccfb22

File tree

5 files changed

+3
-152
lines changed

5 files changed

+3
-152
lines changed

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

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,14 @@
77

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

10-
import org.apache.logging.log4j.LogManager;
11-
import org.apache.logging.log4j.Logger;
1210
import org.elasticsearch.common.settings.Setting;
1311
import org.elasticsearch.common.settings.Settings;
1412

15-
import java.net.URI;
16-
import java.net.URISyntaxException;
1713
import java.util.List;
18-
import java.util.Objects;
19-
import java.util.Set;
2014

21-
/**
22-
* Class encapsulating any global setting for the EIS integration.
23-
*/
2415
public class ElasticInferenceServiceSettings {
2516

26-
public static final Setting<String> EIS_GATEWAY_URL = Setting.simpleString(
27-
"xpack.inference.eis.gateway.url",
28-
new EisGatewayURLValidator(),
29-
Setting.Property.NodeScope
30-
);
31-
32-
private static final Logger log = LogManager.getLogger(ElasticInferenceServiceSettings.class);
33-
34-
/**
35-
* Class to validate the EIS Gateway url set via `xpack.inference.eis.gateway.url`.
36-
*/
37-
public static class EisGatewayURLValidator implements Setting.Validator<String> {
38-
39-
private static final Set<String> VALID_EIS_GATEWAY_SCHEMES = Set.of("http", "https");
40-
41-
@Override
42-
public void validate(String value) {
43-
if (Objects.isNull(value) || value.isEmpty()) {
44-
// No validation needed, if eis-gateway URL is not set
45-
log.debug("eis-gateway url not set. Skipping validation");
46-
return;
47-
}
48-
49-
try {
50-
var uri = new URI(value);
51-
var scheme = uri.getScheme();
52-
53-
if (scheme == null || VALID_EIS_GATEWAY_SCHEMES.contains(scheme) == false) {
54-
throw new IllegalArgumentException(
55-
"["
56-
+ scheme
57-
+ "] is not a valid URI scheme for the setting ["
58-
+ ElasticInferenceServiceSettings.EIS_GATEWAY_URL.getKey()
59-
+ "]. Use one of ["
60-
+ String.join(",", VALID_EIS_GATEWAY_SCHEMES)
61-
+ "]"
62-
);
63-
}
64-
} catch (URISyntaxException e) {
65-
throw new IllegalArgumentException("[" + e.getInput() + "] is not a valid URI", e);
66-
}
67-
}
68-
}
17+
static final Setting<String> EIS_GATEWAY_URL = Setting.simpleString("xpack.inference.eis.gateway.url", Setting.Property.NodeScope);
6918

7019
// Adjust this variable to be volatile, if the setting can be updated at some point in time
7120
private final String eisGatewayUrl;

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ private URI createUri() throws URISyntaxException {
108108
default -> throw new IllegalArgumentException("Unsupported model for EIS [" + modelId + "]");
109109
}
110110

111-
var uriString = elasticInferenceServiceComponents().eisGatewayUrl() + "/sparse-text-embedding/" + modelIdUriPath;
112-
113-
// We perform the same validation here as when reading the setting to make sure that our extended URI is still valid
114-
// This method throws, if the URI is invalid
115-
new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate(uriString);
116-
117-
return new URI(uriString);
111+
return new URI(elasticInferenceServiceComponents().eisGatewayUrl() + "/sparse-text-embedding/" + modelIdUriPath);
118112
}
119113
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceSettingsTests.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceSparseEmbeddingsModelTests.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,6 @@
1515

1616
public class ElasticInferenceServiceSparseEmbeddingsModelTests extends ESTestCase {
1717

18-
public void testCreateURI_ThrowError_OnMissingURIScheme() {
19-
expectThrows(IllegalArgumentException.class, () -> createModel("www.missing-scheme-gateway-url.com"));
20-
}
21-
22-
public void testCreateURI_ThrowError_OnWrongURIScheme() {
23-
expectThrows(IllegalArgumentException.class, () -> createModel("file://www.missing-scheme-gateway-url.com"));
24-
}
25-
26-
public void testCreateURI_DoesNotThrowError_ForHTTP() {
27-
var scheme = "http";
28-
29-
try {
30-
createModel(scheme + "://www.valid-gateway-url.com");
31-
} catch (Exception e) {
32-
fail(e, "Should not throw exception for " + "[" + scheme + "]");
33-
}
34-
}
35-
36-
public void testCreateURI_DoesNotThrowError_ForHTTPS() {
37-
var scheme = "https";
38-
39-
try {
40-
createModel(scheme + "://www.valid-gateway-url.com");
41-
} catch (Exception e) {
42-
fail(e, "Should not throw exception for " + "[" + scheme + "]");
43-
}
44-
}
45-
4618
public static ElasticInferenceServiceSparseEmbeddingsModel createModel(String url) {
4719
return createModel(url, null);
4820
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ private ElasticInferenceService createServiceWithMockSender() {
492492
return new ElasticInferenceService(
493493
mock(HttpRequestSender.Factory.class),
494494
createWithEmptySettings(threadPool),
495-
new ElasticInferenceServiceComponents("http://valid-eis-gateway-url.com")
495+
new ElasticInferenceServiceComponents(null)
496496
);
497497
}
498498
}

0 commit comments

Comments
 (0)