Skip to content

Commit 84c16ce

Browse files
Adding feature flag
1 parent da1c71f commit 84c16ce

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public enum FeatureFlag {
1919
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
2020
SUB_OBJECTS_AUTO_ENABLED("es.sub_objects_auto_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
2121
DOC_VALUES_SKIPPER("es.doc_values_skipper_feature_flag_enabled=true", Version.fromString("8.18.1"), null),
22-
USE_LUCENE101_POSTINGS_FORMAT("es.use_lucene101_postings_format_feature_flag_enabled=true", Version.fromString("9.1.0"), null);
22+
USE_LUCENE101_POSTINGS_FORMAT("es.use_lucene101_postings_format_feature_flag_enabled=true", Version.fromString("9.1.0"), null),
23+
INFERENCE_CUSTOM_SERVICE_ENABLED("es.inference_custom_service_feature_flag_enabled=true", Version.fromString("8.19.0"), null);
2324

2425
public final String systemProperty;
2526
public final Version from;

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/BaseMockEISAuthServerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.core.TimeValue;
1616
import org.elasticsearch.test.cluster.ElasticsearchCluster;
17+
import org.elasticsearch.test.cluster.FeatureFlag;
1718
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1819
import org.elasticsearch.test.rest.ESRestTestCase;
1920
import org.junit.ClassRule;
@@ -46,6 +47,7 @@ public class BaseMockEISAuthServerTest extends ESRestTestCase {
4647
// This plugin is located in the inference/qa/test-service-plugin package, look for TestInferenceServicePlugin
4748
.plugin("inference-service-test")
4849
.user("x_pack_rest_user", "x-pack-test-password")
50+
.feature(FeatureFlag.INFERENCE_CUSTOM_SERVICE_ENABLED)
4951
.build();
5052

5153
// The reason we're doing this is to make sure the mock server is initialized first so we can get the address before communicating

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceBaseRestTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.core.Nullable;
2121
import org.elasticsearch.inference.TaskType;
2222
import org.elasticsearch.test.cluster.ElasticsearchCluster;
23+
import org.elasticsearch.test.cluster.FeatureFlag;
2324
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2425
import org.elasticsearch.test.rest.ESRestTestCase;
2526
import org.elasticsearch.xcontent.XContentBuilder;
@@ -50,6 +51,7 @@ public class InferenceBaseRestTest extends ESRestTestCase {
5051
.setting("xpack.security.enabled", "true")
5152
.plugin("inference-service-test")
5253
.user("x_pack_rest_user", "x-pack-test-password")
54+
.feature(FeatureFlag.INFERENCE_CUSTOM_SERVICE_ENABLED)
5355
.build();
5456

5557
@ClassRule
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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;
9+
10+
import org.elasticsearch.common.util.FeatureFlag;
11+
12+
public class CustomServiceFeatureFlag {
13+
/**
14+
* {@link org.elasticsearch.xpack.inference.services.custom.CustomService} feature flag. When the feature is complete,
15+
* this flag will be removed.
16+
* Enable feature via JVM option: `-Des.inference_custom_service_feature_flag_enabled=true`.
17+
*/
18+
public static final FeatureFlag CUSTOM_SERVICE_FEATURE_FLAG = new FeatureFlag("inference_custom_service");
19+
20+
private CustomServiceFeatureFlag() {}
21+
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferenceNamedWriteablesProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
import java.util.ArrayList;
115115
import java.util.List;
116116

117+
import static org.elasticsearch.xpack.inference.CustomServiceFeatureFlag.CUSTOM_SERVICE_FEATURE_FLAG;
118+
117119
public class InferenceNamedWriteablesProvider {
118120

119121
private InferenceNamedWriteablesProvider() {}
@@ -177,6 +179,10 @@ public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
177179
}
178180

179181
private static void addCustomNamedWriteables(List<NamedWriteableRegistry.Entry> namedWriteables) {
182+
if (CUSTOM_SERVICE_FEATURE_FLAG.isEnabled() == false) {
183+
return;
184+
}
185+
180186
namedWriteables.add(
181187
new NamedWriteableRegistry.Entry(ServiceSettings.class, CustomServiceSettings.NAME, CustomServiceSettings::new)
182188
);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@
149149
import java.util.Set;
150150
import java.util.function.Predicate;
151151
import java.util.function.Supplier;
152+
import java.util.stream.Stream;
152153

153154
import static java.util.Collections.singletonList;
155+
import static org.elasticsearch.xpack.inference.CustomServiceFeatureFlag.CUSTOM_SERVICE_FEATURE_FLAG;
154156
import static org.elasticsearch.xpack.inference.action.filter.ShardBulkInferenceActionFilter.INDICES_INFERENCE_BATCH_SIZE;
155157
import static org.elasticsearch.xpack.inference.common.InferenceAPIClusterAwareRateLimitingFeature.INFERENCE_API_CLUSTER_AWARE_RATE_LIMITING_FEATURE_FLAG;
156158

@@ -380,7 +382,11 @@ public void loadExtensions(ExtensionLoader loader) {
380382
}
381383

382384
public List<InferenceServiceExtension.Factory> getInferenceServiceFactories() {
383-
return List.of(
385+
List<InferenceServiceExtension.Factory> conditionalServices = CUSTOM_SERVICE_FEATURE_FLAG.isEnabled()
386+
? List.of(context -> new CustomService(httpFactory.get(), serviceComponents.get()))
387+
: List.of();
388+
389+
List<InferenceServiceExtension.Factory> availableServices = List.of(
384390
context -> new HuggingFaceElserService(httpFactory.get(), serviceComponents.get()),
385391
context -> new HuggingFaceService(httpFactory.get(), serviceComponents.get()),
386392
context -> new OpenAiService(httpFactory.get(), serviceComponents.get()),
@@ -397,9 +403,11 @@ public List<InferenceServiceExtension.Factory> getInferenceServiceFactories() {
397403
context -> new JinaAIService(httpFactory.get(), serviceComponents.get()),
398404
context -> new VoyageAIService(httpFactory.get(), serviceComponents.get()),
399405
context -> new DeepSeekService(httpFactory.get(), serviceComponents.get()),
400-
context -> new CustomService(httpFactory.get(), serviceComponents.get()),
401406
ElasticsearchInternalService::new
402407
);
408+
409+
return Stream.concat(availableServices.stream(), conditionalServices.stream())
410+
.toList();
403411
}
404412

405413
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public static void throwIfNotEmptyMap(Map<String, Object> settingsMap, String fi
206206
public static ElasticsearchStatusException unknownSettingsError(Map<String, Object> config, String serviceName) {
207207
// TODO map as JSON
208208
return new ElasticsearchStatusException(
209-
"Model configuration contains settings [{}] unknown to the [{}] service",
209+
"Configuration contains settings [{}] unknown to the [{}] service",
210210
RestStatus.BAD_REQUEST,
211211
config,
212212
serviceName
@@ -215,7 +215,7 @@ public static ElasticsearchStatusException unknownSettingsError(Map<String, Obje
215215

216216
public static ElasticsearchStatusException unknownSettingsError(Map<String, Object> config, String field, String scope) {
217217
return new ElasticsearchStatusException(
218-
"Model configuration contains unknown settings [{}] while parsing field [{}] for settings [{}]",
218+
"Configuration contains unknown settings [{}] while parsing field [{}] for settings [{}]",
219219
RestStatus.BAD_REQUEST,
220220
config,
221221
field,

0 commit comments

Comments
 (0)