-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Star-Tree] Search level stats for nodes, indices and shards #18707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83956e7
startree node,indices,shards stats
sandeshkr419 2b6cdba
changing to builder pattern
sandeshkr419 078cded
add query current, fix version
sandeshkr419 e9201d4
fix version
sandeshkr419 563e7aa
add integ test
sandeshkr419 7218ea6
typo
sandeshkr419 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 101 additions & 3 deletions
104
rest-api-spec/src/main/resources/rest-api-spec/test/cat.shards/10_basic.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
server/src/internalClusterTest/java/org/opensearch/search/stats/StarTreeSearchStatsIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.search.stats; | ||
|
|
||
| import org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest; | ||
| import org.opensearch.action.admin.indices.stats.IndicesStatsResponse; | ||
| import org.opensearch.action.search.SearchResponse; | ||
| import org.opensearch.cluster.metadata.IndexMetadata; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.common.xcontent.XContentFactory; | ||
| import org.opensearch.index.search.stats.SearchStats; | ||
| import org.opensearch.search.aggregations.AggregationBuilders; | ||
| import org.opensearch.search.aggregations.bucket.terms.Terms; | ||
| import org.opensearch.search.aggregations.metrics.Sum; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
|
||
| import static org.opensearch.index.query.QueryBuilders.matchAllQuery; | ||
| import static org.opensearch.index.query.QueryBuilders.termQuery; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
| import static org.hamcrest.Matchers.lessThan; | ||
|
|
||
| /** | ||
| * Integration tests for search statistics related to star-tree. | ||
| */ | ||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE) | ||
| public class StarTreeSearchStatsIT extends OpenSearchIntegTestCase { | ||
|
|
||
| private static final String STARTREE_INDEX_NAME = "test_startree"; | ||
| private static final String REGULAR_INDEX_NAME = "test_regular"; | ||
|
|
||
| /** | ||
| * This test validates that star-tree specific search stats are correctly reported. | ||
| * It creates two indices: one with a star-tree field and one without. | ||
| * It then runs queries that should and should not be offloaded to the star-tree | ||
| * and verifies the star-tree related stats. | ||
| */ | ||
| public void testStarTreeQueryStats() throws Exception { | ||
| // Create an index with a star-tree field mapping using the composite structure | ||
| createIndex( | ||
| STARTREE_INDEX_NAME, | ||
| Settings.builder() | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put("index.composite_index", true) | ||
| .put("index.append_only.enabled", true) | ||
| .put("index.search.star_tree_index.enabled", true) | ||
| .put("index.codec", "default") | ||
| .build(), | ||
| XContentFactory.jsonBuilder() | ||
| .startObject() | ||
| .startObject("composite") | ||
| .startObject("my_star_tree") | ||
| .field("type", "star_tree") | ||
| .startObject("config") | ||
| .startArray("ordered_dimensions") | ||
| .startObject() | ||
| .field("name", "product") | ||
| .endObject() | ||
| .startObject() | ||
| .field("name", "size") | ||
| .endObject() | ||
| .endArray() | ||
| .startArray("metrics") | ||
| .startObject() | ||
| .field("name", "sales") | ||
| .field("stats", new String[] { "sum" }) | ||
| .endObject() | ||
| .endArray() | ||
| .endObject() | ||
| .endObject() | ||
| .endObject() | ||
| .startObject("properties") | ||
| .startObject("product") | ||
| .field("type", "keyword") | ||
| .endObject() | ||
| .startObject("size") | ||
| .field("type", "keyword") | ||
| .endObject() | ||
| .startObject("sales") | ||
| .field("type", "double") | ||
| .endObject() | ||
| .startObject("non_dimension_field") | ||
| .field("type", "text") | ||
| .endObject() | ||
| .endObject() | ||
| .endObject() | ||
| .toString() | ||
| ); | ||
|
|
||
| // Create an index without a star-tree | ||
| createIndex( | ||
| REGULAR_INDEX_NAME, | ||
| Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build() | ||
| ); | ||
| ensureGreen(STARTREE_INDEX_NAME, REGULAR_INDEX_NAME); | ||
|
|
||
| client().prepareIndex(STARTREE_INDEX_NAME) | ||
| .setSource("product", "laptop", "sales", 1200.0, "non_dimension_field", "some text", "size", "18") | ||
| .get(); | ||
| client().prepareIndex(STARTREE_INDEX_NAME) | ||
| .setSource("product", "keyboard", "sales", 150.0, "non_dimension_field", "more text", "size", "12") | ||
| .get(); | ||
| client().prepareIndex(REGULAR_INDEX_NAME).setSource("product", "monitor", "sales", 400.0).get(); | ||
|
|
||
| // Force merge the star-tree index to ensure star-tree segments are created | ||
| client().admin().indices().forceMerge(new ForceMergeRequest(STARTREE_INDEX_NAME).maxNumSegments(1)).get(); | ||
| refresh(); | ||
|
|
||
| // Query 1: This query should be answered by the star-tree. | ||
| // It's an aggregation on a dimension with a metric sub-aggregation and size=0. | ||
| SearchResponse starTreeResponse = client().prepareSearch(STARTREE_INDEX_NAME) | ||
| .setQuery(matchAllQuery()) | ||
| .addAggregation( | ||
| AggregationBuilders.terms("products").field("product").subAggregation(AggregationBuilders.sum("total_sales").field("sales")) | ||
| ) | ||
| .setSize(0) | ||
| .execute() | ||
| .actionGet(); | ||
| assertEquals(2, starTreeResponse.getHits().getTotalHits().value()); | ||
| Terms terms = starTreeResponse.getAggregations().get("products"); | ||
| assertEquals(2, terms.getBuckets().size()); | ||
| Sum sum = terms.getBuckets().get(0).getAggregations().get("total_sales"); | ||
| assertNotNull(sum); | ||
|
|
||
| // Query 2: This query should NOT be answered by the star-tree as it queries a non-dimension field. | ||
| client().prepareSearch(STARTREE_INDEX_NAME).setQuery(termQuery("non_dimension_field", "text")).execute().actionGet(); | ||
|
|
||
| // Query 3: A standard query on the regular index. | ||
| client().prepareSearch(REGULAR_INDEX_NAME).setQuery(matchAllQuery()).get(); | ||
|
|
||
| // Fetch index statistics | ||
| IndicesStatsResponse stats = client().admin().indices().prepareStats(STARTREE_INDEX_NAME, REGULAR_INDEX_NAME).setSearch(true).get(); | ||
|
|
||
| // Assertions for the star-tree index | ||
| SearchStats.Stats starTreeIndexStats = stats.getIndex(STARTREE_INDEX_NAME).getTotal().getSearch().getTotal(); | ||
|
|
||
| assertThat("Star-tree index should have 2 total queries", starTreeIndexStats.getQueryCount(), equalTo(2L)); | ||
| assertThat("Star-tree index should have 1 star-tree query", starTreeIndexStats.getStarTreeQueryCount(), equalTo(1L)); | ||
| assertThat( | ||
| "Star-tree query time should be non-negative", | ||
| starTreeIndexStats.getStarTreeQueryTimeInMillis(), | ||
| greaterThanOrEqualTo(0L) | ||
| ); | ||
| assertThat( | ||
| "Star-tree query current should be non-negative", | ||
| starTreeIndexStats.getStarTreeQueryCurrent(), | ||
| greaterThanOrEqualTo(0L) | ||
| ); | ||
|
|
||
| // Assertions for the regular index | ||
| SearchStats.Stats regularIndexStats = stats.getIndex(REGULAR_INDEX_NAME).getTotal().getSearch().getTotal(); | ||
| assertThat("Regular index should have 1 total query", regularIndexStats.getQueryCount(), equalTo(1L)); | ||
| assertThat("Regular index should have 0 star-tree queries", regularIndexStats.getStarTreeQueryCount(), equalTo(0L)); | ||
| assertThat("Regular index should have 0 star-tree query time", regularIndexStats.getStarTreeQueryTimeInMillis(), equalTo(0L)); | ||
|
|
||
| // Assertions for the total stats across both indices | ||
| SearchStats.Stats totalStats = stats.getTotal().getSearch().getTotal(); | ||
| assertThat("Total query count should be 3", totalStats.getQueryCount(), equalTo(3L)); | ||
| assertThat("Total star-tree query count should be 1", totalStats.getStarTreeQueryCount(), equalTo(1L)); | ||
| assertThat(totalStats.getQueryTimeInMillis(), greaterThanOrEqualTo(totalStats.getStarTreeQueryTimeInMillis())); | ||
|
|
||
| // While not guaranteed, the time spent on the single star-tree query should be less than the total query time. | ||
| if (totalStats.getStarTreeQueryCount() > 0 && totalStats.getQueryCount() > totalStats.getStarTreeQueryCount()) { | ||
| assertThat( | ||
| "Star-tree query time should be less than total query time", | ||
| totalStats.getStarTreeQueryTimeInMillis(), | ||
| lessThan(totalStats.getQueryTimeInMillis()) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.