-
Notifications
You must be signed in to change notification settings - Fork 18
Refactor connectionId, nodeId, clusterId #375
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2561ba5
Rename connectionId to nodeId if not containing db.
ArgusLi 514581b
Split into explicit cluster/standalone branches and replies.
ArgusLi 711fa95
Fix changes in the frontend.
ArgusLi ede6eda
Add configSlice test
ArgusLi 00d3843
Re-key all node level metrics states to nodeId
ArgusLi 0c63e4e
Fix hotkey standalone no result bug.
ArgusLi 927a19c
fix lint import issue
ArgusLi 6a87f05
Fix lint
ArgusLi da46eb6
Fix double hot key response.
ArgusLi 568d3d1
Add ADR.
ArgusLi 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
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
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
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
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
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
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
110 changes: 110 additions & 0 deletions
110
apps/frontend/src/state/valkey-features/commandlogs/commandLogsSlice.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,110 @@ | ||
| import { describe, it, expect } from "vitest" | ||
| import { COMMANDLOG_TYPE } from "@common/src/constants.ts" | ||
| import commandLogsReducer, { | ||
| commandLogsRequested, | ||
| commandLogsFulfilled, | ||
| commandLogsError | ||
| } from "./commandLogsSlice" | ||
|
|
||
| describe("commandLogsSlice", () => { | ||
| const initialState = {} | ||
|
|
||
| describe("commandLogsRequested", () => { | ||
| it("keys the standalone pending entry by the db-less nodeId", () => { | ||
| const state = commandLogsReducer( | ||
| initialState, | ||
| commandLogsRequested({ connectionId: "host-6379-db0" }), | ||
| ) | ||
|
|
||
| expect(state["host-6379"]).toBeDefined() | ||
| expect(state["host-6379-db0"]).toBeUndefined() | ||
| expect(state["host-6379"].loading).toBe(true) | ||
| }) | ||
|
|
||
| it("collapses two connections to the same node on different dbs into one entry", () => { | ||
| const afterDb0 = commandLogsReducer( | ||
| initialState, | ||
| commandLogsRequested({ connectionId: "host-6379-db0" }), | ||
| ) | ||
| const afterDb1 = commandLogsReducer( | ||
| afterDb0, | ||
| commandLogsRequested({ connectionId: "host-6379-db1" }), | ||
| ) | ||
|
|
||
| expect(Object.keys(afterDb1)).toEqual(["host-6379"]) | ||
| }) | ||
|
|
||
| it("keys the cluster pending entry by clusterId", () => { | ||
| const state = commandLogsReducer( | ||
| initialState, | ||
| commandLogsRequested({ connectionId: "node-1-db0", clusterId: "cluster-1" }), | ||
| ) | ||
|
|
||
| expect(state["cluster-1"]).toBeDefined() | ||
| expect(state["node-1-db0"]).toBeUndefined() | ||
| }) | ||
| }) | ||
|
|
||
| describe("commandLogsFulfilled", () => { | ||
| it("keys a standalone reply by nodeId", () => { | ||
| const rows = [{ ts: 1, metric: "slow", values: [] }] | ||
| const state = commandLogsReducer( | ||
| initialState, | ||
| commandLogsFulfilled({ | ||
| nodeId: "host-6379", | ||
| commandLogType: COMMANDLOG_TYPE.SLOW, | ||
| parsedResponse: { rows, count: 10 }, | ||
| }), | ||
| ) | ||
|
|
||
| expect(state["host-6379"]).toBeDefined() | ||
| expect(state["host-6379"].logs[COMMANDLOG_TYPE.SLOW]).toEqual(rows) | ||
| expect(state["host-6379"].count).toBe(10) | ||
| expect(state["host-6379"].loading).toBe(false) | ||
| }) | ||
|
|
||
| it("keys a cluster reply by clusterId and keeps nodeErrors db-less", () => { | ||
| const state = commandLogsReducer( | ||
| initialState, | ||
| commandLogsFulfilled({ | ||
| clusterId: "cluster-1", | ||
| commandLogType: COMMANDLOG_TYPE.SLOW, | ||
| parsedResponse: { rows: [], count: 0 }, | ||
| nodeErrors: [{ nodeId: "node-1", error: "down" }], | ||
| }), | ||
| ) | ||
|
|
||
| expect(state["cluster-1"]).toBeDefined() | ||
| expect(state["cluster-1"].nodeErrors).toEqual([{ nodeId: "node-1", error: "down" }]) | ||
| }) | ||
| }) | ||
|
|
||
| describe("commandLogsError", () => { | ||
| it("keys a standalone error by nodeId", () => { | ||
| const seeded = commandLogsReducer( | ||
| initialState, | ||
| commandLogsRequested({ connectionId: "host-6379-db0" }), | ||
| ) | ||
| const state = commandLogsReducer( | ||
| seeded, | ||
| commandLogsError({ nodeId: "host-6379", error: { message: "boom" } }), | ||
| ) | ||
|
|
||
| expect(state["host-6379"].error).toEqual({ message: "boom" }) | ||
| expect(state["host-6379"].loading).toBe(false) | ||
| }) | ||
|
|
||
| it("keys a cluster error by clusterId", () => { | ||
| const seeded = commandLogsReducer( | ||
| initialState, | ||
| commandLogsRequested({ connectionId: "node-1-db0", clusterId: "cluster-1" }), | ||
| ) | ||
| const state = commandLogsReducer( | ||
| seeded, | ||
| commandLogsError({ clusterId: "cluster-1", error: { message: "boom" } }), | ||
| ) | ||
|
|
||
| expect(state["cluster-1"].error).toEqual({ message: "boom" }) | ||
| }) | ||
| }) | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to just store nodeId in frontend state instead of stripping the db suffixed ID every time we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually are using targetId as the key in the frontend state for node level metrics state. This can be seen in the following functions in the code i.e.
selectCommandLogs()(),selectHotKeys()()...The reason for keeping the connectionId key state is that we still have things that need to be scoped by db such as the connection details, keys etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more so referring to storing nodeId in connection state, so components can read it directly instead of calling toNodeId every time. But this isn't a blocker if you don't think its worth the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding nodeId in connection state means that if the connectionId gets changed, we have to ensure nodeId stays consistent, which is an additional thing to manage. toNodeId() is also cheap operation so there's no real performance benefit from caching it directly in connection state.
So in my mind it's not worth gaining that really small performance gain in exchange for an additional state we have to manage.