feat(server): implement LATENCY command set (Redis 7.0+ compatibility)#3461
feat(server): implement LATENCY command set (Redis 7.0+ compatibility)#3461gongna-au wants to merge 2 commits intoapache:unstablefrom
Conversation
|
@gongna-au Could you please add Go tests to ensure the new command works as expected? |
b6c874c to
37d0dac
Compare
|
@git-hulk already |
jihuayu
left a comment
There was a problem hiding this comment.
Greate. Please skip commands with calls == 0 in LATENCY HISTOGRAM [command ...]. Redis returns an empty reply for commands with no recorded samples, rather than an empty histogram entry.
I have a small question: why did you put this command in a separate file instead of keeping it in cmd_server?
37d0dac to
5f23f30
Compare
|
@jihuayu Good point! I've moved CommandLatency into cmd_server.cc alongside other server diagnostic commands (SLOWLOG, PERFLOG, etc.). Also fixed the calls==0 skip for filtered histogram queries. Thanks for the review! |
Implement LATENCY HISTOGRAM, LATENCY RESET and LATENCY HELP subcommands compatible with Redis 7.0 protocol. Skip commands with zero calls in histogram output. Add Go integration tests covering all subcommands, error handling, histogram output structure, filtering and zero-calls exclusion. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
5f23f30 to
8353f68
Compare
|



Summary
This PR implements the
LATENCYcommand for Kvrocks, focusing on theLATENCY HISTOGRAMsubcommand introduced in Redis 7.0. It leverages the existing histogram infrastructure (histogram-bucket-boundariesconfig +CommandHistogramstats) to expose per-command latency distributions via the standard Redis protocol.Changes
New File:
src/commands/cmd_latency.ccImplements
CommandLatencywith three subcommands:LATENCY HISTOGRAM [command ...]— Returns a cumulative distribution of command latencies.calls(integer) andhistogram_usec(map of boundary → cumulative count).CommandHistogram::bucketsare converted to cumulative sums at output time."inf".histogram-bucket-boundariesis not configured.LATENCY RESET [event ...]— Returns(integer) 0.LATENCY LATEST/HISTORY/GRAPH), which Kvrocks does not have. Per Redis docs, histogram data is reset viaCONFIG RESETSTAT, notLATENCY RESET. Returning 0 correctly indicates no event classes were reset.LATENCY HELP— Returns usage information for all supported subcommands.Build System
No changes needed. The file is automatically picked up by
file(GLOB_RECURSE KVROCKS_SRCS src/*.cc)in rootCMakeLists.txt.Command Registration
Registered under
CommandCategory::ServerviaREDIS_REGISTER_COMMANDS(Server, ...), same category ascmd_server.cc. This is safe because the macro generates unique static variables per translation unit using__LINE__.Compatibility
LATENCY HISTOGRAM [cmd ...]histogram_usecfield, empty buckets skippedLATENCY HELPLATENCY RESET [event ...]LATENCY LATESTLATENCY HISTORY eventLATENCY GRAPH eventLATENCY DOCTORConfiguration Prerequisite
Histograms are only tracked when
histogram-bucket-boundariesis set inkvrocks.conf. Example:If empty (default),
LATENCY HISTOGRAMreturns an empty map — this is expected behavior, not an error.RESP Protocol Details
%) viaconn->HeaderOfMap(), which auto-degrades to interleaved RESP2 arrays.