Moves query profiler classes into their own package
The change also renames fields and methods in the Profilers class. Note that I had to make ProfileResult a public class (it was package private before) because now classes that call it are in a different package.
This commit is contained in:
parent
92339c4763
commit
8c9ca8b518
|
@ -30,8 +30,8 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
|||
import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator;
|
||||
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.profile.CollectorResult;
|
||||
import org.elasticsearch.search.profile.InternalProfileCollector;
|
||||
import org.elasticsearch.search.profile.query.CollectorResult;
|
||||
import org.elasticsearch.search.profile.query.InternalProfileCollector;
|
||||
import org.elasticsearch.search.query.QueryPhaseExecutionException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -125,7 +125,7 @@ public class AggregationPhase implements SearchPhase {
|
|||
Collections.emptyList());
|
||||
collector = profileCollector;
|
||||
// start a new profile with this collector
|
||||
context.getProfilers().addProfiler().setCollector(profileCollector);
|
||||
context.getProfilers().addQueryProfiler().setCollector(profileCollector);
|
||||
}
|
||||
globalsCollector.preCollection();
|
||||
context.searcher().search(query, collector);
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.apache.lucene.search.Weight;
|
|||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.search.dfs.AggregatedDfs;
|
||||
import org.elasticsearch.search.profile.QueryProfileBreakdown;
|
||||
import org.elasticsearch.search.profile.ProfileWeight;
|
||||
import org.elasticsearch.search.profile.QueryProfiler;
|
||||
import org.elasticsearch.search.profile.QueryTimingType;
|
||||
import org.elasticsearch.search.profile.query.ProfileWeight;
|
||||
import org.elasticsearch.search.profile.query.QueryProfileBreakdown;
|
||||
import org.elasticsearch.search.profile.query.QueryProfiler;
|
||||
import org.elasticsearch.search.profile.query.QueryTimingType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.util.Map;
|
|||
* Each InternalProfileResult has a List of InternalProfileResults, which will contain
|
||||
* "children" queries if applicable
|
||||
*/
|
||||
final class ProfileResult implements Writeable, ToXContent {
|
||||
public final class ProfileResult implements Writeable, ToXContent {
|
||||
|
||||
private static final ParseField TYPE = new ParseField("type");
|
||||
private static final ParseField DESCRIPTION = new ParseField("description");
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.search.profile.query.CollectorResult;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.profile;
|
||||
|
||||
import org.elasticsearch.search.internal.ContextIndexSearcher;
|
||||
import org.elasticsearch.search.profile.query.QueryProfiler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -29,31 +30,31 @@ import java.util.List;
|
|||
public final class Profilers {
|
||||
|
||||
private final ContextIndexSearcher searcher;
|
||||
private final List<QueryProfiler> profilers;
|
||||
private final List<QueryProfiler> queryProfilers;
|
||||
|
||||
/** Sole constructor. This {@link Profilers} instance will initially wrap one {@link QueryProfiler}. */
|
||||
public Profilers(ContextIndexSearcher searcher) {
|
||||
this.searcher = searcher;
|
||||
this.profilers = new ArrayList<>();
|
||||
addProfiler();
|
||||
this.queryProfilers = new ArrayList<>();
|
||||
addQueryProfiler();
|
||||
}
|
||||
|
||||
/** Switch to a new profile. */
|
||||
public QueryProfiler addProfiler() {
|
||||
public QueryProfiler addQueryProfiler() {
|
||||
QueryProfiler profiler = new QueryProfiler();
|
||||
searcher.setProfiler(profiler);
|
||||
profilers.add(profiler);
|
||||
queryProfilers.add(profiler);
|
||||
return profiler;
|
||||
}
|
||||
|
||||
/** Get the current profiler. */
|
||||
public QueryProfiler getCurrent() {
|
||||
return profilers.get(profilers.size() - 1);
|
||||
public QueryProfiler getCurrentQueryProfiler() {
|
||||
return queryProfilers.get(queryProfilers.size() - 1);
|
||||
}
|
||||
|
||||
/** Return the list of all created {@link QueryProfiler}s so far. */
|
||||
public List<QueryProfiler> getProfilers() {
|
||||
return Collections.unmodifiableList(profilers);
|
||||
public List<QueryProfiler> getQueryProfilers() {
|
||||
return Collections.unmodifiableList(queryProfilers);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.search.profile.query.QueryProfiler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Collector;
|
|
@ -17,9 +17,10 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.search.profile.ProfileResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Collector;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.Scorer;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.Term;
|
|
@ -17,7 +17,9 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.elasticsearch.search.profile.AbstractProfileBreakdown;
|
||||
|
||||
/**
|
||||
* A record of timings for the various operations that may happen during query execution.
|
|
@ -17,9 +17,10 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.search.profile.ProfileResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import java.util.Locale;
|
||||
|
|
@ -52,10 +52,10 @@ import org.elasticsearch.search.SearchService;
|
|||
import org.elasticsearch.search.aggregations.AggregationPhase;
|
||||
import org.elasticsearch.search.internal.ScrollContext;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.profile.CollectorResult;
|
||||
import org.elasticsearch.search.profile.InternalProfileCollector;
|
||||
import org.elasticsearch.search.profile.ProfileShardResult;
|
||||
import org.elasticsearch.search.profile.SearchProfileShardResults;
|
||||
import org.elasticsearch.search.profile.query.CollectorResult;
|
||||
import org.elasticsearch.search.profile.query.InternalProfileCollector;
|
||||
import org.elasticsearch.search.rescore.RescorePhase;
|
||||
import org.elasticsearch.search.rescore.RescoreSearchContext;
|
||||
import org.elasticsearch.search.sort.SortAndFormats;
|
||||
|
@ -113,7 +113,7 @@ public class QueryPhase implements SearchPhase {
|
|||
|
||||
if (searchContext.getProfilers() != null) {
|
||||
List<ProfileShardResult> shardResults = SearchProfileShardResults
|
||||
.buildShardResults(searchContext.getProfilers().getProfilers());
|
||||
.buildShardResults(searchContext.getProfilers().getQueryProfilers());
|
||||
searchContext.queryResult().profileResults(shardResults);
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ public class QueryPhase implements SearchPhase {
|
|||
try {
|
||||
if (collector != null) {
|
||||
if (doProfile) {
|
||||
searchContext.getProfilers().getCurrent().setCollector((InternalProfileCollector) collector);
|
||||
searchContext.getProfilers().getCurrentQueryProfiler().setCollector((InternalProfileCollector) collector);
|
||||
}
|
||||
searcher.search(query, collector);
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ public class QueryPhase implements SearchPhase {
|
|||
|
||||
if (searchContext.getProfilers() != null) {
|
||||
List<ProfileShardResult> shardResults = SearchProfileShardResults
|
||||
.buildShardResults(searchContext.getProfilers().getProfilers());
|
||||
.buildShardResults(searchContext.getProfilers().getQueryProfilers());
|
||||
searchContext.queryResult().profileResults(shardResults);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
|
@ -37,6 +37,9 @@ import org.apache.lucene.util.IOUtils;
|
|||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.search.internal.ContextIndexSearcher;
|
||||
import org.elasticsearch.search.profile.ProfileResult;
|
||||
import org.elasticsearch.search.profile.query.QueryProfiler;
|
||||
import org.elasticsearch.search.profile.query.QueryTimingType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.util.English;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
|
@ -29,6 +29,9 @@ import org.elasticsearch.action.search.ShardSearchFailure;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.profile.ProfileResult;
|
||||
import org.elasticsearch.search.profile.ProfileShardResult;
|
||||
import org.elasticsearch.search.profile.query.CollectorResult;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
|
@ -36,7 +39,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.search.profile.RandomQueryGenerator.randomQueryBuilder;
|
||||
import static org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.DoubleMatcher.nearlyEqual;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
|
@ -160,7 +163,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
|
|||
nearlyEqual(vanillaMaxScore, profileMaxScore, 0.001));
|
||||
}
|
||||
|
||||
assertThat("Profile totalHits of [" + profileResponse.getHits().totalHits() + "] is not close to Vanilla totalHits [" + vanillaResponse.getHits().totalHits() + "]",
|
||||
assertThat("Profile totalHits of [" + profileResponse.getHits().totalHits() + "] is not close to Vanilla totalHits ["
|
||||
+ vanillaResponse.getHits().totalHits() + "]",
|
||||
vanillaResponse.getHits().getTotalHits(), equalTo(profileResponse.getHits().getTotalHits()));
|
||||
|
||||
SearchHit[] vanillaHits = vanillaResponse.getHits().getHits();
|
||||
|
@ -237,7 +241,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
|
|||
|
||||
indexRandom(true, docs);
|
||||
|
||||
QueryBuilder q = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one")).must(QueryBuilders.matchQuery("field1", "two"));
|
||||
QueryBuilder q = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one"))
|
||||
.must(QueryBuilders.matchQuery("field1", "two"));
|
||||
|
||||
SearchResponse resp = client().prepareSearch()
|
||||
.setQuery(q)
|
||||
|
@ -355,7 +360,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
|
|||
|
||||
refresh();
|
||||
|
||||
QueryBuilder q = QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one"))));
|
||||
QueryBuilder q = QueryBuilders.boolQuery()
|
||||
.must(QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one"))));
|
||||
|
||||
logger.info("Query: {}", q);
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.profile;
|
||||
package org.elasticsearch.search.profile.query;
|
||||
|
||||
import org.apache.lucene.util.English;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
Loading…
Reference in New Issue