|
@@ -5,8 +5,10 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.monitoring.collector.cluster;
|
|
|
|
|
|
+import org.elasticsearch.ElasticsearchTimeoutException;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionFuture;
|
|
|
+import org.elasticsearch.action.FailedNodeException;
|
|
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsIndices;
|
|
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes;
|
|
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
|
|
@@ -37,6 +39,7 @@ import org.elasticsearch.xpack.monitoring.MonitoringTestUtils;
|
|
|
import org.junit.Assert;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -189,7 +192,8 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
|
|
|
when(mockClusterStatsResponse.getIndicesStats()).thenReturn(mockClusterStatsIndices);
|
|
|
|
|
|
final ClusterStatsRequestBuilder clusterStatsRequestBuilder = mock(ClusterStatsRequestBuilder.class);
|
|
|
- when(clusterStatsRequestBuilder.get(eq(timeout))).thenReturn(mockClusterStatsResponse);
|
|
|
+ when(clusterStatsRequestBuilder.setTimeout(eq(timeout))).thenReturn(clusterStatsRequestBuilder);
|
|
|
+ when(clusterStatsRequestBuilder.get()).thenReturn(mockClusterStatsResponse);
|
|
|
|
|
|
final ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);
|
|
|
when(clusterAdminClient.prepareClusterStats()).thenReturn(clusterStatsRequestBuilder);
|
|
@@ -280,7 +284,7 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
|
|
|
{
|
|
|
indexNameExpressionResolver = mock(IndexNameExpressionResolver.class);
|
|
|
when(indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.lenientExpandOpen(), "apm-*"))
|
|
|
- .thenReturn(new Index[0]);
|
|
|
+ .thenReturn(Index.EMPTY_ARRAY);
|
|
|
}
|
|
|
|
|
|
final Client client = mock(Client.class);
|
|
@@ -296,7 +300,8 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
|
|
|
when(mockClusterStatsResponse.getIndicesStats()).thenReturn(mockClusterStatsIndices);
|
|
|
|
|
|
final ClusterStatsRequestBuilder clusterStatsRequestBuilder = mock(ClusterStatsRequestBuilder.class);
|
|
|
- when(clusterStatsRequestBuilder.get(eq(timeout))).thenReturn(mockClusterStatsResponse);
|
|
|
+ when(clusterStatsRequestBuilder.setTimeout(eq(timeout))).thenReturn(clusterStatsRequestBuilder);
|
|
|
+ when(clusterStatsRequestBuilder.get()).thenReturn(mockClusterStatsResponse);
|
|
|
|
|
|
final ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);
|
|
|
when(clusterAdminClient.prepareClusterStats()).thenReturn(clusterStatsRequestBuilder);
|
|
@@ -325,4 +330,58 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
|
|
|
final ClusterStatsMonitoringDoc doc = (ClusterStatsMonitoringDoc) results.iterator().next();
|
|
|
assertThat(doc.getLicense(), nullValue());
|
|
|
}
|
|
|
+
|
|
|
+ public void testDoCollectThrowsTimeoutException() throws Exception {
|
|
|
+ final TimeValue timeout;
|
|
|
+ {
|
|
|
+ final String clusterName = randomAlphaOfLength(10);
|
|
|
+ whenClusterStateWithName(clusterName);
|
|
|
+ final String clusterUUID = UUID.randomUUID().toString();
|
|
|
+ whenClusterStateWithUUID(clusterUUID);
|
|
|
+ timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120));
|
|
|
+ withCollectionTimeout(ClusterStatsCollector.CLUSTER_STATS_TIMEOUT, timeout);
|
|
|
+ }
|
|
|
+ final IndexNameExpressionResolver indexNameExpressionResolver;
|
|
|
+ {
|
|
|
+ indexNameExpressionResolver = mock(IndexNameExpressionResolver.class);
|
|
|
+ when(indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.lenientExpandOpen(), "apm-*"))
|
|
|
+ .thenReturn(Index.EMPTY_ARRAY);
|
|
|
+ }
|
|
|
+
|
|
|
+ final Client client = mock(Client.class);
|
|
|
+ {
|
|
|
+ final ClusterStatsResponse mockClusterStatsResponse = mock(ClusterStatsResponse.class);
|
|
|
+ final ClusterHealthStatus clusterStatus = randomFrom(ClusterHealthStatus.values());
|
|
|
+ when(mockClusterStatsResponse.getStatus()).thenReturn(clusterStatus);
|
|
|
+ when(mockClusterStatsResponse.getNodesStats()).thenReturn(mock(ClusterStatsNodes.class));
|
|
|
+ when(mockClusterStatsResponse.failures()).thenReturn(List.of(new FailedNodeException("node", "msg",
|
|
|
+ new ElasticsearchTimeoutException("timed out"))));
|
|
|
+
|
|
|
+ final ClusterStatsIndices mockClusterStatsIndices = mock(ClusterStatsIndices.class);
|
|
|
+
|
|
|
+ when(mockClusterStatsIndices.getIndexCount()).thenReturn(0);
|
|
|
+ when(mockClusterStatsResponse.getIndicesStats()).thenReturn(mockClusterStatsIndices);
|
|
|
+
|
|
|
+ final ClusterStatsRequestBuilder clusterStatsRequestBuilder = mock(ClusterStatsRequestBuilder.class);
|
|
|
+ when(clusterStatsRequestBuilder.setTimeout(eq(timeout))).thenReturn(clusterStatsRequestBuilder);
|
|
|
+ when(clusterStatsRequestBuilder.get()).thenReturn(mockClusterStatsResponse);
|
|
|
+
|
|
|
+ final ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);
|
|
|
+ when(clusterAdminClient.prepareClusterStats()).thenReturn(clusterStatsRequestBuilder);
|
|
|
+
|
|
|
+ final AdminClient adminClient = mock(AdminClient.class);
|
|
|
+ when(adminClient.cluster()).thenReturn(clusterAdminClient);
|
|
|
+ when(client.admin()).thenReturn(adminClient);
|
|
|
+ }
|
|
|
+
|
|
|
+ final long interval = randomNonNegativeLong();
|
|
|
+ final Settings.Builder settings = Settings.builder();
|
|
|
+ final MonitoringDoc.Node node = MonitoringTestUtils.randomMonitoringNode(random());
|
|
|
+
|
|
|
+ final ClusterStatsCollector collector =
|
|
|
+ new ClusterStatsCollector(settings.build(), clusterService, licenseState,
|
|
|
+ client, licenseService, indexNameExpressionResolver);
|
|
|
+ expectThrows(ElasticsearchTimeoutException.class, () -> collector.doCollect(node, interval, clusterState));
|
|
|
+ }
|
|
|
+
|
|
|
}
|