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 50b2eaa54f0af..f9a1c0c4393f3 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizer.java @@ -69,8 +69,7 @@ private void logQueryShape(QueryBuilder topLevelQueryBuilder) { } QueryShapeVisitor shapeVisitor = new QueryShapeVisitor(); topLevelQueryBuilder.visit(shapeVisitor); - String indentedQueryShape = shapeVisitor.prettyPrintTree(" "); - log.debug("Query shape : " + indentedQueryShape); + log.debug("Query shape : {}", shapeVisitor.prettyPrintTree(" ")); } } diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java index ac0dcf701a2ed..b15ffb0e86ce4 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java @@ -28,6 +28,7 @@ * Increments the counters related to Search Query type. */ public class SearchQueryCategorizingVisitor implements QueryBuilderVisitor { + public static final String LEVEL_TAG = "level"; private final int level; private final SearchQueryCounters searchQueryCounters; @@ -42,27 +43,27 @@ private SearchQueryCategorizingVisitor(SearchQueryCounters counters, int level) public void accept(QueryBuilder qb) { if (qb instanceof BoolQueryBuilder) { - searchQueryCounters.boolCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.boolCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof FunctionScoreQueryBuilder) { - searchQueryCounters.functionScoreCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.functionScoreCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof MatchQueryBuilder) { - searchQueryCounters.matchCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.matchCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof MatchPhraseQueryBuilder) { - searchQueryCounters.matchPhrasePrefixCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.matchPhrasePrefixCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof MultiMatchQueryBuilder) { - searchQueryCounters.multiMatchCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.multiMatchCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof QueryStringQueryBuilder) { - searchQueryCounters.queryStringQueryCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.queryStringQueryCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof RangeQueryBuilder) { - searchQueryCounters.rangeCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.rangeCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof RegexpQueryBuilder) { - searchQueryCounters.regexCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.regexCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof TermQueryBuilder) { - searchQueryCounters.termCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.termCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else if (qb instanceof WildcardQueryBuilder) { - searchQueryCounters.wildcardCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.wildcardCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } else { - searchQueryCounters.otherQueryCounter.add(1, Tags.create().addTag("level", level)); + searchQueryCounters.otherQueryCounter.add(1, Tags.create().addTag(LEVEL_TAG, level)); } } diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java index e44c88262e712..da3a24af3e2a0 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java @@ -38,77 +38,77 @@ public class SearchQueryCounters { public SearchQueryCounters(MetricsRegistry metricsRegistry) { this.metricsRegistry = metricsRegistry; this.aggCounter = metricsRegistry.createCounter( - "aggSearchQueryCounter", + "search.query.type.agg.count", "Counter for the number of top level agg search queries", "0" ); this.boolCounter = metricsRegistry.createCounter( - "boolSearchQueryCounter", + "search.query.type.bool.count", "Counter for the number of top level and nested bool search queries", "0" ); this.functionScoreCounter = metricsRegistry.createCounter( - "functionScoreSearchQueryCounter", + "search.query.type.functionscore.count", "Counter for the number of top level and nested function score search queries", "0" ); this.matchCounter = metricsRegistry.createCounter( - "matchSearchQueryCounter", + "search.query.type.match.count", "Counter for the number of top level and nested match search queries", "0" ); this.matchPhrasePrefixCounter = metricsRegistry.createCounter( - "matchPhrasePrefixSearchQueryCounter", + "search.query.type.matchphrase.count", "Counter for the number of top level and nested match phrase prefix search queries", "0" ); this.multiMatchCounter = metricsRegistry.createCounter( - "multiMatchSearchQueryCounter", + "search.query.type.multimatch.count", "Counter for the number of top level and nested multi match search queries", "0" ); this.otherQueryCounter = metricsRegistry.createCounter( - "otherSearchQueryCounter", + "search.query.type.other.count", "Counter for the number of top level and nested search queries that do not match any other categories", "0" ); this.queryStringQueryCounter = metricsRegistry.createCounter( - "queryStringQuerySearchQueryCounter", + "search.query.type.querystringquery.count", "Counter for the number of top level and nested queryStringQuery search queries", "0" ); this.rangeCounter = metricsRegistry.createCounter( - "rangeSearchQueryCounter", + "search.query.type.range.count", "Counter for the number of top level and nested range search queries", "0" ); this.regexCounter = metricsRegistry.createCounter( - "regexSearchQueryCounter", + "search.query.type.regex.count", "Counter for the number of top level and nested regex search queries", "0" ); this.skippedCounter = metricsRegistry.createCounter( - "skippedQueryCounter", + "search.query.type.skipped.count", "Counter for the number queries skipped due to error", "0" ); this.sortCounter = metricsRegistry.createCounter( - "sortSearchQueryCounter", + "search.query.type.sort.count", "Counter for the number of top level sort search queries", "0" ); this.termCounter = metricsRegistry.createCounter( - "termSearchQueryCounter", + "search.query.type.term.count", "Counter for the number of top level and nested term search queries", "0" ); this.totalCounter = metricsRegistry.createCounter( - "totalSearchQueryCounter", + "search.query.type.total.count", "Counter for the number of top level and nested search queries", "0" ); this.wildcardCounter = metricsRegistry.createCounter( - "wildcardSearchQueryCounter", + "search.query.type.wildcard.count", "Counter for the number of top level and nested wildcard search queries", "0" ); diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index cf04d9b2618df..9bde1fa889ee4 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -138,8 +138,8 @@ public class TransportSearchAction extends HandledTransportAction SEARCH_QUERY_CATEGORIZATION_ENABLED_SETTING = Setting.boolSetting( - "search.query.categorization.enabled", + public static final Setting SEARCH_QUERY_METRICS_ENABLED_SETTING = Setting.boolSetting( + "search.query.metrics.enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic @@ -185,7 +185,7 @@ public class TransportSearchAction extends HandledTransportAction