feat(zookeeper): add agent client browsing and node management

This commit is contained in:
miracle authored and GitHub committed 2026-06-25 00:40:48 +08:00
1 parent a0df43c391
commit 0effda91b3
65 files changed
+2037 -420

No files matched your search

@@ -18,6 +18,10 @@ describe("connectionAttemptTimeout", () => {
expect(connectionAttemptTimeoutMs({ db_type: "prestosql", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
});
it("uses the startup floor for ZooKeeper agent connections", () => {
expect(connectionAttemptTimeoutMs({ db_type: "zookeeper", connect_timeout_secs: 5, transport_layers: [] })).toBe(AGENT_DRIVER_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
});
it("uses a 30s Access agent startup floor", () => {
expect(connectionAttemptTimeoutMs({ db_type: "access", connect_timeout_secs: 5, transport_layers: [] })).toBe(ACCESS_AGENT_MIN_CONNECT_TIMEOUT_SECS * 1000 + CONNECTION_ATTEMPT_TIMEOUT_BUFFER_MS);
});
@@ -0,0 +1,8 @@
import { describe, expect, it } from "vitest";
import { parseConnectionUrl } from "../connectionUrl";
describe("ZooKeeper connection URLs", () => {
it("preserves the host:port chroot path as a ZooKeeper connect string", () => {
expect(parseConnectionUrl("zookeeper://zk-main:2181/app").connectionString).toBe("zk-main:2181/app");
});
});
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import { buildKvKeyTree, collectKvGroupIds, flattenVisibleKvKeyTree, preserveKvExpandedGroupIds } from "@/lib/kvKeyTree";
describe("kv key tree", () => {
it("keeps root keys as leaf nodes", () => {
const tree = buildKvKeyTree([{ key: "/plain", version: 2 }, { key: "/" }]);
expect(tree.map((node) => `${node.kind}:${node.label}`)).toEqual(["leaf:/", "leaf:plain"]);
expect(tree[1]).toMatchObject({ kind: "leaf", key: "/plain", version: 2 });
});
it("groups slash-delimited keys and sorts groups before leaves", () => {
const tree = buildKvKeyTree([
{ key: "/app/config/name", modRevision: 3 },
{ key: "/plain", modRevision: 4 },
{ key: "/app/config/env", modRevision: 5 },
{ key: "/service/api", modRevision: 6 },
]);
expect(tree.map((node) => node.label)).toEqual(["app", "service", "plain"]);
const app = tree[0];
expect(app.kind).toBe("group");
if (app.kind === "group") {
expect(app.children.map((node) => node.label)).toEqual(["config"]);
}
});
it("collects stable group ids", () => {
const tree = buildKvKeyTree([{ key: "/app/config/name" }, { key: "/service/api" }]);
expect([...collectKvGroupIds(tree)].sort()).toEqual(["group:app", "group:app\u0000config", "group:service"]);
});
it("flattens only expanded groups", () => {
const tree = buildKvKeyTree([{ key: "/app/config/name" }, { key: "/plain" }]);
const rows = flattenVisibleKvKeyTree(tree, new Set(["group:app"]));
expect(rows.map((row) => `${row.depth}:${row.node.label}`)).toEqual(["0:app", "1:config", "0:plain"]);
});
it("preserves only expanded groups still present after reload", () => {
const tree = buildKvKeyTree([{ key: "/app/config/name" }, { key: "/service/api" }]);
const next = preserveKvExpandedGroupIds(tree, new Set(["group:app", "group:missing"]));
expect([...next]).toEqual(["group:app"]);
expect([...preserveKvExpandedGroupIds(tree, new Set(), true)].sort()).toEqual(["group:app", "group:app\u0000config", "group:service"]);
});
});
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { refreshedKvSelectionKey } from "@/lib/kvRefreshSelection";
import type { KvKeySummary } from "@/lib/api";
describe("kv refresh selection", () => {
const keys: KvKeySummary[] = [{ key: "/app/config" }, { key: "/app/feature" }];
it("keeps the previously selected key when it still exists after refresh", () => {
expect(refreshedKvSelectionKey("/app/config", keys)).toBe("/app/config");
});
it("clears the selected key when it no longer exists after refresh", () => {
expect(refreshedKvSelectionKey("/app/missing", keys)).toBeNull();
});
});
@@ -0,0 +1,9 @@
import { describe, expect, it } from "vitest";
import { kvRootNodeLabel } from "@/lib/kvRootPresentation";
describe("kv root presentation", () => {
it("keeps etcd under Keys but shows ZooKeeper as root path", () => {
expect(kvRootNodeLabel("etcd")).toBe("Keys");
expect(kvRootNodeLabel("zookeeper")).toBe("/");
});
});
@@ -0,0 +1,88 @@
import { describe, expect, it } from "vitest";
import { formatZooKeeperMetadataRows, formatZooKeeperSummaryBadges, prettyPrintJsonText } from "@/lib/kvValueDisplay";
import type { KvKeyMetadata } from "@/lib/api";
describe("kv value display helpers", () => {
it("pretty prints valid JSON text", () => {
expect(prettyPrintJsonText('{"name":"张三","roles":["admin","reader"]}')).toEqual({
ok: true,
value: '{\n "name": "张三",\n "roles": [\n "admin",\n "reader"\n ]\n}',
});
});
it("does not treat plain text as JSON", () => {
expect(prettyPrintJsonText("hello")).toEqual({
ok: false,
error: "invalid_json",
});
});
it("formats ZooKeeper summary badges with ZK fallbacks", () => {
const metadata: KvKeyMetadata = {
mzxid: 29,
version: 0,
lease: null,
dataLength: 291,
};
expect(formatZooKeeperSummaryBadges(metadata)).toEqual([
{ label: "rev", value: "29" },
{ label: "ver", value: "0" },
{ label: "lease", value: "-" },
{ label: "size", value: "291 B" },
]);
});
it("formats ZooKeeper summary badges with localized labels", () => {
const metadata: KvKeyMetadata = {
mzxid: 373437,
version: 0,
lease: null,
dataLength: 291,
};
expect(
formatZooKeeperSummaryBadges(metadata, {
revision: "修订",
version: "版本",
lease: "租约",
size: "大小",
}),
).toEqual([
{ label: "修订", value: "373437" },
{ label: "版本", value: "0" },
{ label: "租约", value: "-" },
{ label: "大小", value: "291 B" },
]);
});
it("formats ZooKeeper stat rows using user-facing labels", () => {
const metadata: KvKeyMetadata = {
ephemeralOwner: 0,
ctime: 1780674584000,
mtime: 1780674585000,
mzxid: 27,
pzxid: 39825,
czxid: 27,
dataLength: 0,
numChildren: 5,
version: 0,
aversion: 0,
cversion: 5,
};
expect(formatZooKeeperMetadataRows(metadata).map((row) => [row.label, row.value])).toEqual([
["ephemeralOwner", "0x0"],
["mtime", expect.stringMatching(/^2026-06-05 \d{2}:49:45$/)],
["ctime", expect.stringMatching(/^2026-06-05 \d{2}:49:44$/)],
["mZxid", "0x1b"],
["pZxid", "0x9b91"],
["cZxid", "0x1b"],
["dataLength", "0"],
["numChildren", "5"],
["dataVersion", "0"],
["aclVersion", "0"],
["cVersion", "5"],
]);
});
});
@@ -332,6 +332,7 @@ describe("supportsExecutionTargetPicker", () => {
expect(supportsExecutionTargetPicker("milvus")).toBe(false);
expect(supportsExecutionTargetPicker("weaviate")).toBe(false);
expect(supportsExecutionTargetPicker("etcd")).toBe(false);
expect(supportsExecutionTargetPicker("zookeeper")).toBe(false);
expect(supportsExecutionTargetPicker("mq")).toBe(false);
expect(supportsExecutionTargetPicker("neo4j")).toBe(false);
expect(supportsExecutionTargetPicker(undefined)).toBe(false);
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { zookeeperDelete, zookeeperGet, zookeeperListPrefix, zookeeperPut, type KvPutOptions, type KvPutResponse } from "../api";
import type { DatabaseType } from "@/types/database";
describe("zookeeper frontend API contract", () => {
it("exposes the zookeeper database type and KV put options", () => {
const dbType: DatabaseType = "zookeeper";
const options: KvPutOptions = {
writeMode: "create",
createMode: "ephemeral_sequential",
};
const response: KvPutResponse = {
key: "/sessions/member-0000000001",
createdKey: "/sessions/member-0000000001",
};
expect(dbType).toBe("zookeeper");
expect(options.createMode).toBe("ephemeral_sequential");
expect(response.createdKey).toBe(response.key);
expect(typeof zookeeperListPrefix).toBe("function");
expect(typeof zookeeperGet).toBe("function");
expect(typeof zookeeperPut).toBe("function");
expect(typeof zookeeperDelete).toBe("function");
});
});
@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { firstZooKeeperEndpoint, normalizeZooKeeperConnectString } from "../zookeeperConnection";
describe("zookeeperConnection", () => {
it("normalizes comma, semicolon, and newline separated connect strings", () => {
expect(normalizeZooKeeperConnectString(" zk-1:2181, zk-2:2182\nzk-3 ; ")).toBe("zk-1:2181,zk-2:2182,zk-3");
});
it("extracts the first host and port from a connect string", () => {
expect(firstZooKeeperEndpoint("zk-1:2182,zk-2:2181")).toEqual({ host: "zk-1", port: 2182 });
});
it("strips a zookeeper URL scheme when normalizing connect strings", () => {
expect(normalizeZooKeeperConnectString("zookeeper://zk-main:2181")).toBe("zk-main:2181");
});
it("uses the ZooKeeper default port when the first endpoint omits a port", () => {
expect(firstZooKeeperEndpoint("zk-main")).toEqual({ host: "zk-main", port: 2181 });
});
it("parses bracketed IPv6 endpoints", () => {
expect(firstZooKeeperEndpoint("[::1]:2281,zk-2:2181")).toEqual({ host: "::1", port: 2281 });
});
});