[dev] Add INFO COMMANDSTATS tracking with per-command success rates#1728
Merged
Mathos1432 merged 5 commits intodevfrom Apr 24, 2026
Merged
[dev] Add INFO COMMANDSTATS tracking with per-command success rates#1728Mathos1432 merged 5 commits intodevfrom
Mathos1432 merged 5 commits intodevfrom
Conversation
Implements Redis-compatible INFO COMMANDSTATS support, gated behind --commandstats-monitor config flag. Tracks per-command calls, failed_calls, and rejected_calls using lightweight counter increments (no Stopwatch). Key design decisions: - Array-indexed by RespCommand enum for O(1) access - Per-session counters (single-writer, no locking on hot path) - On-demand aggregation from active sessions + disposed session history - No latency tracking (usec=0) to avoid Stopwatch overhead - Monitor dispose handles case where Start() was never called (EmbeddedServer) - Include LatencyMonitor in monitor creation condition to fix pre-existing NRE - Use Enum.GetValues for resetEventFlags to fix pre-existing KeyNotFoundException Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…matrembl/commandstats-dev
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Redis-compatible INFO COMMANDSTATS support to Garnet, enabling per-command observability (calls / failed_calls / rejected_calls) with low overhead and opt-in tracking.
Changes:
- Introduces
CommandStatsdata structure (array-indexed byRespCommand) and wires per-session tracking + history aggregation. - Extends INFO plumbing to support a new
COMMANDSTATSsection (excluded from default INFO) and exposes enablement via CLI/config. - Adds unit tests validating disabled behavior, call/failure tracking, formatting, and INFO section exclusions.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Garnet.test/TestUtils.cs | Adds commandStatsMonitor parameter to test server creation. |
| test/Garnet.test/RespInfoTests.cs | Extends INFO section exclusion assertions to include additional sections + Commandstats. |
| test/Garnet.test/RespCommandStatsTests.cs | Adds coverage for COMMANDSTATS output and tracking behavior. |
| libs/server/StoreWrapper.cs | Ensures GarnetServerMonitor is created when commandstats/latency monitors are enabled. |
| libs/server/SessionParseStateExtensions.cs | Adds parser support for COMMANDSTATS section token. |
| libs/server/Servers/GarnetServerOptions.cs | Adds CommandStatsMonitor option to server configuration. |
| libs/server/Resp/RespServerSessionOutput.cs | Marks commandErrorWritten when WriteError helpers are used. |
| libs/server/Resp/RespServerSession.cs | Adds per-session CommandStats and increments calls/failed/rejected counters. |
| libs/server/Resp/Objects/ObjectStoreUtils.cs | Marks commandErrorWritten for abort/error helper path. |
| libs/server/Metrics/Info/GarnetInfoMetrics.cs | Adds INFO COMMANDSTATS section generation + aggregation logic. |
| libs/server/Metrics/GarnetServerMonitor.cs | Adds history aggregation for commandstats, reset support, and Start/Dispose fix. |
| libs/server/Metrics/GarnetServerMetrics.cs | Adds global + history commandstats fields to global metrics. |
| libs/server/Metrics/CommandStats.cs | Implements the per-command counters and aggregation/reset helpers. |
| libs/host/defaults.conf | Adds default config entry for CommandStatsMonitor. |
| libs/host/Configuration/Redis/RedisOptions.cs | Adds commandstats-tracking config alias mapping. |
| libs/host/Configuration/Options.cs | Adds --commandstats-monitor CLI flag and wires it into server options. |
| libs/common/Metrics/InfoMetricsType.cs | Adds COMMANDSTATS enum value for INFO sections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kevin-montrose
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this change being made?
Garnet lacks Redis-compatible command usage statistics. Users and monitoring tools that rely on
INFO COMMANDSTATSget no data, making it harder to understand workload composition and identify failing commands. This cherry-picks #1702 (merged to main) onto dev.What changed?
How was this validated?