|
|
@@ -9,17 +9,24 @@
|
|
|
package org.elasticsearch.rest.action.cat;
|
|
|
|
|
|
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
|
|
+import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
|
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
import org.elasticsearch.cluster.ClusterName;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
+import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
+import org.elasticsearch.monitor.fs.FsInfo;
|
|
|
+import org.elasticsearch.monitor.os.OsStats;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.test.rest.FakeRestRequest;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static java.util.Collections.emptySet;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
@@ -48,4 +55,70 @@ public class RestNodesActionTests extends ESTestCase {
|
|
|
|
|
|
action.buildTable(false, new FakeRestRequest(), clusterStateResponse, nodesInfoResponse, nodesStatsResponse);
|
|
|
}
|
|
|
+
|
|
|
+ public void testFormattedNumericSort() {
|
|
|
+ final var clusterState = ClusterState.builder(ClusterName.DEFAULT)
|
|
|
+ .nodes(DiscoveryNodes.builder().add(DiscoveryNodeUtils.create("node-1")).add(DiscoveryNodeUtils.create("node-2")))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final var nowMillis = System.currentTimeMillis();
|
|
|
+ final var rowOrder = RestTable.getRowOrder(
|
|
|
+ action.buildTable(
|
|
|
+ false,
|
|
|
+ new FakeRestRequest(),
|
|
|
+ new ClusterStateResponse(clusterState.getClusterName(), clusterState, false),
|
|
|
+ new NodesInfoResponse(clusterState.getClusterName(), List.of(), List.of()),
|
|
|
+ new NodesStatsResponse(
|
|
|
+ clusterState.getClusterName(),
|
|
|
+ List.of(
|
|
|
+ // sorting 10 vs 9 in all relevant columns, since these sort incorrectly as strings
|
|
|
+ getTrickySortingNodeStats(nowMillis, clusterState.nodes().get("node-1"), 10),
|
|
|
+ getTrickySortingNodeStats(nowMillis, clusterState.nodes().get("node-2"), 9)
|
|
|
+ ),
|
|
|
+ Collections.emptyList()
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ new FakeRestRequest.Builder(xContentRegistry()).withParams(
|
|
|
+ Map.of("s", randomFrom("load_1m", "load_5m", "load_15m", "disk.used_percent"))
|
|
|
+ ).build()
|
|
|
+ );
|
|
|
+
|
|
|
+ final var nodesList = new ArrayList<DiscoveryNode>();
|
|
|
+ for (final var node : clusterState.nodes()) {
|
|
|
+ nodesList.add(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertEquals("node-2", nodesList.get(rowOrder.get(0)).getId());
|
|
|
+ assertEquals("node-1", nodesList.get(rowOrder.get(1)).getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static NodeStats getTrickySortingNodeStats(long nowMillis, DiscoveryNode node, int sortValue) {
|
|
|
+ return new NodeStats(
|
|
|
+ node,
|
|
|
+ nowMillis,
|
|
|
+ null,
|
|
|
+ new OsStats(
|
|
|
+ nowMillis,
|
|
|
+ new OsStats.Cpu((short) sortValue, new double[] { sortValue, sortValue, sortValue }),
|
|
|
+ new OsStats.Mem(0, 0, 0),
|
|
|
+ new OsStats.Swap(0, 0),
|
|
|
+ null
|
|
|
+ ),
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ new FsInfo(nowMillis, null, new FsInfo.Path[] { new FsInfo.Path("/foo", "/foo", 100, 100 - sortValue, 100 - sortValue) }),
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|