Search in sources :

Example 6 with CompletionStats

use of org.opensearch.search.suggest.completion.CompletionStats in project OpenSearch by opensearch-project.

the class CompletionsStatsTests method testSerialize.

public void testSerialize() throws IOException {
    FieldMemoryStats map = randomBoolean() ? null : FieldMemoryStatsTests.randomFieldMemoryStats();
    CompletionStats stats = new CompletionStats(randomNonNegativeLong(), map);
    BytesStreamOutput out = new BytesStreamOutput();
    stats.writeTo(out);
    StreamInput input = out.bytes().streamInput();
    CompletionStats read = new CompletionStats(input);
    assertEquals(-1, input.read());
    assertEquals(stats.getSizeInBytes(), read.getSizeInBytes());
    assertEquals(stats.getFields(), read.getFields());
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) FieldMemoryStats(org.opensearch.common.FieldMemoryStats) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats)

Example 7 with CompletionStats

use of org.opensearch.search.suggest.completion.CompletionStats in project OpenSearch by opensearch-project.

the class RestShardsAction method buildTable.

// package private for testing
Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsResponse stats) {
    Table table = getTableWithHeader(request);
    for (ShardRouting shard : state.getState().routingTable().allShards()) {
        ShardStats shardStats = stats.asMap().get(shard);
        CommonStats commonStats = null;
        CommitStats commitStats = null;
        if (shardStats != null) {
            commonStats = shardStats.getStats();
            commitStats = shardStats.getCommitStats();
        }
        table.startRow();
        table.addCell(shard.getIndexName());
        table.addCell(shard.id());
        if (shard.primary()) {
            table.addCell("p");
        } else {
            table.addCell("r");
        }
        table.addCell(shard.state());
        table.addCell(getOrNull(commonStats, CommonStats::getDocs, DocsStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getStore, StoreStats::getSize));
        if (shard.assignedToNode()) {
            String ip = state.getState().nodes().get(shard.currentNodeId()).getHostAddress();
            String nodeId = shard.currentNodeId();
            StringBuilder name = new StringBuilder();
            name.append(state.getState().nodes().get(shard.currentNodeId()).getName());
            if (shard.relocating()) {
                String reloIp = state.getState().nodes().get(shard.relocatingNodeId()).getHostAddress();
                String reloNme = state.getState().nodes().get(shard.relocatingNodeId()).getName();
                String reloNodeId = shard.relocatingNodeId();
                name.append(" -> ");
                name.append(reloIp);
                name.append(" ");
                name.append(reloNodeId);
                name.append(" ");
                name.append(reloNme);
            }
            table.addCell(ip);
            table.addCell(nodeId);
            table.addCell(name);
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        table.addCell(commitStats == null ? null : commitStats.getUserData().get(Engine.SYNC_COMMIT_ID));
        if (shard.unassignedInfo() != null) {
            table.addCell(shard.unassignedInfo().getReason());
            Instant unassignedTime = Instant.ofEpochMilli(shard.unassignedInfo().getUnassignedTimeInMillis());
            table.addCell(UnassignedInfo.DATE_TIME_FORMATTER.format(unassignedTime));
            table.addCell(TimeValue.timeValueMillis(System.currentTimeMillis() - shard.unassignedInfo().getUnassignedTimeInMillis()));
            table.addCell(shard.unassignedInfo().getDetails());
        } else {
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
            table.addCell(null);
        }
        if (shard.recoverySource() != null) {
            table.addCell(shard.recoverySource().getType().toString().toLowerCase(Locale.ROOT));
        } else {
            table.addCell(null);
        }
        table.addCell(getOrNull(commonStats, CommonStats::getCompletion, CompletionStats::getSize));
        table.addCell(getOrNull(commonStats, CommonStats::getFieldData, FieldDataStats::getMemorySize));
        table.addCell(getOrNull(commonStats, CommonStats::getFieldData, FieldDataStats::getEvictions));
        table.addCell(getOrNull(commonStats, CommonStats::getQueryCache, QueryCacheStats::getMemorySize));
        table.addCell(getOrNull(commonStats, CommonStats::getQueryCache, QueryCacheStats::getEvictions));
        table.addCell(getOrNull(commonStats, CommonStats::getFlush, FlushStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getFlush, FlushStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::current));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getExistsTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getExistsCount));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getMissingTime));
        table.addCell(getOrNull(commonStats, CommonStats::getGet, GetStats::getMissingCount));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getDeleteCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getIndexing, i -> i.getTotal().getIndexFailedCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrent));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrentNumDocs));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getCurrentSize));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalNumDocs));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalSize));
        table.addCell(getOrNull(commonStats, CommonStats::getMerge, MergeStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getExternalTotal));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getExternalTotalTime));
        table.addCell(getOrNull(commonStats, CommonStats::getRefresh, RefreshStats::getListeners));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getFetchCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, SearchStats::getOpenContexts));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getQueryCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollCurrent()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollTime()));
        table.addCell(getOrNull(commonStats, CommonStats::getSearch, i -> i.getTotal().getScrollCount()));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getCount));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getZeroMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getIndexWriterMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getVersionMapMemory));
        table.addCell(getOrNull(commonStats, CommonStats::getSegments, SegmentsStats::getBitsetMemory));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getMaxSeqNo));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getLocalCheckpoint));
        table.addCell(getOrNull(shardStats, ShardStats::getSeqNoStats, SeqNoStats::getGlobalCheckpoint));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::current));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::total));
        table.addCell(getOrNull(commonStats, CommonStats::getWarmer, WarmerStats::totalTime));
        table.addCell(getOrNull(shardStats, ShardStats::getDataPath, s -> s));
        table.addCell(getOrNull(shardStats, ShardStats::getStatePath, s -> s));
        table.endRow();
    }
    return table;
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) SeqNoStats(org.opensearch.index.seqno.SeqNoStats) Collections.unmodifiableList(java.util.Collections.unmodifiableList) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) SearchStats(org.opensearch.index.search.stats.SearchStats) Table(org.opensearch.common.Table) Function(java.util.function.Function) Strings(org.opensearch.common.Strings) MergeStats(org.opensearch.index.merge.MergeStats) RestActionListener(org.opensearch.rest.action.RestActionListener) RefreshStats(org.opensearch.index.refresh.RefreshStats) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) SegmentsStats(org.opensearch.index.engine.SegmentsStats) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) StoreStats(org.opensearch.index.store.StoreStats) CommitStats(org.opensearch.index.engine.CommitStats) RestResponseListener(org.opensearch.rest.action.RestResponseListener) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) DocsStats(org.opensearch.index.shard.DocsStats) FlushStats(org.opensearch.index.flush.FlushStats) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest) Instant(java.time.Instant) GetStats(org.opensearch.index.get.GetStats) RestResponse(org.opensearch.rest.RestResponse) WarmerStats(org.opensearch.index.warmer.WarmerStats) ShardRouting(org.opensearch.cluster.routing.ShardRouting) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) Engine(org.opensearch.index.engine.Engine) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) Table(org.opensearch.common.Table) CommitStats(org.opensearch.index.engine.CommitStats) Instant(java.time.Instant) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Example 8 with CompletionStats

