Skip to content

refactor(metrics): key CPU and memory state by nodeId instead of connectionId - #567

Closed
RajGahoi wants to merge 1 commit into
valkey-io:mainfrom
RajGahoi:feat/key-metrics-by-node-id
Closed

RajGahoi wants to merge 1 commit into
valkey-io:mainfrom
RajGahoi:feat/key-metrics-by-node-id

Conversation

@RajGahoi

Copy link
Copy Markdown
Contributor

Fixes #464

Description

Memory and CPU usage metrics are fetched from the metrics server at the node level. Previously, the backend tagged replies with \connectionId\ and the frontend stored state per connection. Consequently, when multiple connections existed to the same node across different databases (e.g. \host-6379-db0\ and \host-6379-db1), duplicate copies of the same CPU and memory data were stored in state.

This PR addresses #464 by:

  1. Server-Side Alignment: In \cpuUsageRequested\ and \memoryUsageRequested, emits fulfilled and error messages tagged with the db-less
    odeId\ (\ oNodeId(connectionId)).
  2. Frontend Redux Slices: In \cpuSlice\ and \memorySlice, keys requested, fulfilled, and error entries by
    odeId\ (using \ oNodeId), collapsing multiple database connections to the same node into a single source of truth.
  3. Selector Compatibility: Updates \selectCpuUsage, \selectCpuUsageLoading, \selectMemoryUsage, and \selectMemoryUsageLoading\ to accept both
    odeId\ and db-suffixed \connectionId\ via \ oNodeId, maintaining seamless compatibility with existing component calls.
  4. Unit Tests: Added comprehensive test suites (\cpuSlice.test.ts\ and \memorySlice.test.ts) verifying that requests from different databases collapse into a single node entry, errors and fulfilled payloads update correctly, and selectors resolve cleanly.

Testing


  • pm --workspace apps/frontend run lint: 0 errors

  • pm --workspace apps/frontend run test: 19 test suites, 250 tests passed (100% green)

  • pm --workspace apps/server run lint: 0 errors

…ectionId (fixes valkey-io#464)

Signed-off-by: Raj Gahoi <gahoiraj01@gmail.com>
@github-actions github-actions Bot added area/frontend UI components, state, routing area/server Backend, WebSocket, actions labels Oct 17, 2026
@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0713cbb-08e7-424d-8148-ca4b8af18343
📥 Commits

Reviewing files that changed from the base of the PR and between 0161e2a and c8f4fad.

📒 Files selected for processing: 6
  • apps/frontend/src/state/valkey-features/cpu/cpuSlice.test.ts
  • apps/frontend/src/state/valkey-features/cpu/cpuSlice.ts
  • apps/frontend/src/state/valkey-features/memory/memorySlice.test.ts
  • apps/frontend/src/state/valkey-features/memory/memorySlice.ts
  • apps/server/src/actions/cpuUsage.ts
  • apps/server/src/actions/memoryUsage.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

📝 Walkthrough

CPU and memory metrics now use node IDs in server messages and frontend state. Frontend selectors and reducers resolve database-specific connection IDs to node IDs. Added tests cover requests, responses, errors, and selectors.

Changes: Node-keyed CPU and memory metrics

Layer / File(s) Summary
Normalize server metrics messages
apps/server/src/actions/cpuUsage.ts, apps/server/src/actions/memoryUsage.ts
The CPU and memory handlers derive a node ID for metrics-server lookups and include it in success and error messages.
Key frontend state by node
apps/frontend/src/state/valkey-features/cpu/cpuSlice.ts, apps/frontend/src/state/valkey-features/cpu/cpuSlice.test.ts, apps/frontend/src/state/valkey-features/memory/memorySlice.ts, apps/frontend/src/state/valkey-features/memory/memorySlice.test.ts
The reducers and selectors resolve state keys to node IDs. Tests cover explicit node IDs, database-suffixed connection IDs, invalid responses, errors, and loading state.

Suggested reviewers: nassery318

Priority: ⬇️ Low

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to c8f4f

CPU and memory metrics remain accessible across database connections to the same node. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: CPU and memory state now use nodeId instead of connectionId.
Description check Passed The description explains the problem, implementation, compatibility behavior, tests, and reported validation results. It omits the requested Change Visualization, but the core description is complete.
Linked Issues check Passed Issue #464 requires CPU and memory state to use nodeId because metrics are node-level. The CPU and memory reducers now resolve nodeId with toNodeId and store requests, fulfilled data, and errors under…
Out of Scope Changes check Passed The changed files are limited to CPU and memory metric server actions, Redux slices, and their unit tests. These changes directly implement issue #464 and provide supporting test coverage. No unrelate…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6…
Full details: Linked Issues check

Explanation

Issue #464 requires CPU and memory state to use nodeId because metrics are node-level. The CPU and memory reducers now resolve nodeId with toNodeId and store requests, fulfilled data, and errors under that key. The selectors also normalize database-suffixed connectionId values. The server CPU action emits nodeId in success and error payloads, and the PR summary reports the same change for memory. Added tests cover multi-database collapsing, payload handling, errors, and selector access.

Full details: Out of Scope Changes check

Explanation

The changed files are limited to CPU and memory metric server actions, Redux slices, and their unit tests. These changes directly implement issue #464 and provide supporting test coverage. No unrelated behavior is identified.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6 files.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ArgusLi

ArgusLi commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Hi @RajGahoi, thank you for this PR and for the tests on both slices.

We are going to close it for now. Changing the key of the CPU and memory state is a decision about the state model, and #464 does not define it fully:

  • Clusters. Hot keys, big keys and command logs use clusterId for a cluster and nodeId for a standalone node. This PR uses nodeId in both cases, and the issue does not say which is correct.
  • Time ranges. Each entry holds a series for the time range that the requester chose. When all databases on a node share one entry, a request from one database replaces the chart of another. For example, the 1 h metrics-readiness retry can replace a 24 h chart. fix(dashboard): prevent time range race condition on CPU and memory metrics charts (#590) #591 changes the same entries, so the two designs must agree.
  • Cluster identity. We are now changing how the server represents clusters and nodes, and that work decides which identifier this state should use.

Our contribution guide asks for an approved design before changes like this. We will post on #464 when the cluster work decides the identifiers. If you want to work on it then, please open a Design Discussion that answers the questions above, and tag the maintainers.

Thanks again for your work on the dashboard metrics.

@ArgusLi ArgusLi closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/frontend UI components, state, routing area/server Backend, WebSocket, actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory and CPU state keyed by connectionId instead of nodeId

2 participants