From 68a226e49448ea595a1df4f1d8bd04a412aff998 Mon Sep 17 00:00:00 2001 From: Siddhant Deshmukh Date: Mon, 24 Jun 2024 16:19:11 -0700 Subject: [PATCH] Javadocs Signed-off-by: Siddhant Deshmukh --- .../core/categorizer/QueryShapeVisitor.java | 9 ++++++++ .../SearchQueryAggregationCategorizer.java | 8 +++++++ .../categorizer/SearchQueryCategorizer.java | 17 ++++++++++++++- .../core/categorizer/SearchQueryCounters.java | 21 +++++++++++++++++++ .../core/service/QueryInsightsService.java | 1 + .../settings/QueryCategorizationSettings.java | 6 ++++++ 6 files changed, 61 insertions(+), 1 deletion(-) diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/QueryShapeVisitor.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/QueryShapeVisitor.java index 92724c9cc57b2..f967b05dc7258 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/QueryShapeVisitor.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/QueryShapeVisitor.java @@ -57,6 +57,10 @@ public QueryBuilderVisitor getChildVisitor(BooleanClause.Occur occur) { return childVisitorWrapper; } + /** + * Convert query builder tree to json + * @return + */ public String toJson() { StringBuilder outputBuilder = new StringBuilder("{\"type\":\"").append(queryType.get()).append("\""); for (Map.Entry> entry : childVisitors.entrySet()) { @@ -75,6 +79,11 @@ public String toJson() { return outputBuilder.toString(); } + /** + * Pretty print the query builder tree + * @param indent indent size + * @return + */ public String prettyPrintTree(String indent) { StringBuilder outputBuilder = new StringBuilder(indent).append(queryType.get()).append("\n"); for (Map.Entry> entry : childVisitors.entrySet()) { diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryAggregationCategorizer.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryAggregationCategorizer.java index 94a9b9182e9d7..31f12f57be562 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryAggregationCategorizer.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryAggregationCategorizer.java @@ -22,10 +22,18 @@ public class SearchQueryAggregationCategorizer { private static final String TYPE_TAG = "type"; private final SearchQueryCounters searchQueryCounters; + /** + * Constructor for SearchQueryAggregationCategorizer + * @param searchQueryCounters + */ public SearchQueryAggregationCategorizer(SearchQueryCounters searchQueryCounters) { this.searchQueryCounters = searchQueryCounters; } + /** + * Increment aggregation related counters + * @param aggregatorFactories input aggregations + */ public void incrementSearchQueryAggregationCounters(Collection aggregatorFactories) { for (AggregationBuilder aggregationBuilder : aggregatorFactories) { incrementCountersRecursively(aggregationBuilder); diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCategorizer.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCategorizer.java index cd8f3b3e978bf..96b91b6fd5bb0 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCategorizer.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCategorizer.java @@ -31,15 +31,26 @@ public final class SearchQueryCategorizer { private static final Logger log = LogManager.getLogger(SearchQueryCategorizer.class); + /** + * Contains all the search query counters + */ public final SearchQueryCounters searchQueryCounters; final SearchQueryAggregationCategorizer searchQueryAggregationCategorizer; + /** + * Constructor for SearchQueryCategorizor + * @param metricsRegistry + */ public SearchQueryCategorizer(MetricsRegistry metricsRegistry) { searchQueryCounters = new SearchQueryCounters(metricsRegistry); searchQueryAggregationCategorizer = new SearchQueryAggregationCategorizer(searchQueryCounters); } + /** + * Consume records and increment counters for the records + * @param records records to consume + */ public void consumeRecords(List records) { for (SearchQueryRecord record : records) { SearchSourceBuilder source = (SearchSourceBuilder) record.getAttributes().get(Attribute.SOURCE); @@ -47,6 +58,10 @@ public void consumeRecords(List records) { } } + /** + * Increment categorizations counters for the given source search query + * @param source search query source + */ public void categorize(SearchSourceBuilder source) { QueryBuilder topLevelQueryBuilder = source.query(); logQueryShape(topLevelQueryBuilder); @@ -58,7 +73,7 @@ public void categorize(SearchSourceBuilder source) { private void incrementQuerySortCounters(List> sorts) { if (sorts != null && sorts.size() > 0) { for (ListIterator> it = sorts.listIterator(); it.hasNext();) { - SortBuilder sortBuilder = it.next(); + SortBuilder sortBuilder = it.next(); String sortOrder = sortBuilder.order().toString(); searchQueryCounters.sortCounter.add(1, Tags.create().addTag("sort_order", sortOrder)); } diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCounters.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCounters.java index 42569b2978379..8c7c91f794f16 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCounters.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/categorizer/SearchQueryCounters.java @@ -24,12 +24,28 @@ public final class SearchQueryCounters { private static final String LEVEL_TAG = "level"; private static final String UNIT = "1"; private final MetricsRegistry metricsRegistry; + /** + * Aggregation counter + */ public final Counter aggCounter; + /** + * Counter for all other query types (catch all) + */ public final Counter otherQueryCounter; + /** + * Counter for sort + */ public final Counter sortCounter; private final Map, Counter> queryHandlers; + /** + * Counter name to Counter object map + */ public final ConcurrentHashMap nameToQueryTypeCounters; + /** + * Constructor + * @param metricsRegistry opentelemetry metrics registry + */ public SearchQueryCounters(MetricsRegistry metricsRegistry) { this.metricsRegistry = metricsRegistry; this.nameToQueryTypeCounters = new ConcurrentHashMap<>(); @@ -52,6 +68,11 @@ public SearchQueryCounters(MetricsRegistry metricsRegistry) { } + /** + * Increment counter + * @param queryBuilder query builder + * @param level level of query builder, 0 being highest level + */ public void incrementCounter(QueryBuilder queryBuilder, int level) { String uniqueQueryCounterName = queryBuilder.getName(); diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java index e81670a1d842d..7ee5e3cff4af6 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java @@ -89,6 +89,7 @@ public class QueryInsightsService extends AbstractLifecycleComponent { * @param clusterSettings OpenSearch cluster level settings * @param threadPool The OpenSearch thread pool to run async tasks * @param client OS client + * @param metricsRegistry Opentelemetry Metrics registry */ @Inject public QueryInsightsService(final ClusterSettings clusterSettings, final ThreadPool threadPool, final Client client, final MetricsRegistry metricsRegistry) { diff --git a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/settings/QueryCategorizationSettings.java b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/settings/QueryCategorizationSettings.java index 1220d58294bc0..a0d8873c4bb62 100644 --- a/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/settings/QueryCategorizationSettings.java +++ b/plugins/query-insights/src/main/java/org/opensearch/plugin/insights/settings/QueryCategorizationSettings.java @@ -10,7 +10,13 @@ import org.opensearch.common.settings.Setting; +/** + * Settings for Query Categorization + */ public class QueryCategorizationSettings { + /** + * Enabling search query metrics + */ public static final Setting SEARCH_QUERY_METRICS_ENABLED_SETTING = Setting.boolSetting( "search.query.metrics.enabled", false,