use of org.opensearch.search.suggest.completion.CompletionStats in project OpenSearch by opensearch-project.

the class TransportRolloverActionTests method randomIndicesStatsResponse.

public static IndicesStatsResponse randomIndicesStatsResponse(final IndexMetadata[] indices) {
    List<ShardStats> shardStats = new ArrayList<>();
    for (final IndexMetadata index : indices) {
        int numShards = randomIntBetween(1, 3);
        // -1 means there is no primary shard.
        int primaryIdx = randomIntBetween(-1, numShards - 1);
        for (int i = 0; i < numShards; i++) {
            ShardId shardId = new ShardId(index.getIndex(), i);
            boolean primary = (i == primaryIdx);
            Path path = createTempDir().resolve("indices").resolve(index.getIndexUUID()).resolve(String.valueOf(i));
            ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, primary, primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
            shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
            shardRouting = shardRouting.moveToStarted();
            CommonStats stats = new CommonStats();
            stats.fieldData = new FieldDataStats();
            stats.queryCache = new QueryCacheStats();
            stats.docs = new DocsStats();
            stats.store = new StoreStats();
            stats.indexing = new IndexingStats();
            stats.search = new SearchStats();
            stats.segments = new SegmentsStats();
            stats.merge = new MergeStats();
            stats.refresh = new RefreshStats();
            stats.completion = new CompletionStats();
            stats.requestCache = new RequestCacheStats();
            stats.get = new GetStats();
            stats.flush = new FlushStats();
            stats.warmer = new WarmerStats();
            shardStats.add(new ShardStats(shardRouting, new ShardPath(false, path, path, shardId), stats, null, null, null));
        }
    }
    return IndicesStatsTests.newIndicesStatsResponse(shardStats.toArray(new ShardStats[shardStats.size()]), shardStats.size(), shardStats.size(), 0, emptyList());
}
Also used : StoreStats(org.opensearch.index.store.StoreStats) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) RefreshStats(org.opensearch.index.refresh.RefreshStats) ArrayList(java.util.ArrayList) GetStats(org.opensearch.index.get.GetStats) SegmentsStats(org.opensearch.index.engine.SegmentsStats) ShardId(org.opensearch.index.shard.ShardId) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) FlushStats(org.opensearch.index.flush.FlushStats) ShardPath(org.opensearch.index.shard.ShardPath) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) DocsStats(org.opensearch.index.shard.DocsStats) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) Path(java.nio.file.Path) ShardPath(org.opensearch.index.shard.ShardPath) IndexingStats(org.opensearch.index.shard.IndexingStats) WarmerStats(org.opensearch.index.warmer.WarmerStats) SearchStats(org.opensearch.index.search.stats.SearchStats) MergeStats(org.opensearch.index.merge.MergeStats) ShardRouting(org.opensearch.cluster.routing.ShardRouting) RequestCacheStats(org.opensearch.index.cache.request.RequestCacheStats) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats)

