use of org.opensearch.indices.NodeIndicesStats in project OpenSearch by opensearch-project.
the class IndexRecoveryIT method testReservesBytesDuringPeerRecoveryPhaseOne.
public void testReservesBytesDuringPeerRecoveryPhaseOne() throws Exception {
internalCluster().startNode();
List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
String indexName = "test-index";
createIndex(indexName, Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.routing.allocation.include._name", String.join(",", dataNodes)).build());
ensureGreen(indexName);
final List<IndexRequestBuilder> indexRequests = IntStream.range(0, between(10, 500)).mapToObj(n -> client().prepareIndex(indexName).setSource("foo", "bar")).collect(Collectors.toList());
indexRandom(randomBoolean(), true, true, indexRequests);
assertThat(client().admin().indices().prepareFlush(indexName).get().getFailedShards(), equalTo(0));
ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
DiscoveryNode nodeWithPrimary = clusterState.nodes().get(clusterState.routingTable().index(indexName).shard(0).primaryShard().currentNodeId());
MockTransportService transportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nodeWithPrimary.getName());
final AtomicBoolean fileInfoIntercepted = new AtomicBoolean();
final AtomicBoolean fileChunkIntercepted = new AtomicBoolean();
transportService.addSendBehavior((connection, requestId, action, request, options) -> {
if (action.equals(PeerRecoveryTargetService.Actions.FILES_INFO)) {
if (fileInfoIntercepted.compareAndSet(false, true)) {
final NodeIndicesStats nodeIndicesStats = client().admin().cluster().prepareNodesStats(connection.getNode().getId()).clear().setIndices(new CommonStatsFlags(CommonStatsFlags.Flag.Store)).get().getNodes().get(0).getIndices();
assertThat(nodeIndicesStats.getStore().getReservedSize().getBytes(), equalTo(0L));
assertThat(nodeIndicesStats.getShardStats(clusterState.metadata().index(indexName).getIndex()).stream().flatMap(s -> Arrays.stream(s.getShards())).map(s -> s.getStats().getStore().getReservedSize().getBytes()).collect(Collectors.toList()), everyItem(equalTo(StoreStats.UNKNOWN_RESERVED_BYTES)));
}
} else if (action.equals(PeerRecoveryTargetService.Actions.FILE_CHUNK)) {
if (fileChunkIntercepted.compareAndSet(false, true)) {
assertThat(client().admin().cluster().prepareNodesStats(connection.getNode().getId()).clear().setIndices(new CommonStatsFlags(CommonStatsFlags.Flag.Store)).get().getNodes().get(0).getIndices().getStore().getReservedSize().getBytes(), greaterThan(0L));
}
}
connection.sendRequest(requestId, action, request, options);
});
assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put("index.number_of_replicas", 1)));
ensureGreen();
assertTrue(fileInfoIntercepted.get());
assertTrue(fileChunkIntercepted.get());
assertThat(client().admin().cluster().prepareNodesStats().get().getNodes().stream().mapToLong(n -> n.getIndices().getStore().getReservedSize().getBytes()).sum(), equalTo(0L));
}
use of org.opensearch.indices.NodeIndicesStats in project OpenSearch by opensearch-project.
the class RestNodesAction method buildTable.
Table buildTable(boolean fullId, RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
DiscoveryNodes nodes = state.getState().nodes();
String masterId = nodes.getMasterNodeId();
Table table = getTableWithHeader(req);
for (DiscoveryNode node : nodes) {
NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
NodeStats stats = nodesStats.getNodesMap().get(node.getId());
JvmInfo jvmInfo = info == null ? null : info.getInfo(JvmInfo.class);
JvmStats jvmStats = stats == null ? null : stats.getJvm();
FsInfo fsInfo = stats == null ? null : stats.getFs();
OsStats osStats = stats == null ? null : stats.getOs();
ProcessStats processStats = stats == null ? null : stats.getProcess();
NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices();
table.startRow();
table.addCell(fullId ? node.getId() : Strings.substring(node.getId(), 0, 4));
table.addCell(info == null ? null : info.getInfo(ProcessInfo.class).getId());
table.addCell(node.getHostAddress());
table.addCell(node.getAddress().address().getPort());
final HttpInfo httpInfo = info == null ? null : info.getInfo(HttpInfo.class);
if (httpInfo != null) {
TransportAddress transportAddress = httpInfo.getAddress().publishAddress();
table.addCell(NetworkAddress.format(transportAddress.address()));
} else {
table.addCell("-");
}
table.addCell(node.getVersion().toString());
table.addCell(info == null ? null : info.getBuild().type().displayName());
table.addCell(info == null ? null : info.getBuild().hash());
table.addCell(jvmInfo == null ? null : jvmInfo.version());
ByteSizeValue diskTotal = null;
ByteSizeValue diskUsed = null;
ByteSizeValue diskAvailable = null;
String diskUsedPercent = null;
if (fsInfo != null) {
diskTotal = fsInfo.getTotal().getTotal();
diskAvailable = fsInfo.getTotal().getAvailable();
diskUsed = new ByteSizeValue(diskTotal.getBytes() - diskAvailable.getBytes());
double diskUsedRatio = diskTotal.getBytes() == 0 ? 1.0 : (double) diskUsed.getBytes() / diskTotal.getBytes();
diskUsedPercent = String.format(Locale.ROOT, "%.2f", 100.0 * diskUsedRatio);
}
table.addCell(diskTotal);
table.addCell(diskUsed);
table.addCell(diskAvailable);
table.addCell(diskUsedPercent);
table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed());
table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsedPercent());
table.addCell(jvmInfo == null ? null : jvmInfo.getMem().getHeapMax());
table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsed());
table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsedPercent());
table.addCell(osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getTotal());
table.addCell(processStats == null ? null : processStats.getOpenFileDescriptors());
table.addCell(processStats == null ? null : calculatePercentage(processStats.getOpenFileDescriptors(), processStats.getMaxFileDescriptors()));
table.addCell(processStats == null ? null : processStats.getMaxFileDescriptors());
table.addCell(osStats == null ? null : Short.toString(osStats.getCpu().getPercent()));
boolean hasLoadAverage = osStats != null && osStats.getCpu().getLoadAverage() != null;
table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[0] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[0]));
table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[1] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[1]));
table.addCell(!hasLoadAverage || osStats.getCpu().getLoadAverage()[2] == -1 ? null : String.format(Locale.ROOT, "%.2f", osStats.getCpu().getLoadAverage()[2]));
table.addCell(jvmStats == null ? null : jvmStats.getUptime());
final String roles;
if (node.getRoles().isEmpty()) {
roles = "-";
} else {
roles = node.getRoles().stream().map(DiscoveryNodeRole::roleNameAbbreviation).sorted().collect(Collectors.joining());
}
table.addCell(roles);
table.addCell(masterId == null ? "x" : masterId.equals(node.getId()) ? "*" : "-");
table.addCell(node.getName());
CompletionStats completionStats = indicesStats == null ? null : stats.getIndices().getCompletion();
table.addCell(completionStats == null ? null : completionStats.getSize());
FieldDataStats fdStats = indicesStats == null ? null : stats.getIndices().getFieldData();
table.addCell(fdStats == null ? null : fdStats.getMemorySize());
table.addCell(fdStats == null ? null : fdStats.getEvictions());
QueryCacheStats fcStats = indicesStats == null ? null : indicesStats.getQueryCache();
table.addCell(fcStats == null ? null : fcStats.getMemorySize());
table.addCell(fcStats == null ? null : fcStats.getEvictions());
table.addCell(fcStats == null ? null : fcStats.getHitCount());
table.addCell(fcStats == null ? null : fcStats.getMissCount());
RequestCacheStats qcStats = indicesStats == null ? null : indicesStats.getRequestCache();
table.addCell(qcStats == null ? null : qcStats.getMemorySize());
table.addCell(qcStats == null ? null : qcStats.getEvictions());
table.addCell(qcStats == null ? null : qcStats.getHitCount());
table.addCell(qcStats == null ? null : qcStats.getMissCount());
FlushStats flushStats = indicesStats == null ? null : indicesStats.getFlush();
table.addCell(flushStats == null ? null : flushStats.getTotal());
table.addCell(flushStats == null ? null : flushStats.getTotalTime());
GetStats getStats = indicesStats == null ? null : indicesStats.getGet();
table.addCell(getStats == null ? null : getStats.current());
table.addCell(getStats == null ? null : getStats.getTime());
table.addCell(getStats == null ? null : getStats.getCount());
table.addCell(getStats == null ? null : getStats.getExistsTime());
table.addCell(getStats == null ? null : getStats.getExistsCount());
table.addCell(getStats == null ? null : getStats.getMissingTime());
table.addCell(getStats == null ? null : getStats.getMissingCount());
IndexingStats indexingStats = indicesStats == null ? null : indicesStats.getIndexing();
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCurrent());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteTime());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCount());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCurrent());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexTime());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCount());
table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexFailedCount());
MergeStats mergeStats = indicesStats == null ? null : indicesStats.getMerge();
table.addCell(mergeStats == null ? null : mergeStats.getCurrent());
table.addCell(mergeStats == null ? null : mergeStats.getCurrentNumDocs());
table.addCell(mergeStats == null ? null : mergeStats.getCurrentSize());
table.addCell(mergeStats == null ? null : mergeStats.getTotal());
table.addCell(mergeStats == null ? null : mergeStats.getTotalNumDocs());
table.addCell(mergeStats == null ? null : mergeStats.getTotalSize());
table.addCell(mergeStats == null ? null : mergeStats.getTotalTime());
RefreshStats refreshStats = indicesStats == null ? null : indicesStats.getRefresh();
table.addCell(refreshStats == null ? null : refreshStats.getTotal());
table.addCell(refreshStats == null ? null : refreshStats.getTotalTime());
table.addCell(refreshStats == null ? null : refreshStats.getExternalTotal());
table.addCell(refreshStats == null ? null : refreshStats.getExternalTotalTime());
table.addCell(refreshStats == null ? null : refreshStats.getListeners());
ScriptStats scriptStats = stats == null ? null : stats.getScriptStats();
table.addCell(scriptStats == null ? null : scriptStats.getCompilations());
table.addCell(scriptStats == null ? null : scriptStats.getCacheEvictions());
table.addCell(scriptStats == null ? null : scriptStats.getCompilationLimitTriggered());
SearchStats searchStats = indicesStats == null ? null : indicesStats.getSearch();
table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCurrent());
table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchTime());
table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCount());
table.addCell(searchStats == null ? null : searchStats.getOpenContexts());
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCurrent());
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryTime());
table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCount());
table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCurrent());
table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollTime());
table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCount());
SegmentsStats segmentsStats = indicesStats == null ? null : indicesStats.getSegments();
table.addCell(segmentsStats == null ? null : segmentsStats.getCount());
table.addCell(segmentsStats == null ? null : segmentsStats.getZeroMemory());
table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMemory());
table.addCell(segmentsStats == null ? null : segmentsStats.getVersionMapMemory());
table.addCell(segmentsStats == null ? null : segmentsStats.getBitsetMemory());
table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestCurrent());
table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestTime());
table.addCell(searchStats == null ? null : searchStats.getTotal().getSuggestCount());
table.endRow();
}
return table;
}
Aggregations