Skip to content

Commit

Permalink
Add concurrent search stats test into the QueryProfilerIT
Browse files Browse the repository at this point in the history
Signed-off-by: Ticheng Lin <ticheng@amazon.com>
  • Loading branch information
ticheng-aws committed Sep 1, 2023
1 parent a741f0a commit 6e3b3c8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

public class QueryProfilerIT extends ParameterizedOpenSearchIntegTestCase {
private final boolean concurrentSearchEnabled;
private static final String MAX_PREFIX = "max_";
private static final String MIN_PREFIX = "min_";
private static final String AVG_PREFIX = "avg_";
private static final String TIMING_TYPE_COUNT_SUFFIX = "_count";

public QueryProfilerIT(Settings settings) {
super(settings);
this.concurrentSearchEnabled = Boolean.parseBoolean(settings.get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey()));
}

@ParametersFactory
Expand Down Expand Up @@ -250,6 +258,7 @@ public void testSimpleMatch() throws Exception {
assertEquals(result.getLuceneDescription(), "field1:one");
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -292,6 +301,7 @@ public void testBool() throws Exception {
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertEquals(result.getProfiledChildren().size(), 2);
assertQueryProfileResult(result);

// Check the children
List<ProfileResult> children = result.getProfiledChildren();
Expand All @@ -303,12 +313,14 @@ public void testBool() throws Exception {
assertThat(childProfile.getTime(), greaterThan(0L));
assertNotNull(childProfile.getTimeBreakdown());
assertEquals(childProfile.getProfiledChildren().size(), 0);
assertQueryProfileResult(childProfile);

childProfile = children.get(1);
assertEquals(childProfile.getQueryName(), "TermQuery");
assertEquals(childProfile.getLuceneDescription(), "field1:two");
assertThat(childProfile.getTime(), greaterThan(0L));
assertNotNull(childProfile.getTimeBreakdown());
assertQueryProfileResult(childProfile);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -351,6 +363,7 @@ public void testEmptyBool() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -396,6 +409,7 @@ public void testCollapsingBool() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -436,6 +450,7 @@ public void testBoosting() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -476,6 +491,7 @@ public void testDisMaxRange() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -515,6 +531,7 @@ public void testRange() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -568,6 +585,7 @@ public void testPhrase() throws Exception {
assertNotNull(result.getLuceneDescription());
assertThat(result.getTime(), greaterThan(0L));
assertNotNull(result.getTimeBreakdown());
assertQueryProfileResult(result);
}

CollectorResult result = searchProfiles.getCollectorResult();
Expand Down Expand Up @@ -600,4 +618,35 @@ public void testNoProfile() throws Exception {
assertThat("Profile response element should be an empty map", resp.getProfileResults().size(), equalTo(0));
}

private void assertQueryProfileResult(ProfileResult result) {
Map<String, Long> breakdown = result.getTimeBreakdown();
Long maxSliceTime = result.getMaxSliceTime();
Long minSliceTime = result.getMinSliceTime();
Long avgSliceTime = result.getAvgSliceTime();
if (concurrentSearchEnabled) {
assertNotNull(maxSliceTime);
assertNotNull(minSliceTime);
assertNotNull(avgSliceTime);
assertThat(breakdown.size(), equalTo(66));
for (QueryTimingType queryTimingType : QueryTimingType.values()) {
if (queryTimingType != QueryTimingType.CREATE_WEIGHT) {
String maxTimingType = MAX_PREFIX + queryTimingType;
String minTimingType = MIN_PREFIX + queryTimingType;
String avgTimingType = AVG_PREFIX + queryTimingType;
assertNotNull(breakdown.get(maxTimingType));
assertNotNull(breakdown.get(minTimingType));
assertNotNull(breakdown.get(avgTimingType));
assertNotNull(breakdown.get(maxTimingType + TIMING_TYPE_COUNT_SUFFIX));
assertNotNull(breakdown.get(minTimingType + TIMING_TYPE_COUNT_SUFFIX));
assertNotNull(breakdown.get(avgTimingType + TIMING_TYPE_COUNT_SUFFIX));
}
}
} else {
assertThat(maxSliceTime, is(nullValue()));
assertThat(minSliceTime, is(nullValue()));
assertThat(avgSliceTime, is(nullValue()));
assertThat(breakdown.size(), equalTo(27));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import static org.mockito.Mockito.when;

public class QueryProfilerTests extends OpenSearchTestCase {
private final int concurrency;
private Directory dir;
private IndexReader reader;
private ContextIndexSearcher searcher;
Expand All @@ -105,7 +104,6 @@ public static Collection<Object[]> concurrency() {

public QueryProfilerTests(int concurrency) {
this.executor = (concurrency > 0) ? Executors.newFixedThreadPool(concurrency) : null;
this.concurrency = concurrency;
}

@Before
Expand Down Expand Up @@ -185,7 +183,7 @@ public void testBasic() throws IOException {
assertThat(breakdown.get(QueryTimingType.SCORE + TIMING_TYPE_COUNT_SUFFIX), greaterThan(0L));
assertThat(breakdown.get(QueryTimingType.MATCH + TIMING_TYPE_COUNT_SUFFIX), equalTo(0L));

if (concurrency > 0) {
if (executor != null) {
assertThat(profileResult.getMaxSliceTime(), is(not(nullValue())));
assertThat(profileResult.getMinSliceTime(), is(not(nullValue())));
assertThat(profileResult.getAvgSliceTime(), is(not(nullValue())));
Expand Down Expand Up @@ -252,7 +250,7 @@ public void testNoScoring() throws IOException {
assertThat(breakdown.get(QueryTimingType.SCORE + TIMING_TYPE_COUNT_SUFFIX), equalTo(0L));
assertThat(breakdown.get(QueryTimingType.MATCH + TIMING_TYPE_COUNT_SUFFIX), equalTo(0L));

if (concurrency > 0) {
if (executor != null) {
assertThat(profileResult.getMaxSliceTime(), is(not(nullValue())));
assertThat(profileResult.getMinSliceTime(), is(not(nullValue())));
assertThat(profileResult.getAvgSliceTime(), is(not(nullValue())));
Expand Down Expand Up @@ -333,7 +331,7 @@ public void testApproximations() throws IOException {
assertThat(breakdown.get(QueryTimingType.SCORE + TIMING_TYPE_COUNT_SUFFIX), equalTo(0L));
assertThat(breakdown.get(QueryTimingType.MATCH + TIMING_TYPE_COUNT_SUFFIX), greaterThan(0L));

if (concurrency > 0) {
if (executor != null) {
assertThat(profileResult.getMaxSliceTime(), is(not(nullValue())));
assertThat(profileResult.getMinSliceTime(), is(not(nullValue())));
assertThat(profileResult.getAvgSliceTime(), is(not(nullValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import static org.mockito.Mockito.when;

public class QueryProfilePhaseTests extends IndexShardTestCase {
private final int concurrency;
private IndexShard indexShard;
private final ExecutorService executor;
private final QueryPhaseSearcher queryPhaseSearcher;
Expand All @@ -113,7 +112,6 @@ public static Collection<Object[]> concurrency() {
public QueryProfilePhaseTests(int concurrency, QueryPhaseSearcher queryPhaseSearcher) {
this.executor = (concurrency > 0) ? Executors.newFixedThreadPool(concurrency) : null;
this.queryPhaseSearcher = queryPhaseSearcher;
this.concurrency = concurrency;
}

@Override
Expand Down Expand Up @@ -340,7 +338,7 @@ public void testMinScoreDisablesCountOptimization() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThanOrEqualTo(100L));
assertThat(query.getTimeBreakdown().get("score_count"), equalTo(1L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThanOrEqualTo(100L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThanOrEqualTo(100L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThanOrEqualTo(100L));
Expand Down Expand Up @@ -487,7 +485,7 @@ public void testTerminateAfterEarlyTermination() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -565,7 +563,7 @@ public void testTerminateAfterEarlyTermination() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -611,7 +609,7 @@ public void testTerminateAfterEarlyTermination() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -743,7 +741,7 @@ public void testTerminateAfterEarlyTermination() throws Exception {
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("create_weight_count"), equalTo(1L));
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(0).getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand All @@ -758,7 +756,7 @@ public void testTerminateAfterEarlyTermination() throws Exception {
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("create_weight_count"), equalTo(1L));
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getProfiledChildren().get(1).getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1104,7 +1102,7 @@ public void testDisableTopScoreCollection() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThan(0L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1191,7 +1189,7 @@ public void testMinScore() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), equalTo(10L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1276,7 +1274,7 @@ public void testMaxScore() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThanOrEqualTo(6L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThanOrEqualTo(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1319,7 +1317,7 @@ public void testMaxScore() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThanOrEqualTo(6L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1397,7 +1395,7 @@ public void testCollapseQuerySearchResults() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThanOrEqualTo(6L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down Expand Up @@ -1432,7 +1430,7 @@ public void testCollapseQuerySearchResults() throws Exception {
assertThat(query.getTimeBreakdown().keySet(), not(empty()));
assertThat(query.getTimeBreakdown().get("score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("score_count"), greaterThanOrEqualTo(6L));
if (concurrency > 0) {
if (executor != null) {
assertThat(query.getTimeBreakdown().get("max_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("min_score"), greaterThan(0L));
assertThat(query.getTimeBreakdown().get("avg_score"), greaterThan(0L));
Expand Down

0 comments on commit 6e3b3c8

Please sign in to comment.