Example 9 with CompletionStats

use of org.opensearch.search.suggest.completion.CompletionStats 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;
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) RefreshStats(org.opensearch.index.refresh.RefreshStats) TransportAddress(org.opensearch.common.transport.TransportAddress) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) GetStats(org.opensearch.index.get.GetStats) SegmentsStats(org.opensearch.index.engine.SegmentsStats) HttpInfo(org.opensearch.http.HttpInfo) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) FsInfo(org.opensearch.monitor.fs.FsInfo) FlushStats(org.opensearch.index.flush.FlushStats) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) ScriptStats(org.opensearch.script.ScriptStats) ProcessStats(org.opensearch.monitor.process.ProcessStats) Table(org.opensearch.common.Table) IndexingStats(org.opensearch.index.shard.IndexingStats) OsStats(org.opensearch.monitor.os.OsStats) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) SearchStats(org.opensearch.index.search.stats.SearchStats) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) MergeStats(org.opensearch.index.merge.MergeStats) NodeIndicesStats(org.opensearch.indices.NodeIndicesStats) RequestCacheStats(org.opensearch.index.cache.request.RequestCacheStats) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats)

Example 10 with CompletionStats

use of org.opensearch.search.suggest.completion.CompletionStats in project OpenSearch by opensearch-project.

the class CompletionStatsCacheTests method testCompletionStatsCache.

