diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java index 2c313da69b42e..49fb38b518dce 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java @@ -16,7 +16,6 @@ */ public enum FeatureFlag { TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null), - LEARNING_TO_RANK("es.learning_to_rank_feature_flag_enabled=true", Version.fromString("8.12.0"), null), FAILURE_STORE_ENABLED("es.failure_store_feature_flag_enabled=true", Version.fromString("8.12.0"), null); public final String systemProperty; diff --git a/x-pack/plugin/ml/qa/basic-multi-node/build.gradle b/x-pack/plugin/ml/qa/basic-multi-node/build.gradle index 3f2f85e3e09da..b71c4a5de3dca 100644 --- a/x-pack/plugin/ml/qa/basic-multi-node/build.gradle +++ b/x-pack/plugin/ml/qa/basic-multi-node/build.gradle @@ -1,4 +1,3 @@ -import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.internal.info.BuildParams apply plugin: 'elasticsearch.legacy-java-rest-test' @@ -17,7 +16,7 @@ testClusters.configureEach { setting 'xpack.license.self_generated.type', 'trial' setting 'indices.lifecycle.history_index_enabled', 'false' setting 'slm.history_index_enabled', 'false' - requiresFeature 'es.learning_to_rank_feature_flag_enabled', Version.fromString("8.12.0") + setting 'xpack.ml.learning_to_rank.enabled', 'true' } if (BuildParams.inFipsJvm){ diff --git a/x-pack/plugin/ml/qa/ml-with-security/build.gradle b/x-pack/plugin/ml/qa/ml-with-security/build.gradle index df2eb2c687fb5..270f29ff714a9 100644 --- a/x-pack/plugin/ml/qa/ml-with-security/build.gradle +++ b/x-pack/plugin/ml/qa/ml-with-security/build.gradle @@ -1,4 +1,3 @@ -import org.elasticsearch.gradle.Version apply plugin: 'elasticsearch.legacy-yaml-rest-test' dependencies { @@ -258,5 +257,5 @@ testClusters.configureEach { user username: "no_ml", password: "x-pack-test-password", role: "minimal" setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.security.enabled', 'true' - requiresFeature 'es.learning_to_rank_feature_flag_enabled', Version.fromString("8.12.0") + setting 'xpack.ml.learning_to_rank.enabled', 'true' } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 1031d45facf85..1e9f975456c57 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -327,7 +327,6 @@ import org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor; import org.elasticsearch.xpack.ml.inference.loadingservice.ModelLoadingService; import org.elasticsearch.xpack.ml.inference.ltr.LearningToRankRescorerBuilder; -import org.elasticsearch.xpack.ml.inference.ltr.LearningToRankRescorerFeature; import org.elasticsearch.xpack.ml.inference.ltr.LearningToRankService; import org.elasticsearch.xpack.ml.inference.modelsize.MlModelSizeNamedXContentProvider; import org.elasticsearch.xpack.ml.inference.persistence.TrainedModelProvider; @@ -890,7 +889,7 @@ private static void reportClashingNodeAttribute(String attrName) { @Override public List> getRescorers() { - if (enabled && LearningToRankRescorerFeature.isEnabled()) { + if (enabled && learningToRankService.get().isEnabled()) { return List.of( new RescorerSpec<>( LearningToRankRescorerBuilder.NAME, @@ -1125,7 +1124,7 @@ public Collection createComponents(PluginServices services) { this.modelLoadingService.set(modelLoadingService); this.learningToRankService.set( - new LearningToRankService(modelLoadingService, trainedModelProvider, services.scriptService(), services.xContentRegistry()) + new LearningToRankService(modelLoadingService, trainedModelProvider, services.scriptService(), services.xContentRegistry(), settings) ); this.deploymentManager.set( @@ -1801,7 +1800,7 @@ public List getNamedXContent() { ); namedXContent.addAll(new CorrelationNamedContentProvider().getNamedXContentParsers()); // LTR Combine with Inference named content provider when feature flag is removed - if (LearningToRankRescorerFeature.isEnabled()) { + if (learningToRankService.get().isEnabled()) { namedXContent.addAll(new MlLTRNamedXContentProvider().getNamedXContentParsers()); } return namedXContent; @@ -1889,7 +1888,7 @@ public List getNamedWriteables() { namedWriteables.addAll(new CorrelationNamedContentProvider().getNamedWriteables()); namedWriteables.addAll(new ChangePointNamedContentProvider().getNamedWriteables()); // LTR Combine with Inference named content provider when feature flag is removed - if (LearningToRankRescorerFeature.isEnabled()) { + if (learningToRankService.get().isEnabled()) { namedWriteables.addAll(new MlLTRNamedXContentProvider().getNamedWriteables()); } return namedWriteables; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankRescorerFeature.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankRescorerFeature.java deleted file mode 100644 index 42598691beec2..0000000000000 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankRescorerFeature.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.ml.inference.ltr; - -import org.elasticsearch.common.util.FeatureFlag; - -/** - * Learning to rank feature flag. When the feature is complete, this flag will be removed. - * - * Upon removal, ensure transport serialization is all corrected for future BWC. - * - * See {@link LearningToRankRescorerBuilder} - */ -public class LearningToRankRescorerFeature { - - private LearningToRankRescorerFeature() {} - - private static final FeatureFlag LEARNING_TO_RANK = new FeatureFlag("learning_to_rank"); - - public static boolean isEnabled() { - return LEARNING_TO_RANK.isEnabled(); - } -} diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankService.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankService.java index 177099801e0a5..d1c23b26dc46e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankService.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankService.java @@ -7,8 +7,11 @@ package org.elasticsearch.xpack.ml.inference.ltr; +import org.elasticsearch.Build; import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchNoneQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -52,6 +55,20 @@ import static org.elasticsearch.xpack.core.ml.job.messages.Messages.INFERENCE_CONFIG_QUERY_BAD_FORMAT; public class LearningToRankService { + /** + * This setting behave like a feature flag for the learning to rank feature but can be set by an operator on self-managed environment. + * The feature is enabled by default only for snapshots builds. + * + * Before enabling by default, ensure transport serialization is all corrected for future BWC. + * + * See {@link LearningToRankRescorerBuilder} + */ + public static Setting LEARNING_TO_RANK_ENABLED = Setting.boolSetting("xpack.ml.learning_to_rank.enabled", + Build.current().isSnapshot(), + Setting.Property.OperatorDynamic, + Setting.Property.NodeScope + ); + private static final Map SCRIPT_OPTIONS = Map.ofEntries( entry(MustacheScriptEngine.DETECT_MISSING_PARAMS_OPTION, Boolean.TRUE.toString()) ); @@ -59,26 +76,39 @@ public class LearningToRankService { private final TrainedModelProvider trainedModelProvider; private final ScriptService scriptService; private final XContentParserConfiguration parserConfiguration; + private final boolean enabled; public LearningToRankService( ModelLoadingService modelLoadingService, TrainedModelProvider trainedModelProvider, ScriptService scriptService, - NamedXContentRegistry xContentRegistry + NamedXContentRegistry xContentRegistry, + Settings settings ) { - this(modelLoadingService, trainedModelProvider, scriptService, XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)); + this(modelLoadingService, trainedModelProvider, scriptService, XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry), settings); } LearningToRankService( ModelLoadingService modelLoadingService, TrainedModelProvider trainedModelProvider, ScriptService scriptService, - XContentParserConfiguration parserConfiguration + XContentParserConfiguration parserConfiguration, + Settings settings ) { this.modelLoadingService = modelLoadingService; this.scriptService = scriptService; this.trainedModelProvider = trainedModelProvider; this.parserConfiguration = parserConfiguration; + this.enabled = LEARNING_TO_RANK_ENABLED.get(settings); + } + + /** + * Check if the learning to rank is enabled or not. + * + * @return Whether the LTR feature is enabled or not. + */ + public boolean isEnabled() { + return enabled; } /** diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankServiceTests.java index 39d0af9041d03..ea878903ce5a2 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ltr/LearningToRankServiceTests.java @@ -238,7 +238,7 @@ private LearningToRankService getTestLearningToRankService(LearningToRankConfig } private LearningToRankService getTestLearningToRankService(TrainedModelProvider trainedModelProvider) { - return new LearningToRankService(mockModelLoadingService(), trainedModelProvider, getTestScriptService(), xContentRegistry()); + return new LearningToRankService(mockModelLoadingService(), trainedModelProvider, getTestScriptService(), xContentRegistry(), Settings.EMPTY); } private ScriptService getTestScriptService() { diff --git a/x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java b/x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java index 0efe2797c7f76..ff7a7cc82e9b7 100644 --- a/x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +++ b/x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java @@ -43,7 +43,7 @@ public class XPackRestIT extends AbstractXPackRestTest { .setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB") .user("x_pack_rest_user", "x-pack-test-password") .feature(FeatureFlag.TIME_SERIES_MODE) - .feature(FeatureFlag.LEARNING_TO_RANK) + .setting("xpack.ml.learning_to_rank.enabled", "true") .configFile("testnode.pem", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem")) .configFile("testnode.crt", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt")) .configFile("service_tokens", Resource.fromClasspath("service_tokens"))