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:
Colin Goodheart-Smithe 2016-05-17 10:45:34 +01:00
parent 92339c4763
commit 8c9ca8b518
19 changed files with 54 additions and 38 deletions

View File

@ -30,8 +30,8 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.profile.CollectorResult; import org.elasticsearch.search.profile.query.CollectorResult;
import org.elasticsearch.search.profile.InternalProfileCollector; import org.elasticsearch.search.profile.query.InternalProfileCollector;
import org.elasticsearch.search.query.QueryPhaseExecutionException; import org.elasticsearch.search.query.QueryPhaseExecutionException;
import java.io.IOException; import java.io.IOException;
@ -125,7 +125,7 @@ public class AggregationPhase implements SearchPhase {
Collections.emptyList()); Collections.emptyList());
collector = profileCollector; collector = profileCollector;
// start a new profile with this collector // start a new profile with this collector
context.getProfilers().addProfiler().setCollector(profileCollector); context.getProfilers().addQueryProfiler().setCollector(profileCollector);
} }
globalsCollector.preCollection(); globalsCollector.preCollection();
context.searcher().search(query, collector); context.searcher().search(query, collector);

View File

@ -33,10 +33,10 @@ import org.apache.lucene.search.Weight;
import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.AggregatedDfs;
import org.elasticsearch.search.profile.QueryProfileBreakdown; import org.elasticsearch.search.profile.query.ProfileWeight;
import org.elasticsearch.search.profile.ProfileWeight; import org.elasticsearch.search.profile.query.QueryProfileBreakdown;
import org.elasticsearch.search.profile.QueryProfiler; import org.elasticsearch.search.profile.query.QueryProfiler;
import org.elasticsearch.search.profile.QueryTimingType; import org.elasticsearch.search.profile.query.QueryTimingType;
import java.io.IOException; import java.io.IOException;

View File

@ -43,7 +43,7 @@ import java.util.Map;
* Each InternalProfileResult has a List of InternalProfileResults, which will contain * Each InternalProfileResult has a List of InternalProfileResults, which will contain
* "children" queries if applicable * "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 TYPE = new ParseField("type");
private static final ParseField DESCRIPTION = new ParseField("description"); private static final ParseField DESCRIPTION = new ParseField("description");

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.profile.query.CollectorResult;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -20,6 +20,7 @@
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile;
import org.elasticsearch.search.internal.ContextIndexSearcher; import org.elasticsearch.search.internal.ContextIndexSearcher;
import org.elasticsearch.search.profile.query.QueryProfiler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,31 +30,31 @@ import java.util.List;
public final class Profilers { public final class Profilers {
private final ContextIndexSearcher searcher; 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}. */ /** Sole constructor. This {@link Profilers} instance will initially wrap one {@link QueryProfiler}. */
public Profilers(ContextIndexSearcher searcher) { public Profilers(ContextIndexSearcher searcher) {
this.searcher = searcher; this.searcher = searcher;
this.profilers = new ArrayList<>(); this.queryProfilers = new ArrayList<>();
addProfiler(); addQueryProfiler();
} }
/** Switch to a new profile. */ /** Switch to a new profile. */
public QueryProfiler addProfiler() { public QueryProfiler addQueryProfiler() {
QueryProfiler profiler = new QueryProfiler(); QueryProfiler profiler = new QueryProfiler();
searcher.setProfiler(profiler); searcher.setProfiler(profiler);
profilers.add(profiler); queryProfilers.add(profiler);
return profiler; return profiler;
} }
/** Get the current profiler. */ /** Get the current profiler. */
public QueryProfiler getCurrent() { public QueryProfiler getCurrentQueryProfiler() {
return profilers.get(profilers.size() - 1); return queryProfilers.get(queryProfilers.size() - 1);
} }
/** Return the list of all created {@link QueryProfiler}s so far. */ /** Return the list of all created {@link QueryProfiler}s so far. */
public List<QueryProfiler> getProfilers() { public List<QueryProfiler> getQueryProfilers() {
return Collections.unmodifiableList(profilers); return Collections.unmodifiableList(queryProfilers);
} }
} }

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.profile.query.QueryProfiler;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;

View File

@ -17,7 +17,7 @@
* under the License. * 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.LeafReaderContext;
import org.apache.lucene.search.Collector; import org.apache.lucene.search.Collector;

View File

@ -17,9 +17,10 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.search.profile.ProfileResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;

