-
Notifications
You must be signed in to change notification settings - Fork 25.6k
datafeed: check remote_cluster_client before cluster aliases in start #129601
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
Merged
schase-es
merged 5 commits into
elastic:main
from
schase-es:ES-11841_remote-cluster-client-role-datafeed-indices
Jun 20, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7766546
datafeed: check remote_cluster_client before cluster aliases in start
schase-es 76ec29f
Addressed review feedback:
schase-es 7482dad
[CI] Auto commit changes from spotless
6267596
Merge branch 'main' into ES-11841_remote-cluster-client-role-datafeed…
schase-es 1e44abc
Trimmed extra dependencies from gradle
schase-es File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
x-pack/plugin/ml/qa/datafeed-multicluster-tests/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| apply plugin: 'elasticsearch.internal-java-rest-test' | ||
| apply plugin: 'elasticsearch.rest-resources' | ||
|
|
||
| dependencies { | ||
| testImplementation project(':x-pack:qa') | ||
| testImplementation project(path: ':test:test-clusters') | ||
| } | ||
|
|
||
| tasks.named('javaRestTest') { | ||
| usesDefaultDistribution("Test internally configures the clusters") | ||
| } |
177 changes: 177 additions & 0 deletions
177
.../javaRestTest/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRemoteClusterClientIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.ml.datafeed; | ||
|
|
||
| import org.apache.http.HttpHost; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.client.RestClient; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
| import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||
| import org.elasticsearch.test.rest.ESRestTestCase; | ||
| import org.junit.ClassRule; | ||
| import org.junit.rules.RuleChain; | ||
| import org.junit.rules.TestRule; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.hamcrest.Matchers.containsString; | ||
|
|
||
| /** | ||
| * A test to check that remote_cluster_client errors are correctly reported when a datafeed job is started. | ||
| * The local datafeed job references a remote index in a local anomaly detection job. When the | ||
| * remote_cluster_client role is missing in the local cluster. This prevents remote indices from being | ||
| * resolved to their cluster names. | ||
| * | ||
| * @see <a href="https://github.com/elastic/elasticsearch/issues/121149">GitHub issue 121149</a> | ||
| */ | ||
| public class DatafeedRemoteClusterClientIT extends ESRestTestCase { | ||
| public static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local() | ||
| .name("remote_cluster") | ||
| .distribution(DistributionType.DEFAULT) | ||
| .module("data-streams") | ||
| .module("x-pack-stack") | ||
| .setting("xpack.security.enabled", "false") | ||
| .setting("xpack.license.self_generated.type", "trial") | ||
| .setting("cluster.logsdb.enabled", "true") | ||
| .build(); | ||
|
|
||
| public static ElasticsearchCluster localCluster = ElasticsearchCluster.local() | ||
| .name("local_cluster") | ||
| .distribution(DistributionType.DEFAULT) | ||
| .module("data-streams") | ||
| .module("x-pack-stack") | ||
| .setting("xpack.security.enabled", "false") | ||
| .setting("xpack.license.self_generated.type", "trial") | ||
| .setting("cluster.logsdb.enabled", "true") | ||
| .setting("node.roles", "[data,ingest,master,ml]") // remote_cluster_client not included | ||
| .setting("cluster.remote.remote_cluster.seeds", () -> "\"" + remoteCluster.getTransportEndpoint(0) + "\"") | ||
| .setting("cluster.remote.connections_per_cluster", "1") | ||
| .setting("cluster.remote.remote_cluster.skip_unavailable", "false") | ||
| .build(); | ||
|
|
||
| @ClassRule | ||
| public static TestRule clusterRule = RuleChain.outerRule(remoteCluster).around(localCluster); | ||
|
|
||
| private RestClient localClusterClient() throws IOException { | ||
| var clusterHosts = parseClusterHosts(localCluster.getHttpAddresses()); | ||
| return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0])); | ||
| } | ||
|
|
||
| private RestClient remoteClusterClient() throws IOException { | ||
| var clusterHosts = parseClusterHosts(remoteCluster.getHttpAddresses()); | ||
| return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0])); | ||
| } | ||
|
|
||
| public void testSource() throws IOException { | ||
| String localIndex = "local_index"; | ||
| String remoteIndex = "remote_index"; | ||
| String mapping = """ | ||
| { | ||
| "properties": { | ||
| "timestamp": { | ||
| "type": "date" | ||
| }, | ||
| "bytes": { | ||
| "type": "integer" | ||
| } | ||
| } | ||
| } | ||
| """; | ||
| try (RestClient localClient = localClusterClient(); RestClient remoteClient = remoteClusterClient()) { | ||
| createIndex( | ||
| remoteClient, | ||
| remoteIndex, | ||
| Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(5, 20)).build(), | ||
| mapping | ||
| ); | ||
|
|
||
| Request request = new Request("PUT", "_ml/anomaly_detectors/test_anomaly_detector"); | ||
| request.setJsonEntity(""" | ||
| { | ||
| "analysis_config": { | ||
| "bucket_span": "15m", | ||
| "detectors": [ | ||
| { | ||
| "detector_description": "Sum of bytes", | ||
| "function": "sum", | ||
| "field_name": "bytes" | ||
| } | ||
| ] | ||
| }, | ||
| "data_description": { | ||
| "time_field": "timestamp", | ||
| "time_format": "epoch_ms" | ||
| }, | ||
| "analysis_limits": { | ||
| "model_memory_limit": "11MB" | ||
| }, | ||
| "model_plot_config": { | ||
| "enabled": true, | ||
| "annotations_enabled": true | ||
| }, | ||
| "results_index_name": "test_datafeed_out", | ||
| "datafeed_config": { | ||
| "indices": [ | ||
| "remote_cluster:remote_index" | ||
| ], | ||
| "query": { | ||
| "bool": { | ||
| "must": [ | ||
| { | ||
| "match_all": {} | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "runtime_mappings": { | ||
| "hour_of_day": { | ||
| "type": "long", | ||
| "script": { | ||
| "source": "emit(doc['timestamp'].value.getHour());" | ||
| } | ||
| } | ||
| }, | ||
| "datafeed_id": "test_datafeed" | ||
| } | ||
| }"""); | ||
| Response response = localClient.performRequest(request); | ||
| logger.info("Anomaly Detection Response:", response.getStatusLine()); | ||
|
|
||
| request = new Request("GET", "_ml/anomaly_detectors/test_anomaly_detector"); | ||
| response = localClient.performRequest(request); | ||
| logger.info("Anomaly detection get:", response.getEntity()); | ||
|
|
||
| request = new Request("POST", "_ml/anomaly_detectors/test_anomaly_detector/_open"); | ||
| response = localClient.performRequest(request); | ||
|
|
||
| final Request startRequest = new Request("POST", "_ml/datafeeds/test_datafeed/_start"); | ||
| request.setJsonEntity(""" | ||
| { | ||
| "start": "2019-04-07T18:22:16Z" | ||
| } | ||
| """); | ||
| ResponseException e = assertThrows(ResponseException.class, () -> localClient.performRequest(startRequest)); | ||
| assertThat(e.getMessage(), containsString(""" | ||
| Datafeed [test_datafeed] is configured with a remote index pattern(s) \ | ||
| [remote_cluster:remote_index] but the current node [local_cluster-0] \ | ||
| is not allowed to connect to remote clusters. Please enable node.remote_cluster_client \ | ||
| for all machine learning nodes and master-eligible nodes""")); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTestRestCluster() { | ||
| return localCluster.getHttpAddresses(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.