Repository navigation
feat(topology): show INFO metrics and utilization for replica nodes in Cluster Topology #577
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
base: main
Are you sure you want to change the base?
Changes from all commits
bde3882
3d71090
b734bcb
6cdda62
b72c3a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, it, expect } from "vitest" | ||
| import { buildNodeRows, aggregateClusterMetrics } from "./clusterSelectors" | ||
| import type { PrimaryNode, NodeUtilization } from "./clusterSlice" | ||
|
|
||
| describe("clusterSelectors", () => { | ||
| const mockClusterNodes: Record<string, PrimaryNode> = { | ||
| "node-primary-1": { | ||
| host: "127.0.0.1", | ||
| port: 7000, | ||
| tls: false, | ||
| verifyTlsCertificate: false, | ||
| replicas: [ | ||
| { | ||
| id: "node-replica-1", | ||
| host: "127.0.0.1", | ||
| port: 7001, | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| describe("buildNodeRows", () => { | ||
| it("builds node rows with primary and its replicas", () => { | ||
| const rows = buildNodeRows(mockClusterNodes) | ||
| expect(rows).toHaveLength(2) | ||
| expect(rows[0]).toMatchObject({ | ||
| role: "primary", | ||
| host: "127.0.0.1", | ||
| port: 7000, | ||
| isGroupEnd: false, | ||
| }) | ||
| expect(rows[1]).toMatchObject({ | ||
| role: "replica", | ||
| host: "127.0.0.1", | ||
| port: 7001, | ||
| isGroupEnd: true, | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe("aggregateClusterMetrics", () => { | ||
| it("flags high utilization nodes across both primaries and replicas", () => { | ||
| const rows = buildNodeRows(mockClusterNodes) | ||
| const mockData = { | ||
| "node-primary-1": { | ||
| instantaneous_ops_per_sec: "150", | ||
| keyspace_hits: "100", | ||
| keyspace_misses: "10", | ||
| }, | ||
| "127-0-0-1-7001": { | ||
| instantaneous_ops_per_sec: "50", | ||
| keyspace_hits: "40", | ||
| keyspace_misses: "5", | ||
| }, | ||
| } | ||
| const mockUtilization: Record<string, NodeUtilization> = { | ||
| "node-primary-1": { | ||
| nodeId: "node-primary-1", | ||
| used_memory: 1000, | ||
| memory_limit_bytes: 2000, | ||
| memory_basis: "maxmemory", | ||
| memory_utilization_percent: 50, | ||
| cpu_utilization_percent: 85, // high CPU | ||
| cpu_sample_interval_seconds: null, | ||
| warnings: [], | ||
| }, | ||
| "127-0-0-1-7001": { | ||
| nodeId: "127-0-0-1-7001", | ||
| used_memory: 500, | ||
| memory_limit_bytes: 2000, | ||
| memory_basis: "maxmemory", | ||
| memory_utilization_percent: 25, | ||
| cpu_utilization_percent: 90, // high CPU on replica | ||
| cpu_sample_interval_seconds: null, | ||
| warnings: [], | ||
| }, | ||
| } | ||
|
|
||
| const metrics = aggregateClusterMetrics(rows, mockData, mockUtilization) | ||
|
|
||
| expect(metrics.hasUtilization).toBe(true) | ||
| expect(metrics.usedMemory).toBe(1500) | ||
| expect(metrics.memoryLimit).toBe(4000) | ||
| expect(metrics.opsPerSec).toBe(200) | ||
| expect(metrics.hits).toBe(140) | ||
| expect(metrics.misses).toBe(15) | ||
| // Both primary and replica with high utilization should be flagged | ||
| expect(metrics.flaggedNodes).toBe(2) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,8 +97,8 @@ export const aggregateClusterMetrics = ( | |
| metrics.hits += Number(nodeData?.keyspace_hits) || 0 | ||
| metrics.misses += Number(nodeData?.keyspace_misses) || 0 | ||
|
|
||
| // Badges render on primaries only, so replicas must not inflate the count. | ||
| if (row.role === "primary" && getNodeUtilizationLevel(nodeUtilization) === "high") { | ||
| // Count high utilization nodes across the cluster. | ||
| if (getNodeUtilizationLevel(nodeUtilization) === "high") { | ||
|
Comment on lines
+100
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Align the utilization filter in
Remove the Proposed fix in Cluster.tsx- const matchesUtilization = utilizationFilter === "all"
- || (row.role === "primary" && level === utilizationFilter)
+ const matchesUtilization = utilizationFilter === "all" || level === utilizationFilter🤖 Prompt for AI Agents |
||
| metrics.flaggedNodes += 1 | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.