forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
...alClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsRemoteIT.java
This file contains 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,149 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.stats; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.search.SearchRequest; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.health.ClusterHealthStatus; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.index.query.MatchAllQueryBuilder; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.test.AbstractMultiClustersTestCase; | ||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.test.ESIntegTestCase.Scope; | ||
import org.elasticsearch.test.InternalTestCluster; | ||
import org.junit.Assert; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.equalToIgnoringCase; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasKey; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.oneOf; | ||
|
||
@ClusterScope(scope = Scope.TEST, numDataNodes = 0) | ||
public class ClusterStatsRemoteIT extends AbstractMultiClustersTestCase { | ||
private static final String REMOTE1 = "cluster-a"; | ||
private static final String REMOTE2 = "cluster-b"; | ||
|
||
private static final String INDEX_NAME = "demo"; | ||
|
||
@Override | ||
protected boolean reuseClusters() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Collection<String> remoteClusterAlias() { | ||
return List.of(REMOTE1, REMOTE2); | ||
} | ||
|
||
@Override | ||
protected Map<String, Boolean> skipUnavailableForRemoteClusters() { | ||
return Map.of(REMOTE1, false, REMOTE2, true); | ||
} | ||
|
||
public void testRemoteClusterStats() throws ExecutionException, InterruptedException { | ||
setupClusters(); | ||
final Client client = client(LOCAL_CLUSTER); | ||
SearchRequest searchRequest = new SearchRequest("*", "*:*"); | ||
searchRequest.allowPartialSearchResults(false); | ||
searchRequest.setCcsMinimizeRoundtrips(randomBoolean()); | ||
searchRequest.source(new SearchSourceBuilder().query(new MatchAllQueryBuilder()).size(10)); | ||
|
||
// do a search | ||
assertResponse(cluster(LOCAL_CLUSTER).client().search(searchRequest), Assert::assertNotNull); | ||
// collect stats without remotes | ||
ClusterStatsResponse response = client.admin().cluster().prepareClusterStats().get(); | ||
assertNotNull(response.getCcsMetrics()); | ||
var remotesUsage = response.getCcsMetrics().getByRemoteCluster(); | ||
assertThat(remotesUsage.size(), equalTo(3)); | ||
assertNull(response.getRemoteClustersStats()); | ||
// collect stats with remotes | ||
response = client.admin().cluster().prepareClusterStatsWithRemotes().get(); | ||
assertNotNull(response.getCcsMetrics()); | ||
remotesUsage = response.getCcsMetrics().getByRemoteCluster(); | ||
assertThat(remotesUsage.size(), equalTo(3)); | ||
assertNotNull(response.getRemoteClustersStats()); | ||
var remoteStats = response.getRemoteClustersStats(); | ||
assertThat(remoteStats.size(), equalTo(2)); | ||
for (String clusterAlias : remoteClusterAlias()) { | ||
assertThat(remoteStats, hasKey(clusterAlias)); | ||
assertThat(remotesUsage, hasKey(clusterAlias)); | ||
assertThat(remoteStats.get(clusterAlias).getStatus(), equalToIgnoringCase(ClusterHealthStatus.GREEN.name())); | ||
assertThat(remoteStats.get(clusterAlias).getIndicesCount(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getNodesCount(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getShardsCount(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getHeapBytes(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getMemBytes(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getIndicesBytes(), greaterThan(0L)); | ||
assertThat(remoteStats.get(clusterAlias).getVersions(), hasItem(Version.CURRENT.toString())); | ||
assertThat(remoteStats.get(clusterAlias).getClusterUUID(), not(equalTo(""))); | ||
assertThat(remoteStats.get(clusterAlias).getMode(), oneOf("sniff", "proxy")); | ||
} | ||
assertFalse(remoteStats.get(REMOTE1).isSkipUnavailable()); | ||
assertTrue(remoteStats.get(REMOTE2).isSkipUnavailable()); | ||
} | ||
|
||
private void setupClusters() { | ||
int numShardsLocal = randomIntBetween(2, 10); | ||
Settings localSettings = indexSettings(numShardsLocal, randomIntBetween(0, 1)).build(); | ||
assertAcked( | ||
client(LOCAL_CLUSTER).admin() | ||
.indices() | ||
.prepareCreate(INDEX_NAME) | ||
.setSettings(localSettings) | ||
.setMapping("@timestamp", "type=date", "f", "type=text") | ||
); | ||
indexDocs(client(LOCAL_CLUSTER)); | ||
|
||
int numShardsRemote = randomIntBetween(2, 10); | ||
for (String clusterAlias : remoteClusterAlias()) { | ||
final InternalTestCluster remoteCluster = cluster(clusterAlias); | ||
remoteCluster.ensureAtLeastNumDataNodes(randomIntBetween(1, 3)); | ||
assertAcked( | ||
client(clusterAlias).admin() | ||
.indices() | ||
.prepareCreate(INDEX_NAME) | ||
.setSettings(indexSettings(numShardsRemote, randomIntBetween(0, 1))) | ||
.setMapping("@timestamp", "type=date", "f", "type=text") | ||
); | ||
assertFalse( | ||
client(clusterAlias).admin() | ||
.cluster() | ||
.prepareHealth(INDEX_NAME) | ||
.setWaitForGreenStatus() | ||
.setTimeout(TimeValue.timeValueSeconds(10)) | ||
.get() | ||
.isTimedOut() | ||
); | ||
indexDocs(client(clusterAlias)); | ||
} | ||
|
||
} | ||
|
||
private void indexDocs(Client client) { | ||
int numDocs = between(5, 20); | ||
for (int i = 0; i < numDocs; i++) { | ||
client.prepareIndex(INDEX_NAME).setSource("f", "v", "@timestamp", randomNonNegativeLong()).get(); | ||
} | ||
client.admin().indices().prepareRefresh(INDEX_NAME).get(); | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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