-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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) (#11809) (cherry picked from commit e948c40) Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0134c5c
commit f9fd183
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.