Skip to content

Latency reset update and latency histogram #3043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

watersRand
Copy link

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:

  • Purpose: Allows users to programmatically reset Redis latency statistics, enabling cleaner monitoring cycles or targeted troubleshooting.
  • Implementation Details:
    • Implemented parseCommand to correctly format the LATENCY RESET command with optional event arguments (e.g., LATENCY RESET command, LATENCY RESET fork).
    • Implemented transformReply to handle the integer reply from Redis, representing the number of events reset.
    • Comprehensive unit tests (LATENCY_RESET.spec.ts) are included for argument transformation and an integration test verifies end-to-end functionality against a live Redis server.
  • Redis Documentation Reference: https://redis.io/commands/latency-reset/

2. LATENCY HISTOGRAM Command:

  • Purpose: Provides granular insights into command execution times and other event latencies by exposing Redis's internal latency histograms.
  • Implementation Details:
    • Implemented parseCommand to correctly format the LATENCY HISTOGRAM command, supporting the optional BUCKETS argument.
    • Implemented transformReply to parse the nested array reply from Redis into a user-friendly array of LatencyHistogramBucket objects, correctly calculating max values and handling '+inf'.
    • Comprehensive unit tests (LATENCY_HISTOGRAM.spec.ts) are included to ensure parseCommand correctly transforms arguments (with and without BUCKETS), and transformReply accurately parses various reply formats (typical, empty, single bucket, and malformed).
    • An integration test is provided to verify the end-to-end functionality of client.latencyHistogram against a live Redis server, including generating latency events and asserting the histogram's structure.
  • Redis Documentation Reference: https://redis.io/commands/latency-histogram/

General Changes for Both Commands:

  • Updated packages/client/lib/commands/index.ts to expose both LATENCY RESET and LATENCY 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, increasing this.timeout in the testWithClient 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 against redislabs/client-libs-test:8.2-rc1.

watersRand and others added 5 commits July 28, 2025 14:36
Adds the LATENCY RESET command to the client, including:
- transformArguments and transformReply logic.
- Comprehensive unit tests for argument transformation.
- An integration test to verify end-to-end functionality.
- Updates to packages/client/lib/commands/index.ts to expose the command.
Copy link
Collaborator

@nkaradzhov nkaradzhov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove package-lock.json
Can you also fix the formatting

IS_READ_ONLY: true,


parseCommand(parser: CommandParser, event: LatencyEvent, options?: LatencyHistogramOptions) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add jsdoc here

IS_READ_ONLY: false,


parseCommand(parser: CommandParser, ...events: Array<LatencyEvent>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add jsdoc here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants