-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding concurrent search versions of query count and time metrics
Signed-off-by: Jay Deng <[email protected]>
- Loading branch information
Showing
11 changed files
with
364 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
97 changes: 94 additions & 3 deletions
97
rest-api-spec/src/main/resources/rest-api-spec/test/cat.shards/10_basic.yml
This file contains 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
This file contains 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
128 changes: 128 additions & 0 deletions
128
server/src/internalClusterTest/java/org/opensearch/search/stats/ConcurrentSearchStatsIT.java
This file contains 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,128 @@ | ||
/* | ||
* 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.stats.IndicesStatsRequestBuilder; | ||
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.index.IndexModule; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.indices.IndicesQueryCache; | ||
import org.opensearch.indices.IndicesService; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.script.Script; | ||
import org.opensearch.script.ScriptType; | ||
import org.opensearch.search.SearchTimeoutIT; | ||
import org.opensearch.test.InternalSettingsPlugin; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import static org.opensearch.index.query.QueryBuilders.scriptQuery; | ||
import static org.opensearch.search.SearchTimeoutIT.ScriptedDelayedPlugin.SCRIPT_NAME; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.lessThan; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2, numClientNodes = 0) | ||
public class ConcurrentSearchStatsIT extends OpenSearchIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(SearchTimeoutIT.ScriptedDelayedPlugin.class, InternalSettingsPlugin.class); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
// Filter/Query cache is cleaned periodically, default is 60s, so make sure it runs often. Thread.sleep for 60s is bad | ||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put(IndicesService.INDICES_CACHE_CLEAN_INTERVAL_SETTING.getKey(), "1ms") | ||
.put(IndicesQueryCache.INDICES_QUERIES_CACHE_ALL_SEGMENTS_SETTING.getKey(), true) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Settings indexSettings() { | ||
return Settings.builder() | ||
.put(super.indexSettings()) | ||
.put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), false) | ||
.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false) | ||
.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), 0) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.CONCURRENT_SEGMENT_SEARCH, "true").build(); | ||
} | ||
|
||
public void testConcurrentQueryCount() throws Exception { | ||
int NUM_SHARDS = randomIntBetween(1, 5); | ||
createIndex( | ||
"test1", | ||
Settings.builder() | ||
.put(indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, NUM_SHARDS) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.build() | ||
); | ||
createIndex( | ||
"test2", | ||
Settings.builder() | ||
.put(indexSettings()) | ||
.put("search.concurrent_segment_search.enabled", false) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, NUM_SHARDS) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
.build() | ||
); | ||
|
||
ensureGreen(); | ||
|
||
indexRandom( | ||
false, | ||
true, | ||
client().prepareIndex("test1").setId("1").setSource("foo", "bar"), | ||
client().prepareIndex("test1").setId("2").setSource("foo", "baz"), | ||
client().prepareIndex("test2").setId("1").setSource("foo", "bar"), | ||
client().prepareIndex("test2").setId("2").setSource("foo", "baz") | ||
); | ||
|
||
refresh(); | ||
|
||
// Search with custom plugin to ensure that queryTime is significant | ||
client().prepareSearch("_all") | ||
.setQuery(scriptQuery(new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap()))) | ||
.execute() | ||
.actionGet(); | ||
client().prepareSearch("test1") | ||
.setQuery(scriptQuery(new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap()))) | ||
.execute() | ||
.actionGet(); | ||
client().prepareSearch("test2") | ||
.setQuery(scriptQuery(new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap()))) | ||
.execute() | ||
.actionGet(); | ||
|
||
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats(); | ||
IndicesStatsResponse stats = builder.execute().actionGet(); | ||
|
||
assertEquals(4 * NUM_SHARDS, stats.getTotal().search.getTotal().getQueryCount()); | ||
assertEquals(2 * NUM_SHARDS, stats.getTotal().search.getTotal().getConcurrentQueryCount()); | ||
assertThat(stats.getTotal().search.getTotal().getQueryTimeInMillis(), greaterThan(0L)); | ||
assertThat(stats.getTotal().search.getTotal().getConcurrentQueryTimeInMillis(), greaterThan(0L)); | ||
assertThat( | ||
stats.getTotal().search.getTotal().getConcurrentQueryTimeInMillis(), | ||
lessThan(stats.getTotal().search.getTotal().getQueryTimeInMillis()) | ||
); | ||
} | ||
} |
Oops, something went wrong.