Skip to content

Commit e1cf9f7

Browse files
authored
server_family: Support resetting latency histogram (#5428)
When command `config resetstat` is called, reset (clear out) all histograms for commands.
1 parent 5f65a65 commit e1cf9f7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/server/command_registry.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ optional<facade::ErrorReply> CommandId::Validate(CmdArgList tail_args) const {
219219
return nullopt;
220220
}
221221

222+
void CommandId::ResetStats(unsigned thread_index) {
223+
command_stats_[thread_index] = {0, 0};
224+
if (hdr_histogram* h = latency_histogram_; h != nullptr) {
225+
hdr_reset(h);
226+
}
227+
}
228+
222229
hdr_histogram* CommandId::LatencyHist() const {
223230
return latency_histogram_;
224231
}

src/server/command_registry.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ class CommandId : public facade::CommandId {
170170
return (last_key_ != first_key_) || (opt_mask_ & CO::VARIADIC_KEYS);
171171
}
172172

173-
void ResetStats(unsigned thread_index) {
174-
command_stats_[thread_index] = {0, 0};
175-
}
173+
void ResetStats(unsigned thread_index);
176174

177175
CmdCallStats GetStats(unsigned thread_index) const {
178176
return command_stats_[thread_index];

tests/dragonfly/server_family_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ async def test_latency_stats(async_client: aioredis.Redis):
236236
assert key in latency_stats
237237
assert latency_stats[key].keys() == {"p50", "p99", "p99.9"}
238238

239+
await async_client.config_resetstat()
240+
latency_stats = await async_client.info("LATENCYSTATS")
241+
# Only stats for the `config resetstat` command should remain in stats
242+
assert (
243+
len(latency_stats) == 1 and "latency_percentiles_usec_config" in latency_stats,
244+
f"unexpected latency stats after reset: {latency_stats}",
245+
)
246+
239247

240248
async def test_latency_stats_disabled_by_default(async_client: aioredis.Redis):
241249
for _ in range(100):

0 commit comments

Comments
 (0)