-
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.
Merge branch 'main' into segrep-backpressure-stats
Signed-off-by: Rishikesh Pasham <62345295+Rishikesh1159@users.noreply.github.com>
- Loading branch information
Showing
23 changed files
with
810 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ BWC_VERSION: | |
- "2.10.0" | ||
- "2.10.1" | ||
- "2.11.0" | ||
- "2.11.1" | ||
- "2.12.0" |
Validating CODEOWNERS rules …
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 |
---|---|---|
@@ -1 +1 @@ | ||
* @reta @anasalkouz @andrross @Bukhtawar @CEHENKLE @dblock @gbbafna @setiah @kartg @kotwanikunal @mch2 @nknize @owaiskazi19 @peternied @Rishikesh1159 @ryanbogan @saratvemulapalli @shwetathareja @dreamer-89 @tlfeng @VachaShah @dbwiddis @sachinpkale @sohami @msfroh | ||
* @abbashus @adnapibar @anasalkouz @andrross @Bukhtawar @CEHENKLE @dblock @dbwiddis @dreamer-89 @gbbafna @kartg @kotwanikunal @mch2 @msfroh @nknize @owaiskazi19 @peternied @reta @Rishikesh1159 @ryanbogan @sachinpkale @saratvemulapalli @setiah @shwetathareja @sohami @tlfeng @VachaShah |
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
81 changes: 81 additions & 0 deletions
81
server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.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,81 @@ | ||
/* | ||
* 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.action.search; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.index.query.QueryBuilderVisitor; | ||
import org.opensearch.index.query.QueryShapeVisitor; | ||
import org.opensearch.search.aggregations.AggregatorFactories; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.search.sort.SortBuilder; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
import java.util.List; | ||
import java.util.ListIterator; | ||
|
||
/** | ||
* Class to categorize the search queries based on the type and increment the relevant counters. | ||
* Class also logs the query shape. | ||
*/ | ||
final class SearchQueryCategorizer { | ||
|
||
private static final Logger log = LogManager.getLogger(SearchQueryCategorizer.class); | ||
|
||
final SearchQueryCounters searchQueryCounters; | ||
|
||
public SearchQueryCategorizer(MetricsRegistry metricsRegistry) { | ||
searchQueryCounters = new SearchQueryCounters(metricsRegistry); | ||
} | ||
|
||
public void categorize(SearchSourceBuilder source) { | ||
QueryBuilder topLevelQueryBuilder = source.query(); | ||
|
||
logQueryShape(topLevelQueryBuilder); | ||
incrementQueryTypeCounters(topLevelQueryBuilder); | ||
incrementQueryAggregationCounters(source.aggregations()); | ||
incrementQuerySortCounters(source.sorts()); | ||
} | ||
|
||
private void incrementQuerySortCounters(List<SortBuilder<?>> sorts) { | ||
if (sorts != null && sorts.size() > 0) { | ||
for (ListIterator<SortBuilder<?>> it = sorts.listIterator(); it.hasNext();) { | ||
SortBuilder sortBuilder = it.next(); | ||
String sortOrder = sortBuilder.order().toString(); | ||
searchQueryCounters.sortCounter.add(1, Tags.create().addTag("sort_order", sortOrder)); | ||
} | ||
} | ||
} | ||
|
||
private void incrementQueryAggregationCounters(AggregatorFactories.Builder aggregations) { | ||
if (aggregations != null) { | ||
searchQueryCounters.aggCounter.add(1); | ||
} | ||
} | ||
|
||
private void incrementQueryTypeCounters(QueryBuilder topLevelQueryBuilder) { | ||
if (topLevelQueryBuilder == null) { | ||
return; | ||
} | ||
QueryBuilderVisitor searchQueryVisitor = new SearchQueryCategorizingVisitor(searchQueryCounters); | ||
topLevelQueryBuilder.visit(searchQueryVisitor); | ||
} | ||
|
||
private void logQueryShape(QueryBuilder topLevelQueryBuilder) { | ||
if (topLevelQueryBuilder == null) { | ||
return; | ||
} | ||
QueryShapeVisitor shapeVisitor = new QueryShapeVisitor(); | ||
topLevelQueryBuilder.visit(shapeVisitor); | ||
log.debug("Query shape : {}", shapeVisitor.prettyPrintTree(" ")); | ||
} | ||
|
||
} |
Oops, something went wrong.