Skip to content

Commit 6c9edd0

Browse files
authored
Use a system property to enable inference metadata fields (#118876)
1 parent f52a5a7 commit 6c9edd0

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
package org.elasticsearch.index.mapper;
1111

12+
import org.apache.logging.log4j.LogManager;
13+
import org.apache.logging.log4j.Logger;
1214
import org.apache.lucene.search.IndexSearcher;
1315
import org.apache.lucene.search.Query;
1416
import org.apache.lucene.search.join.BitSetProducer;
15-
import org.elasticsearch.common.util.FeatureFlag;
17+
import org.elasticsearch.core.Booleans;
1618
import org.elasticsearch.index.IndexVersion;
1719
import org.elasticsearch.index.IndexVersions;
1820
import org.elasticsearch.index.query.SearchExecutionContext;
@@ -26,7 +28,37 @@
2628
* the field name for removal from _source.
2729
*/
2830
public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper {
29-
public static final FeatureFlag INFERENCE_METADATA_FIELDS_FEATURE_FLAG = new FeatureFlag("inference_metadata_fields");
31+
public static class SystemProperty {
32+
private static final Logger logger = LogManager.getLogger(SystemProperty.class);
33+
34+
private final boolean enabled;
35+
36+
private SystemProperty(String name) {
37+
String propertyName = "es." + name;
38+
this.enabled = parseSystemProperty(propertyName, false);
39+
if (this.enabled) {
40+
logger.info("Feature " + name + " (via system property '" + propertyName + "') is enabled");
41+
} else {
42+
logger.debug("Feature " + name + " (via system property '" + propertyName + "') is disabled");
43+
}
44+
}
45+
46+
private boolean parseSystemProperty(String propertyName, boolean defaultValue) {
47+
final String propertyValue = System.getProperty(propertyName);
48+
logger.trace("System property [{}] is set to [{}]", propertyName, propertyValue);
49+
try {
50+
return Booleans.parseBoolean(propertyValue, defaultValue);
51+
} catch (IllegalArgumentException e) {
52+
throw new IllegalArgumentException("Invalid value [" + propertyValue + "] for system property [" + propertyName + "]", e);
53+
}
54+
}
55+
56+
public boolean isEnabled() {
57+
return enabled;
58+
}
59+
}
60+
61+
public static final SystemProperty INFERENCE_METADATA_FIELDS_SYSTEM_PROPERTY = new SystemProperty("inference_metadata_fields");
3062

3163
public static final String NAME = "_inference_fields";
3264
public static final String CONTENT_TYPE = "_inference_fields";
@@ -61,6 +93,6 @@ public abstract ValueFetcher valueFetcher(
6193
}
6294

6395
public static boolean isEnabled(IndexVersion indexVersion) {
64-
return indexVersion.onOrAfter(IndexVersions.INFERENCE_METADATA_FIELDS) && INFERENCE_METADATA_FIELDS_FEATURE_FLAG.isEnabled();
96+
return indexVersion.onOrAfter(IndexVersions.INFERENCE_METADATA_FIELDS) && INFERENCE_METADATA_FIELDS_SYSTEM_PROPERTY.isEnabled();
6597
}
6698
}

x-pack/plugin/inference/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,17 @@ tasks.named("thirdPartyAudit").configure {
399399
)
400400
}
401401

402+
tasks.named('test') {
403+
if (buildParams.isSnapshotBuild()) {
404+
systemProperty('es.inference_metadata_fields', 'true')
405+
systemProperty('tests.jvm.argline', '-Des.inference_metadata_fields=true')
406+
}
407+
}
408+
402409
tasks.named('yamlRestTest') {
403410
usesDefaultDistribution()
411+
if (buildParams.isSnapshotBuild()) {
412+
systemProperty('tests.jvm.argline', '-Des.inference_metadata_fields=true')
413+
}
404414
}
405415

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.Set;
2323

24-
import static org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper.INFERENCE_METADATA_FIELDS_FEATURE_FLAG;
24+
import static org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper.INFERENCE_METADATA_FIELDS_SYSTEM_PROPERTY;
2525
import static org.elasticsearch.rest.RestRequest.Method.GET;
2626
import static org.elasticsearch.xpack.inference.rest.Paths.INFERENCE_ID;
2727
import static org.elasticsearch.xpack.inference.rest.Paths.INFERENCE_ID_PATH;
@@ -72,7 +72,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
7272
public Set<String> supportedCapabilities() {
7373
Set<String> capabilities = new HashSet<>();
7474
capabilities.add(DEFAULT_ELSER_2_CAPABILITY);
75-
if (INFERENCE_METADATA_FIELDS_FEATURE_FLAG.isEnabled()) {
75+
if (INFERENCE_METADATA_FIELDS_SYSTEM_PROPERTY.isEnabled()) {
7676
capabilities.add(INFERENCE_METADATA_FIELDS_CAPABILITY);
7777
}
7878

0 commit comments

Comments
 (0)