|
@@ -8,6 +8,8 @@
|
|
|
|
|
|
package org.elasticsearch.search.profile.aggregation;
|
|
|
|
|
|
+import io.github.nik9000.mapmatcher.MapMatcher;
|
|
|
+
|
|
|
import org.elasticsearch.action.index.IndexRequestBuilder;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
@@ -32,6 +34,7 @@ import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static io.github.nik9000.mapmatcher.ListMatcher.matchesList;
|
|
|
import static io.github.nik9000.mapmatcher.MapMatcher.assertMap;
|
|
|
import static io.github.nik9000.mapmatcher.MapMatcher.matchesMap;
|
|
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
@@ -45,9 +48,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSear
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.greaterThan;
|
|
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
-import static org.hamcrest.Matchers.hasEntry;
|
|
|
-import static org.hamcrest.Matchers.hasKey;
|
|
|
-import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
|
|
|
|
@ESIntegTestCase.SuiteScopeTestCase
|
|
@@ -74,6 +74,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
);
|
|
|
|
|
|
private static final String TOTAL_BUCKETS = "total_buckets";
|
|
|
+ private static final String BUILT_BUCKETS = "built_buckets";
|
|
|
private static final String DEFERRED = "deferred_aggregators";
|
|
|
private static final String COLLECTION_STRAT = "collection_strategy";
|
|
|
private static final String RESULT_STRAT = "result_strategy";
|
|
@@ -143,10 +144,10 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(breakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(breakdown.get(BUILD_AGGREGATION).longValue(), greaterThan(0L));
|
|
|
assertThat(breakdown.get(REDUCE), equalTo(0L));
|
|
|
- Map<String, Object> debug = histoAggResult.getDebugInfo();
|
|
|
- assertThat(debug, notNullValue());
|
|
|
- assertThat(debug.keySet(), equalTo(Set.of(TOTAL_BUCKETS)));
|
|
|
- assertThat(((Number) debug.get(TOTAL_BUCKETS)).longValue(), greaterThan(0L));
|
|
|
+ assertMap(
|
|
|
+ histoAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(TOTAL_BUCKETS, greaterThan(0L)).entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -187,11 +188,10 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(histoBreakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- Map<String, Object> histoDebugInfo = histoAggResult.getDebugInfo();
|
|
|
- assertThat(histoDebugInfo, notNullValue());
|
|
|
- assertThat(histoDebugInfo.keySet(), equalTo(Set.of(TOTAL_BUCKETS)));
|
|
|
- assertThat(((Number) histoDebugInfo.get(TOTAL_BUCKETS)).longValue(), greaterThan(0L));
|
|
|
- assertThat(histoAggResult.getProfiledChildren().size(), equalTo(1));
|
|
|
+ assertMap(
|
|
|
+ histoAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(TOTAL_BUCKETS, greaterThan(0L)).entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
|
|
|
ProfileResult termsAggResult = histoAggResult.getProfiledChildren().get(0);
|
|
|
assertThat(termsAggResult, notNullValue());
|
|
@@ -213,23 +213,33 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(avgAggResult.getQueryName(), equalTo("AvgAggregator"));
|
|
|
assertThat(avgAggResult.getLuceneDescription(), equalTo("avg"));
|
|
|
assertThat(avgAggResult.getTime(), greaterThan(0L));
|
|
|
- Map<String, Long> avgBreakdown = termsAggResult.getTimeBreakdown();
|
|
|
+ Map<String, Long> avgBreakdown = avgAggResult.getTimeBreakdown();
|
|
|
assertThat(avgBreakdown, notNullValue());
|
|
|
assertThat(avgBreakdown.keySet(), equalTo(BREAKDOWN_KEYS));
|
|
|
assertThat(avgBreakdown.get(INITIALIZE), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(avgAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(
|
|
|
+ avgAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void assertRemapTermsDebugInfo(ProfileResult termsAggResult) {
|
|
|
- assertThat(termsAggResult.getDebugInfo(), hasEntry(COLLECTION_STRAT, "remap using many bucket ords"));
|
|
|
- assertThat(termsAggResult.getDebugInfo(), hasEntry(RESULT_STRAT, "terms"));
|
|
|
- assertThat(termsAggResult.getDebugInfo(), hasEntry(HAS_FILTER, false));
|
|
|
- assertThat(termsAggResult.getDebugInfo().toString(), (int) termsAggResult.getDebugInfo().get(SEGMENTS_WITH_SINGLE), greaterThan(0));
|
|
|
+ private void assertRemapTermsDebugInfo(ProfileResult termsAggResult, String... deferredAggregators) {
|
|
|
+ MapMatcher matcher = matchesMap().entry(TOTAL_BUCKETS, greaterThan(0L))
|
|
|
+ .entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ .entry(COLLECTION_STRAT, "remap using many bucket ords")
|
|
|
+ .entry(RESULT_STRAT, "terms")
|
|
|
+ .entry(HAS_FILTER, false)
|
|
|
+ .entry(SEGMENTS_WITH_SINGLE, greaterThan(0))
|
|
|
+ .entry(SEGMENTS_WITH_MULTI, 0);
|
|
|
+ if (deferredAggregators.length > 0) {
|
|
|
+ matcher = matcher.entry(DEFERRED, List.of(deferredAggregators));
|
|
|
+ }
|
|
|
+ assertMap(termsAggResult.getDebugInfo(), matcher);
|
|
|
}
|
|
|
|
|
|
public void testMultiLevelProfileBreadthFirst() {
|
|
@@ -261,10 +271,10 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(histoBreakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- Map<String, Object> histoDebugInfo = histoAggResult.getDebugInfo();
|
|
|
- assertThat(histoDebugInfo, notNullValue());
|
|
|
- assertThat(histoDebugInfo.keySet(), equalTo(Set.of(TOTAL_BUCKETS)));
|
|
|
- assertThat(((Number) histoDebugInfo.get(TOTAL_BUCKETS)).longValue(), greaterThan(0L));
|
|
|
+ assertMap(
|
|
|
+ histoAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(TOTAL_BUCKETS, greaterThan(0L)).entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
assertThat(histoAggResult.getProfiledChildren().size(), equalTo(1));
|
|
|
|
|
|
ProfileResult termsAggResult = histoAggResult.getProfiledChildren().get(0);
|
|
@@ -279,7 +289,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(termsBreakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(termsBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(termsBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertRemapTermsDebugInfo(termsAggResult);
|
|
|
+ assertRemapTermsDebugInfo(termsAggResult, "avg");
|
|
|
assertThat(termsAggResult.getProfiledChildren().size(), equalTo(1));
|
|
|
|
|
|
ProfileResult avgAggResult = termsAggResult.getProfiledChildren().get(0);
|
|
@@ -294,7 +304,10 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(avgBreakdown.get(COLLECT), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(avgAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(
|
|
|
+ avgAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
}
|
|
|
}
|
|
@@ -330,8 +343,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(diversifyBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(diversifyBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(diversifyBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(diversifyAggResult.getDebugInfo(), equalTo(Map.of(DEFERRED, List.of("max"))));
|
|
|
- assertThat(diversifyAggResult.getProfiledChildren().size(), equalTo(1));
|
|
|
+ assertMap(diversifyAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)).entry(DEFERRED, List.of("max")));
|
|
|
|
|
|
ProfileResult maxAggResult = diversifyAggResult.getProfiledChildren().get(0);
|
|
|
assertThat(maxAggResult, notNullValue());
|
|
@@ -347,7 +359,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(diversifyBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(maxAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(maxAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
}
|
|
|
}
|
|
@@ -391,10 +403,10 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(histoBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(histoBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- Map<String, Object> histoDebugInfo = histoAggResult.getDebugInfo();
|
|
|
- assertThat(histoDebugInfo, notNullValue());
|
|
|
- assertThat(histoDebugInfo.keySet(), equalTo(Set.of(TOTAL_BUCKETS)));
|
|
|
- assertThat(((Number) histoDebugInfo.get(TOTAL_BUCKETS)).longValue(), greaterThan(0L));
|
|
|
+ assertMap(
|
|
|
+ histoAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(TOTAL_BUCKETS, greaterThan(0L)).entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ );
|
|
|
assertThat(histoAggResult.getProfiledChildren().size(), equalTo(2));
|
|
|
|
|
|
Map<String, ProfileResult> histoAggResultSubAggregations = histoAggResult.getProfiledChildren().stream()
|
|
@@ -432,7 +444,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(avgBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(avgAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(avgAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
|
|
|
ProfileResult maxAggResult = tagsAggResultSubAggregations.get("max");
|
|
@@ -448,7 +460,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(maxBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(maxAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(maxAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
|
|
|
ProfileResult stringsAggResult = histoAggResultSubAggregations.get("strings");
|
|
@@ -483,7 +495,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(avgBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(avgAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(avgAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
|
|
|
maxAggResult = stringsAggResultSubAggregations.get("max");
|
|
@@ -499,7 +511,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(maxBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(maxAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(maxAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
|
|
|
tagsAggResult = stringsAggResultSubAggregations.get("tags");
|
|
@@ -535,7 +547,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(avgBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(avgBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(avgAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(avgAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(avgAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
|
|
|
maxAggResult = tagsAggResultSubAggregations.get("max");
|
|
@@ -551,7 +563,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(maxBreakdown.get(POST_COLLECTION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(BUILD_AGGREGATION), greaterThan(0L));
|
|
|
assertThat(maxBreakdown.get(REDUCE), equalTo(0L));
|
|
|
- assertThat(maxAggResult.getDebugInfo(), equalTo(Map.of()));
|
|
|
+ assertMap(maxAggResult.getDebugInfo(), matchesMap().entry(BUILT_BUCKETS, greaterThan(0)));
|
|
|
assertThat(maxAggResult.getProfiledChildren().size(), equalTo(0));
|
|
|
}
|
|
|
}
|
|
@@ -623,30 +635,36 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertThat(breakdown.get(COLLECT), equalTo(0L));
|
|
|
assertThat(breakdown.get(BUILD_AGGREGATION).longValue(), greaterThan(0L));
|
|
|
assertThat(breakdown.get(REDUCE), equalTo(0L));
|
|
|
- Map<String, Object> debug = histoAggResult.getDebugInfo();
|
|
|
- assertThat(debug, notNullValue());
|
|
|
- assertThat(debug.keySet(), equalTo(Set.of("delegate", "delegate_debug")));
|
|
|
- assertThat(debug.get("delegate"), equalTo("RangeAggregator.FromFilters"));
|
|
|
- Map<?, ?> delegate = (Map<?, ?>) debug.get("delegate_debug");
|
|
|
- assertThat(delegate.keySet(), equalTo(Set.of("average_docs_per_range", "ranges", "delegate", "delegate_debug")));
|
|
|
- assertThat(
|
|
|
- ((Number) delegate.get("average_docs_per_range")).doubleValue(),
|
|
|
- equalTo(RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2)
|
|
|
+ assertMap(
|
|
|
+ histoAggResult.getDebugInfo(),
|
|
|
+ matchesMap().entry(BUILT_BUCKETS, greaterThan(0))
|
|
|
+ .entry("delegate", "RangeAggregator.FromFilters")
|
|
|
+ .entry(
|
|
|
+ "delegate_debug",
|
|
|
+ matchesMap().entry("average_docs_per_range", equalTo(RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2))
|
|
|
+ .entry("ranges", 1)
|
|
|
+ .entry("delegate", "FiltersAggregator.FilterByFilter")
|
|
|
+ .entry(
|
|
|
+ "delegate_debug",
|
|
|
+ matchesMap().entry("segments_with_deleted_docs", 0)
|
|
|
+ .entry("segments_with_doc_count_field", 0)
|
|
|
+ .entry("max_cost", (long) RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2)
|
|
|
+ .entry("estimated_cost", (long) RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2)
|
|
|
+ .entry("estimate_cost_time", greaterThanOrEqualTo(0L)) // ~1,276,734 nanos is normal
|
|
|
+ .entry("segments_counted", 0)
|
|
|
+ .entry("segments_collected", greaterThan(0))
|
|
|
+ .entry(
|
|
|
+ "filters",
|
|
|
+ matchesList().item(
|
|
|
+ matchesMap().entry("scorers_prepared_while_estimating_cost", greaterThan(0))
|
|
|
+ .entry("query", "DocValuesFieldExistsQuery [field=date]")
|
|
|
+ .entry("specialized_for", "docvalues_field_exists")
|
|
|
+ .entry("results_from_metadata", 0)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
);
|
|
|
- assertThat(((Number) delegate.get("ranges")).longValue(), equalTo(1L));
|
|
|
- assertThat(delegate.get("delegate"), equalTo("FiltersAggregator.FilterByFilter"));
|
|
|
- Map<?, ?> delegateDebug = (Map<?, ?>) delegate.get("delegate_debug");
|
|
|
- assertThat(delegateDebug, hasEntry("segments_with_deleted_docs", 0));
|
|
|
- assertThat(delegateDebug, hasEntry("segments_with_doc_count_field", 0));
|
|
|
- assertThat(delegateDebug, hasEntry("max_cost", (long) RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2));
|
|
|
- assertThat(delegateDebug, hasEntry("estimated_cost", (long) RangeAggregator.DOCS_PER_RANGE_TO_USE_FILTERS * 2));
|
|
|
- assertThat((long) delegateDebug.get("estimate_cost_time"), greaterThanOrEqualTo(0L)); // ~1,276,734 nanos is normal
|
|
|
- List<?> filtersDebug = (List<?>) delegateDebug.get("filters");
|
|
|
- assertThat(filtersDebug, hasSize(1));
|
|
|
- Map<?, ?> queryDebug = (Map<?, ?>) filtersDebug.get(0);
|
|
|
- assertThat(queryDebug, hasKey("scorers_prepared_while_estimating_cost"));
|
|
|
- assertThat((int) queryDebug.get("scorers_prepared_while_estimating_cost"), greaterThan(0));
|
|
|
- assertThat(queryDebug, hasEntry("query", "DocValuesFieldExistsQuery [field=date]"));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -721,6 +739,7 @@ public class AggregationProfilerIT extends ESIntegTestCase {
|
|
|
assertMap(
|
|
|
debug,
|
|
|
matchesMap().entry("delegate", "RangeAggregator.NoOverlap")
|
|
|
+ .entry("built_buckets", 1)
|
|
|
.entry("delegate_debug", matchesMap().entry("ranges", 1).entry("average_docs_per_range", 10000.0))
|
|
|
);
|
|
|
}
|