Skip to content

Commit

Permalink
Usage counter for Top N queries using OperationalMetric
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <[email protected]>
  • Loading branch information
deshsidd committed Nov 7, 2024
1 parent 8f92d2f commit 82435cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum OperationalMetric {
INVALID_INDEX_PATTERN_EXCEPTIONS("Number of invalid index pattern exceptions"),
DATA_INGEST_EXCEPTIONS("Number of exceptions during data ingest in Query Insights"),
QUERY_CATEGORIZE_EXCEPTIONS("Number of exceptions when categorizing the queries"),
EXPORTER_FAIL_TO_CLOSE_EXCEPTION("Number of failures when closing the exporter");
EXPORTER_FAIL_TO_CLOSE_EXCEPTION("Number of failures when closing the exporter"),
TOP_N_QUERIES_USAGE_COUNT("Number of times the top n queries API is used");

private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord;
import org.opensearch.plugin.insights.rules.model.healthStats.TopQueriesHealthStats;
import org.opensearch.plugin.insights.settings.QueryInsightsSettings;
import org.opensearch.telemetry.metrics.tags.Tags;
import org.opensearch.threadpool.ThreadPool;

/**
* Service responsible for gathering and storing top N queries
* with high latency or resource usage
*/
public class TopQueriesService {
private static final String METRIC_TYPE_TAG = "metric_type";
private static final String GROUPBY_TAG = "groupby";

/**
* Logger of the local index exporter
*/
Expand Down Expand Up @@ -344,6 +348,9 @@ public void validateExporterAndReaderConfig(Settings settings) {
*/
public List<SearchQueryRecord> getTopQueriesRecords(final boolean includeLastWindow, final String from, final String to)
throws IllegalArgumentException {
OperationalMetricsCounter.getInstance().incrementCounter(
OperationalMetric.TOP_N_QUERIES_USAGE_COUNT,
Tags.create().addTag(METRIC_TYPE_TAG, this.metricType.name()).addTag(GROUPBY_TAG, this.queryGrouper.getGroupingType().name()));
if (!enabled) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Cannot get top n queries for [%s] when it is not enabled.", metricType.toString())
Expand Down

0 comments on commit 82435cb

Please sign in to comment.