Repository navigation
fix(dashboard): prevent time range race condition on CPU and memory metrics charts (#590) #591
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
Merged
ArgusLi
merged 3 commits into
valkey-io:main
from
RajGahoi:fix/dashboard-metrics-race-condition
Dec 1, 2026
+301
−42
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/frontend/src/state/valkey-features/cpu/cpuSlice.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { describe, it, expect } from "vitest" | ||
| import cpuReducer, { | ||
| cpuUsageRequested, | ||
| cpuUsageFulfilled, | ||
| cpuUsageError | ||
| } from "./cpuSlice" | ||
|
|
||
| describe("cpuSlice", () => { | ||
| const connectionId = "conn-1" | ||
|
|
||
| it("adds a generated requestId via prepare callback when caller does not provide one", () => { | ||
| const action = cpuUsageRequested({ connectionId }) | ||
| expect(action.payload.requestId).toBeDefined() | ||
| expect(typeof action.payload.requestId).toBe("string") | ||
| expect(action.payload.requestId.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("preserves an explicitly provided requestId via prepare callback", () => { | ||
| const explicitId = "custom-req-id-123" | ||
| const action = cpuUsageRequested({ connectionId, requestId: explicitId }) | ||
| expect(action.payload.requestId).toBe(explicitId) | ||
| }) | ||
|
|
||
| it("updates state with latest requestId when fulfilled", () => { | ||
| const reqAction = cpuUsageRequested({ connectionId, requestId: "req-latest" }) | ||
| let state = cpuReducer(undefined, reqAction) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| expect(state[connectionId].lastRequestId).toBe("req-latest") | ||
|
|
||
| const mockData = [{ timestamp: 1000, value: 42.5 }] | ||
| const fulfilledAction = cpuUsageFulfilled({ | ||
| connectionId, | ||
| parsedResponse: mockData, | ||
| requestId: "req-latest", | ||
| }) | ||
| state = cpuReducer(state, fulfilledAction) | ||
| expect(state[connectionId].data).toEqual(mockData) | ||
| expect(state[connectionId].loading).toBe(false) | ||
| }) | ||
|
|
||
| it("ignores fulfilled response with an old requestId, leaving data unchanged and loading true", () => { | ||
| // Initial request 1 | ||
| let state = cpuReducer(undefined, cpuUsageRequested({ connectionId, requestId: "req-1" })) | ||
| // Initial fulfillment for request 1 | ||
| const initialData = [{ timestamp: 1000, value: 20 }] | ||
| state = cpuReducer(state, cpuUsageFulfilled({ connectionId, parsedResponse: initialData, requestId: "req-1" })) | ||
| expect(state[connectionId].data).toEqual(initialData) | ||
|
|
||
| // Second request 2 sets loading to true | ||
| state = cpuReducer(state, cpuUsageRequested({ connectionId, requestId: "req-2" })) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| expect(state[connectionId].lastRequestId).toBe("req-2") | ||
|
|
||
| // Late arriving fulfillment for request 1 should be ignored | ||
| const staleData = [{ timestamp: 2000, value: 99 }] | ||
| state = cpuReducer(state, cpuUsageFulfilled({ connectionId, parsedResponse: staleData, requestId: "req-1" })) | ||
| expect(state[connectionId].data).toEqual(initialData) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| }) | ||
|
|
||
| it("ignores error response with an old requestId, leaving error unset and loading true", () => { | ||
| // Request 1 then Request 2 | ||
| let state = cpuReducer(undefined, cpuUsageRequested({ connectionId, requestId: "req-1" })) | ||
| state = cpuReducer(state, cpuUsageRequested({ connectionId, requestId: "req-2" })) | ||
| expect(state[connectionId].loading).toBe(true) | ||
|
|
||
| // Stale error for request 1 | ||
| const staleError = { message: "stale network error" } | ||
| state = cpuReducer(state, cpuUsageError({ connectionId, error: staleError, requestId: "req-1" })) | ||
| expect(state[connectionId].error).toBeUndefined() | ||
| expect(state[connectionId].loading).toBe(true) | ||
| }) | ||
|
|
||
| it("applies error response when requestId matches latest", () => { | ||
| let state = cpuReducer(undefined, cpuUsageRequested({ connectionId, requestId: "req-latest" })) | ||
| const validError = { message: "valid connection error" } | ||
| state = cpuReducer(state, cpuUsageError({ connectionId, error: validError, requestId: "req-latest" })) | ||
| expect(state[connectionId].error).toEqual(validError) | ||
| expect(state[connectionId].loading).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
apps/frontend/src/state/valkey-features/memory/memorySlice.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { describe, it, expect } from "vitest" | ||
| import memoryReducer, { | ||
| memoryUsageRequested, | ||
| memoryUsageFulfilled, | ||
| memoryUsageError | ||
| } from "./memorySlice" | ||
|
|
||
| describe("memorySlice", () => { | ||
| const connectionId = "conn-1" | ||
|
|
||
| it("adds a generated requestId via prepare callback when caller does not provide one", () => { | ||
| const action = memoryUsageRequested({ connectionId }) | ||
| expect(action.payload.requestId).toBeDefined() | ||
| expect(typeof action.payload.requestId).toBe("string") | ||
| expect(action.payload.requestId.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("preserves an explicitly provided requestId via prepare callback", () => { | ||
| const explicitId = "custom-mem-id-456" | ||
| const action = memoryUsageRequested({ connectionId, requestId: explicitId }) | ||
| expect(action.payload.requestId).toBe(explicitId) | ||
| }) | ||
|
|
||
| it("updates state with latest requestId when fulfilled", () => { | ||
| const reqAction = memoryUsageRequested({ connectionId, requestId: "req-latest" }) | ||
| let state = memoryReducer(undefined, reqAction) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| expect(state[connectionId].lastRequestId).toBe("req-latest") | ||
|
|
||
| const mockData = { | ||
| used_memory: { | ||
| description: "Used memory in bytes", | ||
| series: [{ timestamp: 1000, value: 1024000 }], | ||
| }, | ||
| } | ||
| const fulfilledAction = memoryUsageFulfilled({ | ||
| connectionId, | ||
| parsedResponse: mockData, | ||
| requestId: "req-latest", | ||
| }) | ||
| state = memoryReducer(state, fulfilledAction) | ||
| expect(state[connectionId].data).toEqual(mockData) | ||
| expect(state[connectionId].loading).toBe(false) | ||
| }) | ||
|
|
||
| it("ignores fulfilled response with an old requestId, leaving data unchanged and loading true", () => { | ||
| // Initial request 1 | ||
| let state = memoryReducer(undefined, memoryUsageRequested({ connectionId, requestId: "req-1" })) | ||
| // Initial fulfillment for request 1 | ||
| const initialData = { | ||
| used_memory: { | ||
| description: "Initial memory", | ||
| series: [{ timestamp: 1000, value: 500000 }], | ||
| }, | ||
| } | ||
| state = memoryReducer(state, memoryUsageFulfilled({ connectionId, parsedResponse: initialData, requestId: "req-1" })) | ||
| expect(state[connectionId].data).toEqual(initialData) | ||
|
|
||
| // Second request 2 sets loading to true | ||
| state = memoryReducer(state, memoryUsageRequested({ connectionId, requestId: "req-2" })) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| expect(state[connectionId].lastRequestId).toBe("req-2") | ||
|
|
||
| // Late arriving fulfillment for request 1 should be ignored | ||
| const staleData = { | ||
| used_memory: { | ||
| description: "Stale memory", | ||
| series: [{ timestamp: 2000, value: 9999999 }], | ||
| }, | ||
| } | ||
| state = memoryReducer(state, memoryUsageFulfilled({ connectionId, parsedResponse: staleData, requestId: "req-1" })) | ||
| expect(state[connectionId].data).toEqual(initialData) | ||
| expect(state[connectionId].loading).toBe(true) | ||
| }) | ||
|
|
||
| it("ignores error response with an old requestId, leaving error unset and loading true", () => { | ||
| // Request 1 then Request 2 | ||
| let state = memoryReducer(undefined, memoryUsageRequested({ connectionId, requestId: "req-1" })) | ||
| state = memoryReducer(state, memoryUsageRequested({ connectionId, requestId: "req-2" })) | ||
| expect(state[connectionId].loading).toBe(true) | ||
|
|
||
| // Stale error for request 1 | ||
| const staleError = { message: "stale memory network error" } | ||
| state = memoryReducer(state, memoryUsageError({ connectionId, error: staleError, requestId: "req-1" })) | ||
| expect(state[connectionId].error).toBeUndefined() | ||
| expect(state[connectionId].loading).toBe(true) | ||
| }) | ||
|
|
||
| it("applies error response when requestId matches latest", () => { | ||
| let state = memoryReducer(undefined, memoryUsageRequested({ connectionId, requestId: "req-latest" })) | ||
| const validError = { message: "valid memory fetch error" } | ||
| state = memoryReducer(state, memoryUsageError({ connectionId, error: validError, requestId: "req-latest" })) | ||
| expect(state[connectionId].error).toEqual(validError) | ||
| expect(state[connectionId].loading).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.