32
32
33
33
package org .opensearch .search .profile .query ;
34
34
35
+ import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
36
+
35
37
import org .apache .lucene .tests .util .English ;
36
38
import org .opensearch .action .index .IndexRequestBuilder ;
37
39
import org .opensearch .action .search .MultiSearchResponse ;
40
42
import org .opensearch .action .search .SearchType ;
41
43
import org .opensearch .action .search .ShardSearchFailure ;
42
44
import org .opensearch .common .settings .Settings ;
45
+ import org .opensearch .common .util .FeatureFlags ;
43
46
import org .opensearch .index .query .QueryBuilder ;
44
47
import org .opensearch .index .query .QueryBuilders ;
45
48
import org .opensearch .search .SearchHit ;
46
49
import org .opensearch .search .profile .ProfileResult ;
47
50
import org .opensearch .search .profile .ProfileShardResult ;
48
51
import org .opensearch .search .sort .SortOrder ;
49
- import org .opensearch .test .OpenSearchIntegTestCase ;
52
+ import org .opensearch .test .ParameterizedOpenSearchIntegTestCase ;
50
53
51
54
import java .util .Arrays ;
55
+ import java .util .Collection ;
52
56
import java .util .HashSet ;
53
57
import java .util .List ;
54
58
import java .util .Map ;
55
59
import java .util .Set ;
56
60
61
+ import static org .opensearch .search .SearchService .CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING ;
57
62
import static org .opensearch .search .profile .query .RandomQueryGenerator .randomQueryBuilder ;
58
63
import static org .hamcrest .Matchers .emptyOrNullString ;
59
64
import static org .hamcrest .Matchers .equalTo ;
60
65
import static org .hamcrest .Matchers .greaterThan ;
61
66
import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
62
67
import static org .hamcrest .Matchers .is ;
63
68
import static org .hamcrest .Matchers .not ;
69
+ import static org .hamcrest .Matchers .nullValue ;
70
+
71
+ public class QueryProfilerIT extends ParameterizedOpenSearchIntegTestCase {
72
+ private final boolean concurrentSearchEnabled ;
73
+ private static final String MAX_PREFIX = "max_" ;
74
+ private static final String MIN_PREFIX = "min_" ;
75
+ private static final String AVG_PREFIX = "avg_" ;
76
+ private static final String TIMING_TYPE_COUNT_SUFFIX = "_count" ;
77
+
78
+ public QueryProfilerIT (Settings settings , boolean concurrentSearchEnabled ) {
79
+ super (settings );
80
+ this .concurrentSearchEnabled = concurrentSearchEnabled ;
81
+ }
82
+
83
+ @ ParametersFactory
84
+ public static Collection <Object []> parameters () {
85
+ return Arrays .asList (
86
+ new Object [] { Settings .builder ().put (CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING .getKey (), false ).build (), false },
87
+ new Object [] { Settings .builder ().put (CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING .getKey (), true ).build (), true }
88
+ );
89
+ }
64
90
65
- public class QueryProfilerIT extends OpenSearchIntegTestCase {
91
+ @ Override
92
+ protected Settings featureFlagSettings () {
93
+ return Settings .builder ().put (super .featureFlagSettings ()).put (FeatureFlags .CONCURRENT_SEGMENT_SEARCH , "true" ).build ();
94
+ }
66
95
67
96
/**
68
97
* This test simply checks to make sure nothing crashes. Test indexes 100-150 documents,
@@ -229,6 +258,7 @@ public void testSimpleMatch() throws Exception {
229
258
assertEquals (result .getLuceneDescription (), "field1:one" );
230
259
assertThat (result .getTime (), greaterThan (0L ));
231
260
assertNotNull (result .getTimeBreakdown ());
261
+ assertQueryProfileResult (result );
232
262
}
233
263
234
264
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -271,6 +301,7 @@ public void testBool() throws Exception {
271
301
assertThat (result .getTime (), greaterThan (0L ));
272
302
assertNotNull (result .getTimeBreakdown ());
273
303
assertEquals (result .getProfiledChildren ().size (), 2 );
304
+ assertQueryProfileResult (result );
274
305
275
306
// Check the children
276
307
List <ProfileResult > children = result .getProfiledChildren ();
@@ -282,12 +313,14 @@ public void testBool() throws Exception {
282
313
assertThat (childProfile .getTime (), greaterThan (0L ));
283
314
assertNotNull (childProfile .getTimeBreakdown ());
284
315
assertEquals (childProfile .getProfiledChildren ().size (), 0 );
316
+ assertQueryProfileResult (childProfile );
285
317
286
318
childProfile = children .get (1 );
287
319
assertEquals (childProfile .getQueryName (), "TermQuery" );
288
320
assertEquals (childProfile .getLuceneDescription (), "field1:two" );
289
321
assertThat (childProfile .getTime (), greaterThan (0L ));
290
322
assertNotNull (childProfile .getTimeBreakdown ());
323
+ assertQueryProfileResult (childProfile );
291
324
}
292
325
293
326
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -330,6 +363,7 @@ public void testEmptyBool() throws Exception {
330
363
assertNotNull (result .getLuceneDescription ());
331
364
assertThat (result .getTime (), greaterThan (0L ));
332
365
assertNotNull (result .getTimeBreakdown ());
366
+ assertQueryProfileResult (result );
333
367
}
334
368
335
369
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -375,6 +409,7 @@ public void testCollapsingBool() throws Exception {
375
409
assertNotNull (result .getLuceneDescription ());
376
410
assertThat (result .getTime (), greaterThan (0L ));
377
411
assertNotNull (result .getTimeBreakdown ());
412
+ assertQueryProfileResult (result );
378
413
}
379
414
380
415
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -415,6 +450,7 @@ public void testBoosting() throws Exception {
415
450
assertNotNull (result .getLuceneDescription ());
416
451
assertThat (result .getTime (), greaterThan (0L ));
417
452
assertNotNull (result .getTimeBreakdown ());
453
+ assertQueryProfileResult (result );
418
454
}
419
455
420
456
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -455,6 +491,7 @@ public void testDisMaxRange() throws Exception {
455
491
assertNotNull (result .getLuceneDescription ());
456
492
assertThat (result .getTime (), greaterThan (0L ));
457
493
assertNotNull (result .getTimeBreakdown ());
494
+ assertQueryProfileResult (result );
458
495
}
459
496
460
497
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -494,6 +531,7 @@ public void testRange() throws Exception {
494
531
assertNotNull (result .getLuceneDescription ());
495
532
assertThat (result .getTime (), greaterThan (0L ));
496
533
assertNotNull (result .getTimeBreakdown ());
534
+ assertQueryProfileResult (result );
497
535
}
498
536
499
537
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -547,6 +585,7 @@ public void testPhrase() throws Exception {
547
585
assertNotNull (result .getLuceneDescription ());
548
586
assertThat (result .getTime (), greaterThan (0L ));
549
587
assertNotNull (result .getTimeBreakdown ());
588
+ assertQueryProfileResult (result );
550
589
}
551
590
552
591
CollectorResult result = searchProfiles .getCollectorResult ();
@@ -579,4 +618,35 @@ public void testNoProfile() throws Exception {
579
618
assertThat ("Profile response element should be an empty map" , resp .getProfileResults ().size (), equalTo (0 ));
580
619
}
581
620
621
+ private void assertQueryProfileResult (ProfileResult result ) {
622
+ Map <String , Long > breakdown = result .getTimeBreakdown ();
623
+ Long maxSliceTime = result .getMaxSliceTime ();
624
+ Long minSliceTime = result .getMinSliceTime ();
625
+ Long avgSliceTime = result .getAvgSliceTime ();
626
+ if (concurrentSearchEnabled ) {
627
+ assertNotNull (maxSliceTime );
628
+ assertNotNull (minSliceTime );
629
+ assertNotNull (avgSliceTime );
630
+ assertThat (breakdown .size (), equalTo (66 ));
631
+ for (QueryTimingType queryTimingType : QueryTimingType .values ()) {
632
+ if (queryTimingType != QueryTimingType .CREATE_WEIGHT ) {
633
+ String maxTimingType = MAX_PREFIX + queryTimingType ;
634
+ String minTimingType = MIN_PREFIX + queryTimingType ;
635
+ String avgTimingType = AVG_PREFIX + queryTimingType ;
636
+ assertNotNull (breakdown .get (maxTimingType ));
637
+ assertNotNull (breakdown .get (minTimingType ));
638
+ assertNotNull (breakdown .get (avgTimingType ));
639
+ assertNotNull (breakdown .get (maxTimingType + TIMING_TYPE_COUNT_SUFFIX ));
640
+ assertNotNull (breakdown .get (minTimingType + TIMING_TYPE_COUNT_SUFFIX ));
641
+ assertNotNull (breakdown .get (avgTimingType + TIMING_TYPE_COUNT_SUFFIX ));
642
+ }
643
+ }
644
+ } else {
645
+ assertThat (maxSliceTime , is (nullValue ()));
646
+ assertThat (minSliceTime , is (nullValue ()));
647
+ assertThat (avgSliceTime , is (nullValue ()));
648
+ assertThat (breakdown .size (), equalTo (27 ));
649
+ }
650
+ }
651
+
582
652
}
0 commit comments