public void testCompletionStatsCache() throws IOException, InterruptedException {
    final IndexWriterConfig indexWriterConfig = newIndexWriterConfig();
    final PostingsFormat postingsFormat = new Completion84PostingsFormat();
    indexWriterConfig.setCodec(new Lucene87Codec() {

        @Override
        public PostingsFormat getPostingsFormatForField(String field) {
            // all fields are suggest fields
            return postingsFormat;
        }
    });
    final QueryCachingPolicy queryCachingPolicy = new QueryCachingPolicy() {

        @Override
        public void onUse(Query query) {
        }

        @Override
        public boolean shouldCache(Query query) {
            return false;
        }
    };
    try (Directory directory = newDirectory();
        IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig)) {
        final Document document = new Document();
        document.add(new SuggestField("suggest1", "val", 1));
        document.add(new SuggestField("suggest2", "val", 1));
        document.add(new SuggestField("suggest2", "anotherval", 1));
        document.add(new SuggestField("otherfield", "val", 1));
        document.add(new SuggestField("otherfield", "anotherval", 1));
        document.add(new SuggestField("otherfield", "yetmoreval", 1));
        indexWriter.addDocument(document);
        final OpenCloseCounter openCloseCounter = new OpenCloseCounter();
        final CompletionStatsCache completionStatsCache = new CompletionStatsCache(() -> {
            openCloseCounter.countOpened();
            try {
                final DirectoryReader directoryReader = DirectoryReader.open(indexWriter);
                return new Engine.Searcher("test", directoryReader, null, null, queryCachingPolicy, () -> {
                    openCloseCounter.countClosed();
                    IOUtils.close(directoryReader);
                });
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        });
        final int threadCount = 6;
        final TestHarness testHarness = new TestHarness(completionStatsCache, threadCount);
        final Thread[] threads = new Thread[threadCount];
        threads[0] = new Thread(() -> testHarness.getStats(0, "*"));
        threads[1] = new Thread(() -> testHarness.getStats(1, "suggest1", "suggest2"));
        threads[2] = new Thread(() -> testHarness.getStats(2, "sug*"));
        threads[3] = new Thread(() -> testHarness.getStats(3, "no match*"));
        threads[4] = new Thread(() -> testHarness.getStats(4));
        threads[5] = new Thread(() -> testHarness.getStats(5, (String[]) null));
        for (Thread thread : threads) {
            thread.start();
        }
        testHarness.start();
        for (Thread thread : threads) {
            thread.join();
        }
        // 0: "*" should match all fields:
        final long suggest1Size = testHarness.getResult(0).getFields().get("suggest1");
        final long suggest2Size = testHarness.getResult(0).getFields().get("suggest2");
        final long otherFieldSize = testHarness.getResult(0).getFields().get("otherfield");
        final long totalSizeInBytes = testHarness.getResult(0).getSizeInBytes();
        assertThat(suggest1Size, greaterThan(0L));
        assertThat(suggest2Size, greaterThan(0L));
        assertThat(otherFieldSize, greaterThan(0L));
        assertThat(totalSizeInBytes, equalTo(suggest1Size + suggest2Size + otherFieldSize));
        // 1: enumerating fields omits the other ones
        assertThat(testHarness.getResult(1).getSizeInBytes(), equalTo(totalSizeInBytes));
        assertThat(testHarness.getResult(1).getFields().get("suggest1"), equalTo(suggest1Size));
        assertThat(testHarness.getResult(1).getFields().get("suggest2"), equalTo(suggest2Size));
        assertFalse(testHarness.getResult(1).getFields().containsField("otherfield"));
        // 2: wildcards also exclude some fields
        assertThat(testHarness.getResult(2).getSizeInBytes(), equalTo(totalSizeInBytes));
        assertThat(testHarness.getResult(2).getFields().get("suggest1"), equalTo(suggest1Size));
        assertThat(testHarness.getResult(2).getFields().get("suggest2"), equalTo(suggest2Size));
        assertFalse(testHarness.getResult(2).getFields().containsField("otherfield"));
        // 3: non-matching wildcard returns empty set of fields
        assertThat(testHarness.getResult(3).getSizeInBytes(), equalTo(totalSizeInBytes));
        assertFalse(testHarness.getResult(3).getFields().containsField("suggest1"));
        assertFalse(testHarness.getResult(3).getFields().containsField("suggest2"));
        assertFalse(testHarness.getResult(3).getFields().containsField("otherfield"));
        // 4: no fields means per-fields stats is null
        assertThat(testHarness.getResult(4).getSizeInBytes(), equalTo(totalSizeInBytes));
        assertNull(testHarness.getResult(4).getFields());
        // 5: null fields means per-fields stats is null
        assertThat(testHarness.getResult(5).getSizeInBytes(), equalTo(totalSizeInBytes));
        assertNull(testHarness.getResult(5).getFields());
        // the stats were only computed once
        openCloseCounter.assertCount(1);
        // the stats are not recomputed on a refresh
        completionStatsCache.afterRefresh(true);
        openCloseCounter.assertCount(1);
        // but they are recomputed on the next get
        completionStatsCache.get();
        openCloseCounter.assertCount(2);
        // and they do update
        final Document document2 = new Document();
        document2.add(new SuggestField("suggest1", "foo", 1));
        document2.add(new SuggestField("suggest2", "bar", 1));
        document2.add(new SuggestField("otherfield", "baz", 1));
        indexWriter.addDocument(document2);
        completionStatsCache.afterRefresh(true);
        final CompletionStats updatedStats = completionStatsCache.get();
        assertThat(updatedStats.getSizeInBytes(), greaterThan(totalSizeInBytes));
        openCloseCounter.assertCount(3);
        // beforeRefresh does not invalidate the cache
        completionStatsCache.beforeRefresh();
        completionStatsCache.get();
        openCloseCounter.assertCount(3);
        // afterRefresh does not invalidate the cache if no refresh took place
        completionStatsCache.afterRefresh(false);
        completionStatsCache.get();
        openCloseCounter.assertCount(3);
    }
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) Completion84PostingsFormat(org.apache.lucene.search.suggest.document.Completion84PostingsFormat) SuggestField(org.apache.lucene.search.suggest.document.SuggestField) Query(org.apache.lucene.search.Query) DirectoryReader(org.apache.lucene.index.DirectoryReader) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) Lucene87Codec(org.apache.lucene.codecs.lucene87.Lucene87Codec) IndexWriter(org.apache.lucene.index.IndexWriter) Completion84PostingsFormat(org.apache.lucene.search.suggest.document.Completion84PostingsFormat) PostingsFormat(org.apache.lucene.codecs.PostingsFormat) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Directory(org.apache.lucene.store.Directory) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats)

Aggregations

CompletionStats (org.opensearch.search.suggest.completion.CompletionStats)10 QueryCacheStats (org.opensearch.index.cache.query.QueryCacheStats)5 SegmentsStats (org.opensearch.index.engine.SegmentsStats)5 FieldDataStats (org.opensearch.index.fielddata.FieldDataStats)5 FlushStats (org.opensearch.index.flush.FlushStats)5 GetStats (org.opensearch.index.get.GetStats)5 MergeStats (org.opensearch.index.merge.MergeStats)5 RefreshStats (org.opensearch.index.refresh.RefreshStats)5 SearchStats (org.opensearch.index.search.stats.SearchStats)5 FieldMemoryStats (org.opensearch.common.FieldMemoryStats)4 RequestCacheStats (org.opensearch.index.cache.request.RequestCacheStats)4 DocsStats (org.opensearch.index.shard.DocsStats)4 IndexingStats (org.opensearch.index.shard.IndexingStats)4 CommonStats (org.opensearch.action.admin.indices.stats.CommonStats)3 StoreStats (org.opensearch.index.store.StoreStats)3 WarmerStats (org.opensearch.index.warmer.WarmerStats)3 ObjectLongHashMap (com.carrotsearch.hppc.ObjectLongHashMap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)2