From 5154c693993531e9d7936c04f1b768b778b5b057 Mon Sep 17 00:00:00 2001 From: Siddhant Deshmukh Date: Tue, 17 Oct 2023 22:42:51 -0700 Subject: [PATCH] Add sort order as a tag to sort counter Signed-off-by: Siddhant Deshmukh --- .../opensearch/action/search/SearchQueryCategorizer.java | 8 +++++++- .../action/search/SearchQueryCategorizerTests.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java index df6a034d826bd..1049cf18a0ff1 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java @@ -17,8 +17,10 @@ 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. @@ -45,7 +47,11 @@ public void categorize(SearchSourceBuilder source) { private void incrementQuerySortCounters(List> sorts) { if (sorts != null && sorts.size() > 0) { - searchQueryCounters.sortCounter.add(1); + for (ListIterator> it = sorts.listIterator(); it.hasNext(); ) { + SortBuilder sortBuilder = it.next(); + String sortOrder = sortBuilder.order().toString(); + searchQueryCounters.sortCounter.add(1, Tags.create().addTag("sort_order", sortOrder)); + } } } diff --git a/server/src/test/java/org/opensearch/action/search/SearchQueryCategorizerTests.java b/server/src/test/java/org/opensearch/action/search/SearchQueryCategorizerTests.java index b990dfcee699e..568ab5a7dbc8c 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchQueryCategorizerTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchQueryCategorizerTests.java @@ -181,7 +181,7 @@ public void testSortQuery() { searchQueryCategorizer.categorize(sourceBuilder); Mockito.verify(searchQueryCategorizer.searchQueryCounters.matchCounter).add(eq(1.0d), any(Tags.class)); - Mockito.verify(searchQueryCategorizer.searchQueryCounters.sortCounter).add(eq(1.0d)); + Mockito.verify(searchQueryCategorizer.searchQueryCounters.sortCounter, times(2)).add(eq(1.0d), any(Tags.class)); } public void testTermQuery() {