Latency reset update and latency histogram #3043
Open
+2,788
−1,277
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.
feat(client): implement LATENCY RESET UPDATE and LATENCY HISTOGRAM commands
Adds two new latency-related commands to the node-redis client:
LATENCY RESET
: Clears latency samples for specific events or all events.LATENCY HISTOGRAM
: Provides detailed latency distribution information for Redis events.Description
This Pull Request introduces two new Redis commands to the
node-redis
client, enhancing its capabilities for Redis performance monitoring and analysis.1.
LATENCY RESET
Command:parseCommand
to correctly format theLATENCY RESET
command with optional event arguments (e.g.,LATENCY RESET command
,LATENCY RESET fork
).transformReply
to handle the integer reply from Redis, representing the number of events reset.LATENCY_RESET.spec.ts
) are included for argument transformation and an integration test verifies end-to-end functionality against a live Redis server.2.
LATENCY HISTOGRAM
Command:parseCommand
to correctly format theLATENCY HISTOGRAM
command, supporting the optionalBUCKETS
argument.transformReply
to parse the nested array reply from Redis into a user-friendly array ofLatencyHistogramBucket
objects, correctly calculatingmax
values and handling'+inf'
.LATENCY_HISTOGRAM.spec.ts
) are included to ensureparseCommand
correctly transforms arguments (with and withoutBUCKETS
), andtransformReply
accurately parses various reply formats (typical, empty, single bucket, and malformed).client.latencyHistogram
against a live Redis server, including generating latency events and asserting the histogram's structure.General Changes for Both Commands:
packages/client/lib/commands/index.ts
to expose bothLATENCY RESET
andLATENCY HISTOGRAM
commands with their respective camelCase aliases (latencyReset
,latencyHistogram
).Testing Environment Note (Important!):
During local development and testing on a GCP Compute Engine VM, I encountered persistent timeouts related to Docker container startup and client connection. To ensure the tests could run to completion, I temporarily modified the internal timeout within
node_modules/@redis/test-utils/dist/lib/index.js
(specifically, increasingthis.timeout
in thetestWithClient
hook from 30s to 5min). This modification was purely for my local testing environment and is not part of this core contribution. It should not be merged into the main codebase. The tests were successfully run againstredislabs/client-libs-test:8.2-rc1
.