View File

@ -17,7 +17,7 @@
* under the License. * 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.LeafReaderContext;
import org.apache.lucene.search.Collector; import org.apache.lucene.search.Collector;

View File

@ -17,7 +17,7 @@
* under the License. * 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.DocIdSetIterator;
import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Scorer;

View File

@ -17,7 +17,7 @@
* under the License. * 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.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;

View File

@ -17,7 +17,9 @@
* under the License. * 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. * A record of timings for the various operations that may happen during query execution.

View File

@ -17,9 +17,10 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.search.profile.ProfileResult;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import java.util.Locale; import java.util.Locale;

View File

@ -52,10 +52,10 @@ import org.elasticsearch.search.SearchService;
import org.elasticsearch.search.aggregations.AggregationPhase; import org.elasticsearch.search.aggregations.AggregationPhase;
import org.elasticsearch.search.internal.ScrollContext; import org.elasticsearch.search.internal.ScrollContext;
import org.elasticsearch.search.internal.SearchContext; 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.ProfileShardResult;
import org.elasticsearch.search.profile.SearchProfileShardResults; 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.RescorePhase;
import org.elasticsearch.search.rescore.RescoreSearchContext; import org.elasticsearch.search.rescore.RescoreSearchContext;
import org.elasticsearch.search.sort.SortAndFormats; import org.elasticsearch.search.sort.SortAndFormats;
@ -113,7 +113,7 @@ public class QueryPhase implements SearchPhase {
if (searchContext.getProfilers() != null) { if (searchContext.getProfilers() != null) {
List<ProfileShardResult> shardResults = SearchProfileShardResults List<ProfileShardResult> shardResults = SearchProfileShardResults
.buildShardResults(searchContext.getProfilers().getProfilers()); .buildShardResults(searchContext.getProfilers().getQueryProfilers());
searchContext.queryResult().profileResults(shardResults); searchContext.queryResult().profileResults(shardResults);
} }
} }
@ -365,7 +365,7 @@ public class QueryPhase implements SearchPhase {
try { try {
if (collector != null) { if (collector != null) {
if (doProfile) { if (doProfile) {
searchContext.getProfilers().getCurrent().setCollector((InternalProfileCollector) collector); searchContext.getProfilers().getCurrentQueryProfiler().setCollector((InternalProfileCollector) collector);
} }
searcher.search(query, collector); searcher.search(query, collector);
} }
@ -386,7 +386,7 @@ public class QueryPhase implements SearchPhase {
if (searchContext.getProfilers() != null) { if (searchContext.getProfilers() != null) {
List<ProfileShardResult> shardResults = SearchProfileShardResults List<ProfileShardResult> shardResults = SearchProfileShardResults
.buildShardResults(searchContext.getProfilers().getProfilers()); .buildShardResults(searchContext.getProfilers().getQueryProfilers());
searchContext.queryResult().profileResults(shardResults); searchContext.queryResult().profileResults(shardResults);
} }

View File

@ -17,7 +17,7 @@
* under the License. * 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.Document;
import org.apache.lucene.document.Field.Store; 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.apache.lucene.util.TestUtil;
import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.search.internal.ContextIndexSearcher; 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.elasticsearch.test.ESTestCase;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import org.apache.lucene.util.English; import org.apache.lucene.util.English;
import org.elasticsearch.action.index.IndexRequestBuilder; 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.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit; 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.search.sort.SortOrder;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
@ -36,7 +39,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; 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.elasticsearch.test.hamcrest.DoubleMatcher.nearlyEqual;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
@ -160,7 +163,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
nearlyEqual(vanillaMaxScore, profileMaxScore, 0.001)); 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())); vanillaResponse.getHits().getTotalHits(), equalTo(profileResponse.getHits().getTotalHits()));
SearchHit[] vanillaHits = vanillaResponse.getHits().getHits(); SearchHit[] vanillaHits = vanillaResponse.getHits().getHits();
@ -237,7 +241,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
indexRandom(true, docs); 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() SearchResponse resp = client().prepareSearch()
.setQuery(q) .setQuery(q)
@ -355,7 +360,8 @@ public class QueryProfilerIT extends ESIntegTestCase {
refresh(); 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); logger.info("Query: {}", q);

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.elasticsearch.search.profile; package org.elasticsearch.search.profile.query;
import org.apache.lucene.util.English; import org.apache.lucene.util.English;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;