From 52b968acc98afced69f5f4f49a9d2d78358768d1 Mon Sep 17 00:00:00 2001 From: Radhakrishnan Pachyappan Date: Sun, 5 Jul 2026 11:18:24 +0530 Subject: [PATCH] Register status_counter as a filterable index metric in node stats API status_counter was introduced via #19115 but was never added to CommonStatsFlags.Flag, so it was always included in node stats responses regardless of which specific index metric was requested. Callers targeting a single metric such as: GET _nodes/stats/indices/request_cache consistently received status_counter alongside the requested metric. Fix: add Flag.StatusCounter("status_counter", 17) to CommonStatsFlags. RestNodesStatsAction already builds its FLAGS map by iterating all Flag values, so the new flag is auto-registered as a valid filterable metric name. IndicesService.stats() now gates statusCounterStats on flags.isSet(Flag.StatusCounter) so the field is only included when explicitly requested (or when _all metrics are requested). Fixes #22383 Signed-off-by: Radhakrishnan Pachyappan --- .../action/admin/indices/stats/CommonStatsFlags.java | 3 ++- .../java/org/opensearch/indices/IndicesService.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/indices/stats/CommonStatsFlags.java b/server/src/main/java/org/opensearch/action/admin/indices/stats/CommonStatsFlags.java index 03fb55323feec..1e1d213e7400f 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/stats/CommonStatsFlags.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/stats/CommonStatsFlags.java @@ -332,7 +332,8 @@ public enum Flag { Translog("translog", 13), // 14 was previously used for Suggest RequestCache("request_cache", 15), - Recovery("recovery", 16); + Recovery("recovery", 16), + StatusCounter("status_counter", 17); private final String restName; private final int index; diff --git a/server/src/main/java/org/opensearch/indices/IndicesService.java b/server/src/main/java/org/opensearch/indices/IndicesService.java index 247dc866de0d3..5bd7e1bcd5b99 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesService.java +++ b/server/src/main/java/org/opensearch/indices/IndicesService.java @@ -919,11 +919,18 @@ public NodeIndicesStats stats(CommonStatsFlags flags) { break; } } + // Only include status_counter when it is explicitly requested (or when all flags are set). + // Previously it was always included regardless of the requested index metrics, causing it + // to appear even for targeted requests like GET _nodes/stats/indices/request_cache. + // See https://github.com/opensearch-project/OpenSearch/issues/22383 + final StatusCounterStats resolvedStatusCounterStats = flags.isSet(CommonStatsFlags.Flag.StatusCounter) + ? statusCounterStats + : null; if (flags.getIncludeIndicesStatsByLevel()) { NodeIndicesStats.StatsLevel statsLevel = NodeIndicesStats.getAcceptedLevel(flags.getLevels()); - return new NodeIndicesStats(commonStats, statsByShard(this, flags), searchRequestStats, statusCounterStats, statsLevel); + return new NodeIndicesStats(commonStats, statsByShard(this, flags), searchRequestStats, resolvedStatusCounterStats, statsLevel); } else { - return new NodeIndicesStats(commonStats, statsByShard(this, flags), searchRequestStats, statusCounterStats); + return new NodeIndicesStats(commonStats, statsByShard(this, flags), searchRequestStats, resolvedStatusCounterStats); } }