Skip to content

Commit

Permalink
Add sort order as a tag to sort counter
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
  • Loading branch information
deshsidd committed Oct 18, 2023
1 parent 0ace75b commit 5154c69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,7 +47,11 @@ public void categorize(SearchSourceBuilder source) {

private void incrementQuerySortCounters(List<SortBuilder<?>> sorts) {
if (sorts != null && sorts.size() > 0) {
searchQueryCounters.sortCounter.add(1);
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));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5154c69

Please sign in to comment.