-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Throw an error when a datafeed needs CCS but it is not enabled for the node #46044
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,12 @@ | |
import org.elasticsearch.mock.orig.Mockito; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.RemoteClusterService; | ||
import org.elasticsearch.xpack.core.action.util.QueryPage; | ||
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; | ||
import org.elasticsearch.xpack.core.ml.job.config.DataDescription; | ||
import org.elasticsearch.xpack.core.ml.job.config.Job; | ||
import org.elasticsearch.xpack.core.ml.job.messages.Messages; | ||
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; | ||
import org.elasticsearch.xpack.core.ml.job.results.Bucket; | ||
import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; | ||
|
@@ -92,7 +94,9 @@ public void init() { | |
jobConfigProvider, | ||
jobResultsProvider, | ||
datafeedConfigProvider, | ||
jobResultsPersister); | ||
jobResultsPersister, | ||
Settings.EMPTY, | ||
"test_node"); | ||
} | ||
|
||
public void testBuild_GivenScrollDatafeedAndNewJob() throws Exception { | ||
|
@@ -202,6 +206,46 @@ public void testBuild_GivenBucketsRequestFails() { | |
verify(taskHandler).accept(error); | ||
} | ||
|
||
public void testBuildGivenRemoteIndicesButNoRemoteSearching() throws Exception { | ||
Settings settings = Settings.builder().put(RemoteClusterService.ENABLE_REMOTE_CLUSTERS.getKey(), false).build(); | ||
datafeedJobBuilder = | ||
new DatafeedJobBuilder( | ||
client, | ||
xContentRegistry(), | ||
auditor, | ||
System::currentTimeMillis, | ||
jobConfigProvider, | ||
jobResultsProvider, | ||
datafeedConfigProvider, | ||
jobResultsPersister, | ||
settings, | ||
"test_node"); | ||
DataDescription.Builder dataDescription = new DataDescription.Builder(); | ||
dataDescription.setTimeField("time"); | ||
Job.Builder jobBuilder = DatafeedManagerTests.createDatafeedJob(); | ||
jobBuilder.setDataDescription(dataDescription); | ||
jobBuilder.setCreateTime(new Date()); | ||
DatafeedConfig.Builder datafeed = DatafeedManagerTests.createDatafeedConfig("datafeed1", jobBuilder.getId()); | ||
datafeed.setIndices(Collections.singletonList("remotecluster:index-*")); | ||
|
||
AtomicBoolean wasHandlerCalled = new AtomicBoolean(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the handler run in a different thread than the main test thread? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it runs in the same thread but I think because the boolean is updated in a lambda it must be effectively final and you can't do that with a simple |
||
ActionListener<DatafeedJob> datafeedJobHandler = ActionListener.wrap( | ||
datafeedJob -> fail("datafeed builder did not fail when remote index was given and remote clusters were not enabled"), | ||
e -> { | ||
assertThat(e.getMessage(), equalTo(Messages.getMessage(Messages.DATAFEED_NEEDS_REMOTE_CLUSTER_SEARCH, | ||
"datafeed1", | ||
"[remotecluster:index-*]", | ||
"test_node"))); | ||
wasHandlerCalled.compareAndSet(false, true); | ||
} | ||
); | ||
|
||
givenJob(jobBuilder); | ||
givenDatafeed(datafeed); | ||
datafeedJobBuilder.build("datafeed1", datafeedJobHandler); | ||
assertBusy(() -> wasHandlerCalled.get()); | ||
} | ||
|
||
private void givenJob(Job.Builder job) { | ||
Mockito.doAnswer(invocationOnMock -> { | ||
@SuppressWarnings("unchecked") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be tied to the previous item I think this needs to be:
I.e.
+
and--
before and--
after.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you often need a blank line after the admonition block (i.e. after the "ML node." and before the final "--"), otherwise it doesn't format properly. If you need any help with the formatting, just let me know.