Skip to content
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

cluster-ui: skip undefined regions on database pages #106778

Merged
merged 1 commit into from Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 9 additions & 15 deletions pkg/ui/workspaces/cluster-ui/src/databases/util.spec.ts
Expand Up @@ -25,7 +25,7 @@ describe("Getting nodes by region string", () => {
"3": "region3",
};
const result = getNodesByRegionString(nodes, regions, false);
assert.deepStrictEqual(result, `region1(n1), region2(n2), region3(n3)`);
expect(result).toEqual(`region1(n1), region2(n2), region3(n3)`);
});

it("when all nodes same region", () => {
Expand All @@ -36,7 +36,7 @@ describe("Getting nodes by region string", () => {
"3": "region1",
};
const result = getNodesByRegionString(nodes, regions, false);
assert.deepStrictEqual(result, `region1(n1,n2,n3)`);
expect(result).toEqual(`region1(n1,n2,n3)`);
});

it("when some nodes different regions", () => {
Expand All @@ -47,14 +47,14 @@ describe("Getting nodes by region string", () => {
"3": "region2",
};
const result = getNodesByRegionString(nodes, regions, false);
assert.deepStrictEqual(result, `region1(n1,n2), region2(n3)`);
expect(result).toEqual(`region1(n1,n2), region2(n3)`);
});

it("when region map is empty", () => {
const nodes = [1, 2, 3];
const regions = {};
const result = getNodesByRegionString(nodes, regions, false);
assert.deepStrictEqual(result, `undefined(n1,n2,n3)`);
expect(result).toEqual("");
});

it("when nodes are empty", () => {
Expand All @@ -65,7 +65,7 @@ describe("Getting nodes by region string", () => {
"3": "region2",
};
const result = getNodesByRegionString(nodes, regions, false);
assert.deepStrictEqual(result, "");
expect(result).toEqual("");
});
});
});
Expand All @@ -74,32 +74,26 @@ describe("Normalize privileges", () => {
it("sorts correctly when input is disordered", () => {
const privs = ["CREATE", "DELETE", "UPDATE", "ALL", "GRANT"];
const result = normalizePrivileges(privs);
assert.deepStrictEqual(result, [
"ALL",
"CREATE",
"GRANT",
"UPDATE",
"DELETE",
]);
expect(result).toEqual(["ALL", "CREATE", "GRANT", "UPDATE", "DELETE"]);
});

it("removes duplicates", () => {
const privs = ["CREATE", "CREATE", "UPDATE", "ALL", "GRANT"];
const result = normalizePrivileges(privs);
assert.deepStrictEqual(result, ["ALL", "CREATE", "GRANT", "UPDATE"]);
expect(result).toEqual(["ALL", "CREATE", "GRANT", "UPDATE"]);
});
});

describe("Normalize roles", () => {
it("sorts correctly when input is disordered", () => {
const roles = ["public", "root", "admin"];
const result = normalizeRoles(roles);
assert.deepStrictEqual(result, ["root", "admin", "public"]);
expect(result).toEqual(["root", "admin", "public"]);
});

it("removes duplicates", () => {
const roles = ["public", "admin", "admin"];
const result = normalizeRoles(roles);
assert.deepStrictEqual(result, ["admin", "public"]);
expect(result).toEqual(["admin", "public"]);
});
});
4 changes: 4 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/databases/util.ts
Expand Up @@ -99,6 +99,10 @@ export function createNodesByRegionMap(
): Record<string, number[]> {
const nodesByRegionMap: Record<string, number[]> = {};
nodes.forEach((node: number) => {
// If the node's region doesn't exist skip it.
if (nodeRegions[node.toString()] == null) {
return;
}
const region: string = nodeRegions[node.toString()];
if (nodesByRegionMap[region] == null) {
nodesByRegionMap[region] = [];
Expand Down
Expand Up @@ -374,7 +374,7 @@ describe("Database Details Page", function () {
replicationSizeInBytes: 100,
rangeCount: 400,
nodes: [1, 2, 3],
nodesByRegionString: "undefined(n1,n2,n3)",
nodesByRegionString: "",
},
});

Expand All @@ -397,7 +397,7 @@ describe("Database Details Page", function () {
replicationSizeInBytes: 10,
rangeCount: 50,
nodes: [1, 2, 3, 4, 5],
nodesByRegionString: "undefined(n1,n2,n3,n4,n5)",
nodesByRegionString: "",
},
});
});
Expand Down
Expand Up @@ -287,7 +287,7 @@ describe("Database Table Page", function () {
totalBytes: 45,
sizeInBytes: 23,
rangeCount: 56,
nodesByRegionString: "undefined(n1,n2,n3,n4,n5)",
nodesByRegionString: "",
});
});

Expand Down