Skip to content

Commit 15d800c

Browse files
committed
[ML] Disable CrossProject for Datafeeds
Initially, Datafeeds will not support cross-project source indices. We will verify that the IndicesOptions is not trying to resolve a cross-project index expression and throw a cross-project specific error message.
1 parent da9b1d6 commit 15d800c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,10 @@ public DatafeedConfig build() {
10501050
if (indicesOptions == null) {
10511051
indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED;
10521052
}
1053+
if (indicesOptions.resolveCrossProjectIndexExpression()) {
1054+
throw ExceptionsHelper.crossProjectSearchIsDisabled();
1055+
}
1056+
10531057
return new DatafeedConfig(
10541058
id,
10551059
jobId,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/ExceptionsHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public static ElasticsearchStatusException taskOperationFailureToStatusException
101101
return new ElasticsearchStatusException(failure.getCause().getMessage(), failure.getStatus(), failure.getCause());
102102
}
103103

104+
public static ElasticsearchStatusException crossProjectSearchIsDisabled() {
105+
return new ElasticsearchStatusException("Cross-project search is not enabled for any ML feature", RestStatus.FORBIDDEN);
106+
}
107+
104108
/**
105109
* Creates an error message that explains there are shard failures, displays info
106110
* for the first failure (shard/reason) and kindly asks to see more info in the logs

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigBuilderTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77
package org.elasticsearch.xpack.core.ml.datafeed;
88

9+
import org.elasticsearch.ElasticsearchStatusException;
910
import org.elasticsearch.action.search.SearchRequest;
1011
import org.elasticsearch.action.support.IndicesOptions;
1112
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1213
import org.elasticsearch.common.io.stream.Writeable;
1314
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.core.TimeValue;
16+
import org.elasticsearch.rest.RestStatus;
1517
import org.elasticsearch.search.SearchModule;
1618
import org.elasticsearch.search.aggregations.AggregationBuilder;
1719
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -30,6 +32,7 @@
3032

3133
import static org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfigTests.randomStringList;
3234
import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createTestQueryProvider;
35+
import static org.hamcrest.Matchers.equalTo;
3336

3437
public class DatafeedConfigBuilderTests extends AbstractWireSerializingTestCase<DatafeedConfig.Builder> {
3538

@@ -147,4 +150,17 @@ protected Writeable.Reader<DatafeedConfig.Builder> instanceReader() {
147150
return DatafeedConfig.Builder::new;
148151
}
149152

153+
public void testResolveCrossProjectIsDisabled() {
154+
var datafeedBuilder = createRandomizedDatafeedConfigBuilder("jobId", "datafeed-id", 3600000);
155+
datafeedBuilder = datafeedBuilder.setIndicesOptions(
156+
IndicesOptions.builder(datafeedBuilder.getIndicesOptions())
157+
.crossProjectModeOptions(new IndicesOptions.CrossProjectModeOptions(true))
158+
.build()
159+
);
160+
161+
var actualException = assertThrows(ElasticsearchStatusException.class, datafeedBuilder::build);
162+
assertThat(actualException.getMessage(), equalTo("Cross-project search is not enabled for any ML feature"));
163+
assertThat(actualException.status(), equalTo(RestStatus.FORBIDDEN));
164+
}
165+
150166
}

0 commit comments

Comments
 (0)