-
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.
Capture query categorization metrics for additional query types and a…
…ggregations types (#11582) Signed-off-by: Siddhant Deshmukh <[email protected]>
- Loading branch information
Showing
7 changed files
with
286 additions
and
67 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
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/opensearch/action/search/SearchQueryAggregationCategorizer.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,55 @@ | ||
/* | ||
* 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.opensearch.search.aggregations.AggregationBuilder; | ||
import org.opensearch.search.aggregations.PipelineAggregationBuilder; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Increments the counters related to Aggregation Search Queries. | ||
*/ | ||
public class SearchQueryAggregationCategorizer { | ||
|
||
private static final String TYPE_TAG = "type"; | ||
private final SearchQueryCounters searchQueryCounters; | ||
|
||
public SearchQueryAggregationCategorizer(SearchQueryCounters searchQueryCounters) { | ||
this.searchQueryCounters = searchQueryCounters; | ||
} | ||
|
||
public void incrementSearchQueryAggregationCounters(Collection<AggregationBuilder> aggregatorFactories) { | ||
for (AggregationBuilder aggregationBuilder : aggregatorFactories) { | ||
incrementCountersRecursively(aggregationBuilder); | ||
} | ||
} | ||
|
||
private void incrementCountersRecursively(AggregationBuilder aggregationBuilder) { | ||
// Increment counters for the current aggregation | ||
String aggregationType = aggregationBuilder.getType(); | ||
searchQueryCounters.aggCounter.add(1, Tags.create().addTag(TYPE_TAG, aggregationType)); | ||
|
||
// Recursively process sub-aggregations if any | ||
Collection<AggregationBuilder> subAggregations = aggregationBuilder.getSubAggregations(); | ||
if (subAggregations != null && !subAggregations.isEmpty()) { | ||
for (AggregationBuilder subAggregation : subAggregations) { | ||
incrementCountersRecursively(subAggregation); | ||
} | ||
} | ||
|
||
// Process pipeline aggregations | ||
Collection<PipelineAggregationBuilder> pipelineAggregations = aggregationBuilder.getPipelineAggregations(); | ||
for (PipelineAggregationBuilder pipelineAggregation : pipelineAggregations) { | ||
String pipelineAggregationType = pipelineAggregation.getType(); | ||
searchQueryCounters.aggCounter.add(1, Tags.create().addTag(TYPE_TAG, pipelineAggregationType)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.