|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.action.admin.cluster.stats; |
| 11 | + |
| 12 | +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; |
| 13 | +import org.elasticsearch.common.util.CollectionUtils; |
| 14 | +import org.elasticsearch.plugins.Plugin; |
| 15 | +import org.elasticsearch.plugins.PluginsService; |
| 16 | +import org.elasticsearch.telemetry.TestTelemetryPlugin; |
| 17 | +import org.elasticsearch.test.ESIntegTestCase; |
| 18 | +import org.elasticsearch.threadpool.ThreadPool; |
| 19 | +import org.elasticsearch.threadpool.ThreadPoolStats; |
| 20 | + |
| 21 | +import java.util.Collection; |
| 22 | + |
| 23 | +import static org.hamcrest.Matchers.greaterThan; |
| 24 | + |
| 25 | +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) |
| 26 | +public class NodeStatsIT extends ESIntegTestCase { |
| 27 | + |
| 28 | + @Override |
| 29 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 30 | + return CollectionUtils.appendToCopy(super.nodePlugins(), TestTelemetryPlugin.class); |
| 31 | + } |
| 32 | + |
| 33 | + public void testNodeStatsIncludesThreadPoolUtilization() { |
| 34 | + final String dataNode = internalCluster().startNode(); |
| 35 | + |
| 36 | + indexRandom(true, randomIdentifier(), randomIntBetween(10, 100)); |
| 37 | + |
| 38 | + // Trigger a collection (we piggyback on the APM utilization measure for now) |
| 39 | + for (PluginsService pluginsService : internalCluster().getInstances(PluginsService.class)) { |
| 40 | + final TestTelemetryPlugin telemetryPlugin = pluginsService.filterPlugins(TestTelemetryPlugin.class).findFirst().orElseThrow(); |
| 41 | + telemetryPlugin.collect(); |
| 42 | + } |
| 43 | + |
| 44 | + final NodesStatsResponse nodesStatsResponse = internalCluster().client() |
| 45 | + .admin() |
| 46 | + .cluster() |
| 47 | + .prepareNodesStats(dataNode) |
| 48 | + .setThreadPool(true) |
| 49 | + .execute() |
| 50 | + .actionGet(); |
| 51 | + |
| 52 | + final ThreadPoolStats threadPool = nodesStatsResponse.getNodes().getFirst().getThreadPool(); |
| 53 | + final ThreadPoolStats.Stats writeThreadPoolStats = threadPool.stats() |
| 54 | + .stream() |
| 55 | + .filter(st -> ThreadPool.Names.WRITE.equals(st.name())) |
| 56 | + .findFirst() |
| 57 | + .orElseThrow(); |
| 58 | + assertThat(writeThreadPoolStats.utilization(), greaterThan(0.0f)); |
| 59 | + } |
| 60 | +} |
0 commit comments