-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for query profiler with concurrent aggregation (#9248)
* Add support for query profiler with concurrent aggregation (#9248) Signed-off-by: Ticheng Lin <[email protected]> * Refactor and work on the PR comments Signed-off-by: Ticheng Lin <[email protected]> * Update collectorToLeaves mapping for children breakdowns post profile metric collection and before creating the results Signed-off-by: Sorabh Hamirwasia <[email protected]> * Refactor logic to compute the slice level breakdown stats and query level breakdown stats for concurrent search case Signed-off-by: Sorabh Hamirwasia <[email protected]> * Fix QueryProfilePhaseTests and QueryProfileTests, and parameterize QueryProfilerIT with concurrent search enabled Signed-off-by: Ticheng Lin <[email protected]> * Handle the case when there are no leaf context to compute the profile stats to return default stats for all breakdown type along with min/max/avg values. Replace queryStart and queryEnd time with queryNodeTime Signed-off-by: Sorabh Hamirwasia <[email protected]> * Add UTs for ConcurrentQueryProfileBreakdown Signed-off-by: Sorabh Hamirwasia <[email protected]> * Add concurrent search stats test into the QueryProfilerIT Signed-off-by: Ticheng Lin <[email protected]> * Address review comments Signed-off-by: Sorabh Hamirwasia <[email protected]> --------- Signed-off-by: Ticheng Lin <[email protected]> Signed-off-by: Sorabh Hamirwasia <[email protected]> Co-authored-by: Sorabh Hamirwasia <[email protected]>
- Loading branch information
1 parent
0d4263e
commit a2552db
Showing
16 changed files
with
1,114 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
server/src/main/java/org/opensearch/search/profile/query/AbstractQueryProfileTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.profile.query; | ||
|
||
import org.apache.lucene.search.Query; | ||
import org.opensearch.search.profile.AbstractInternalProfileTree; | ||
import org.opensearch.search.profile.ContextualProfileBreakdown; | ||
import org.opensearch.search.profile.ProfileResult; | ||
|
||
/** | ||
* This class tracks the dependency tree for queries (scoring and rewriting) and | ||
* generates {@link QueryProfileBreakdown} for each node in the tree. It also finalizes the tree | ||
* and returns a list of {@link ProfileResult} that can be serialized back to the client | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public abstract class AbstractQueryProfileTree extends AbstractInternalProfileTree<ContextualProfileBreakdown<QueryTimingType>, Query> { | ||
|
||
/** Rewrite time */ | ||
private long rewriteTime; | ||
private long rewriteScratch; | ||
|
||
@Override | ||
protected String getTypeFromElement(Query query) { | ||
// Anonymous classes won't have a name, | ||
// we need to get the super class | ||
if (query.getClass().getSimpleName().isEmpty()) { | ||
return query.getClass().getSuperclass().getSimpleName(); | ||
} | ||
return query.getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
protected String getDescriptionFromElement(Query query) { | ||
return query.toString(); | ||
} | ||
|
||
/** | ||
* Begin timing a query for a specific Timing context | ||
*/ | ||
public void startRewriteTime() { | ||
assert rewriteScratch == 0; | ||
rewriteScratch = System.nanoTime(); | ||
} | ||
|
||
/** | ||
* Halt the timing process and add the elapsed rewriting time. | ||
* startRewriteTime() must be called for a particular context prior to calling | ||
* stopAndAddRewriteTime(), otherwise the elapsed time will be negative and | ||
* nonsensical | ||
* | ||
* @return The elapsed time | ||
*/ | ||
public long stopAndAddRewriteTime() { | ||
long time = Math.max(1, System.nanoTime() - rewriteScratch); | ||
rewriteTime += time; | ||
rewriteScratch = 0; | ||
return time; | ||
} | ||
|
||
public long getRewriteTime() { | ||
return rewriteTime; | ||
} | ||
} |
Oops, something went wrong.