querysub 0.720.0 → 0.722.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/flushlogs.js +7 -0
- package/debugging.md +43 -0
- package/package.json +9 -3
- package/src/-f-node-discovery/NodeDiscovery.ts +1 -1
- package/src/0-path-value-core/AuthorityLookup.ts +0 -1
- package/src/0-path-value-core/PathRouter.ts +0 -1
- package/src/0-path-value-core/PathWatcher.ts +0 -3
- package/src/0-path-value-core/ValidStateComputer.ts +0 -3
- package/src/2-proxy/PathValueProxyWatcher.ts +0 -3
- package/src/2-proxy/TransactionDelayer.ts +0 -1
- package/src/4-deploy/edgeNodes.ts +0 -1
- package/src/4-querysub/querysubPrediction.ts +0 -1
- package/src/config.ts +0 -1
- package/src/diagnostics/StatsHeader.tsx +2 -1
- package/src/diagnostics/StatsOverrides.ts +35 -0
- package/src/diagnostics/logs/IndexedLogs/BufferUnitIndex.ts +0 -1
- package/src/diagnostics/logs/IndexedLogs/MCPIndexedLogs.ts +36 -23
- package/src/diagnostics/logs/IndexedLogs/flushLogsEntry.ts +42 -0
- package/src/diagnostics/logs/IndexedLogs/moveIndexLogsToPublic.ts +6 -0
- package/src/diagnostics/logs/errorNotifications2/ErrorNotificationPage.tsx +7 -19
- package/src/diagnostics/logs/errorNotifications2/ErrorWarning.tsx +4 -5
- package/src/diagnostics/logs/errorNotifications2/errorNotifications.ts +27 -47
- package/src/diagnostics/logs/errorNotifications2/suppressionPatternMatcher.ts +168 -0
- package/src/diagnostics/network/logFilesMain.ts +57 -0
- package/src/diagnostics/network/logSearchMain.ts +86 -0
- package/src/diagnostics/network/networkNodesMain.ts +225 -0
- package/src/diagnostics/network/networkProbe.ts +31 -0
- package/src/diagnostics/network/networkServicesMain.ts +170 -0
- package/src/diagnostics/network/portMappingsMain.ts +28 -0
- package/src/diagnostics/statsDefinitions.tsx +0 -1
- package/src/library-components/LazyComponent.tsx +0 -1
- package/src/library-components/URLParam.ts +0 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { SERVICE_FOLDER } from "../../deployManager/machineSchema";
|
|
3
|
+
|
|
4
|
+
export type ProbeResult<T> = { value?: T; error?: string; ms: number };
|
|
5
|
+
|
|
6
|
+
export async function probeAsync<T>(config: { timeoutMs: number; call: () => Promise<T> }): Promise<ProbeResult<T>> {
|
|
7
|
+
let start = Date.now();
|
|
8
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
9
|
+
let timeout = new Promise<never>((resolve, reject) => {
|
|
10
|
+
timer = setTimeout(() => reject(new Error(`Timed out after ${config.timeoutMs}ms`)), config.timeoutMs);
|
|
11
|
+
});
|
|
12
|
+
try {
|
|
13
|
+
let value = await Promise.race([config.call(), timeout]);
|
|
14
|
+
return { value, ms: Date.now() - start };
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return { error: String((e as Error).stack || e), ms: Date.now() - start };
|
|
17
|
+
} finally {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function serviceFolderFromEntryPoint(entryPoint: string): string {
|
|
23
|
+
let normalized = entryPoint.replaceAll("\\", "/");
|
|
24
|
+
let index = normalized.indexOf(SERVICE_FOLDER);
|
|
25
|
+
if (index < 0) return "";
|
|
26
|
+
return normalized.slice(index + SERVICE_FOLDER.length).split("/")[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function shortEntryPoint(entryPoint: string): string {
|
|
30
|
+
return path.basename(entryPoint || "");
|
|
31
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
module.hotreload = false;
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
let argv = process.argv;
|
|
5
|
+
let cwdIdx = argv.indexOf("--cwd");
|
|
6
|
+
if (cwdIdx >= 0 && argv[cwdIdx + 1]) {
|
|
7
|
+
process.chdir(argv[cwdIdx + 1]);
|
|
8
|
+
argv.splice(cwdIdx, 2);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
import "../../inject";
|
|
13
|
+
|
|
14
|
+
import { formatTime } from "socket-function/src/formatting/format";
|
|
15
|
+
import { blue, green, magenta, red, yellow } from "socket-function/src/formatting/logColors";
|
|
16
|
+
import { sort } from "socket-function/src/misc";
|
|
17
|
+
import { getArchives2Buffered } from "../../-a-archives/archives2";
|
|
18
|
+
import { NodeDiscoveryController } from "../../-f-node-discovery/NodeDiscovery";
|
|
19
|
+
import { MACHINE_RESYNC_INTERVAL, MachineInfo, getAllServiceConfigs, getLiveServiceParameters, getMachineIdList, machineConfigs, machineInfos, machineNames } from "../../deployManager/machineSchema";
|
|
20
|
+
import { disablePathAuditer } from "../pathAuditerCallback";
|
|
21
|
+
import { probeAsync, ProbeResult } from "./networkProbe";
|
|
22
|
+
|
|
23
|
+
const NODE_CALL_TIMEOUT_MS = 10_000;
|
|
24
|
+
const DEAD_MACHINE_THRESHOLD = MACHINE_RESYNC_INTERVAL * 4;
|
|
25
|
+
|
|
26
|
+
async function timedAsync<T>(label: string, call: () => Promise<T>): Promise<T> {
|
|
27
|
+
let start = Date.now();
|
|
28
|
+
console.log(magenta(`Reading ${label}...`));
|
|
29
|
+
let value = await call();
|
|
30
|
+
console.log(magenta(`Read ${label} in ${formatTime(Date.now() - start)}`));
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
disablePathAuditer();
|
|
36
|
+
|
|
37
|
+
let [nodeIds, configs, infos, names, disabledMachines] = await Promise.all([
|
|
38
|
+
timedAsync("node list", () => getArchives2Buffered("nodes/").find("", { fallbacks: true })),
|
|
39
|
+
timedAsync("service configs", () => getAllServiceConfigs()),
|
|
40
|
+
timedAsync("machine heartbeats", () => machineInfos.entries()),
|
|
41
|
+
timedAsync("machine names", () => machineNames.values()),
|
|
42
|
+
timedAsync("machine configs", async () => new Set((await machineConfigs.values()).filter(x => x.disabled).map(x => x.machineId))),
|
|
43
|
+
]);
|
|
44
|
+
let listedNodes = new Set(nodeIds);
|
|
45
|
+
let infoByMachine = new Map<string, MachineInfo>(infos);
|
|
46
|
+
let nameByMachine = new Map(names.map(x => [x.machineId, x.name]));
|
|
47
|
+
let machineLabel = (machineId: string) => {
|
|
48
|
+
let name = nameByMachine.get(machineId);
|
|
49
|
+
return name && `${name} (${machineId})` || machineId;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let referencedNodeIds = new Set<string>();
|
|
53
|
+
for (let info of infoByMachine.values()) {
|
|
54
|
+
for (let service of Object.values(info.services || {})) {
|
|
55
|
+
for (let nodeId of Object.values(service.nodeIds || {})) {
|
|
56
|
+
if (nodeId) referencedNodeIds.add(nodeId.trim());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let aliveByNode = new Map<string, ProbeResult<boolean>>();
|
|
61
|
+
await Promise.all([...referencedNodeIds].map(async nodeId => {
|
|
62
|
+
aliveByNode.set(nodeId, await probeAsync({ timeoutMs: NODE_CALL_TIMEOUT_MS, call: () => NodeDiscoveryController.nodes[nodeId].isAlive() }));
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
console.log();
|
|
66
|
+
console.log(magenta(`===== Machines =====`));
|
|
67
|
+
let machineIds = [...new Set([...infoByMachine.keys(), ...configs.flatMap(x => getMachineIdList(getLiveServiceParameters(x)))])];
|
|
68
|
+
sort(machineIds, x => machineLabel(x));
|
|
69
|
+
for (let machineId of machineIds) {
|
|
70
|
+
let info = infoByMachine.get(machineId);
|
|
71
|
+
if (!info) {
|
|
72
|
+
console.log(red(`✗ ${machineLabel(machineId)} has no machine heartbeat, but services are configured to run on it`));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let age = Date.now() - info.heartbeat;
|
|
76
|
+
let disabled = disabledMachines.has(machineId) && yellow(" (disabled)") || "";
|
|
77
|
+
if (age > DEAD_MACHINE_THRESHOLD) {
|
|
78
|
+
console.log(red(`✗ ${machineLabel(machineId)} heartbeat ${formatTime(age)} ago (dead threshold ${formatTime(DEAD_MACHINE_THRESHOLD)})${disabled}`));
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
console.log(green(`✓ ${machineLabel(machineId)} heartbeat ${formatTime(age)} ago${disabled}`), `git ${info.gitRef.slice(0, 8)}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log();
|
|
85
|
+
console.log(magenta(`===== Services =====`));
|
|
86
|
+
let problems = 0;
|
|
87
|
+
sort(configs, x => x.parameters.key);
|
|
88
|
+
for (let config of configs) {
|
|
89
|
+
let parameters = getLiveServiceParameters(config);
|
|
90
|
+
if (!parameters.deploy) {
|
|
91
|
+
console.log(blue(`- ${parameters.key} (not deployed)`));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let instanceCounts = new Map<string, number>();
|
|
95
|
+
for (let machineId of getMachineIdList(parameters)) {
|
|
96
|
+
instanceCounts.set(machineId, (instanceCounts.get(machineId) || 0) + 1);
|
|
97
|
+
}
|
|
98
|
+
let lines: string[] = [];
|
|
99
|
+
let healthy = 0;
|
|
100
|
+
let expected = 0;
|
|
101
|
+
for (let [machineId, count] of instanceCounts) {
|
|
102
|
+
if (disabledMachines.has(machineId)) {
|
|
103
|
+
lines.push(yellow(` ${machineLabel(machineId)}: machine disabled, ${count} instance(s) not expected`));
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
let info = infoByMachine.get(machineId);
|
|
107
|
+
let service = info?.services?.[config.serviceId];
|
|
108
|
+
for (let index = 0; index < count; index++) {
|
|
109
|
+
expected++;
|
|
110
|
+
let where = ` ${machineLabel(machineId)} #${index}`;
|
|
111
|
+
if (!info) {
|
|
112
|
+
lines.push(red(`${where}: no machine heartbeat`));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (Date.now() - info.heartbeat > DEAD_MACHINE_THRESHOLD) {
|
|
116
|
+
lines.push(red(`${where}: machine heartbeat is ${formatTime(Date.now() - info.heartbeat)} old`));
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (!service) {
|
|
120
|
+
lines.push(red(`${where}: the machine has not reported this service at all`));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
let launch = `launched ${service.totalTimesLaunched}x, last ${service.lastLaunchedTime && `${formatTime(Date.now() - service.lastLaunchedTime)} ago` || "never"}`;
|
|
124
|
+
let error = service.errorFromLastRun && red(` last run error: ${service.errorFromLastRun.split("\n").find(x => x.trim()) || ""}`) || "";
|
|
125
|
+
let nodeId = (service.nodeIds?.[index] || "").trim();
|
|
126
|
+
if (!nodeId) {
|
|
127
|
+
lines.push(yellow(`${where}: no node id recorded yet (${launch})${error}`));
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
let alive = aliveByNode.get(nodeId);
|
|
131
|
+
let inList = listedNodes.has(nodeId) && "in node list" || red("NOT in node list");
|
|
132
|
+
if (!alive?.value) {
|
|
133
|
+
lines.push(red(`${where}: ${nodeId} unreachable after ${formatTime(alive?.ms || 0)}, ${inList} (${launch})${error} ${alive?.error?.split("\n")[0] || ""}`));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!listedNodes.has(nodeId)) {
|
|
137
|
+
lines.push(yellow(`${where}: ${nodeId} answers calls but is ${inList} (${launch})${error}`));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
healthy++;
|
|
141
|
+
lines.push(green(`${where}: ${nodeId} ok, ping ${formatTime(alive.ms)}`) + ` (${launch})${error}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
problems += expected - healthy;
|
|
145
|
+
let color = healthy === expected && green || healthy && yellow || red;
|
|
146
|
+
console.log(color(`${healthy === expected && "✓" || "✗"} ${parameters.key} ${healthy}/${expected} healthy`), config.info?.title || "");
|
|
147
|
+
for (let line of lines) {
|
|
148
|
+
console.log(line);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let unattributed = nodeIds.filter(nodeId => !referencedNodeIds.has(nodeId));
|
|
153
|
+
console.log();
|
|
154
|
+
console.log(magenta(`===== Summary =====`));
|
|
155
|
+
console.log(`${configs.length} service configs, ${problems && red(`${problems} unhealthy instance(s)`) || green("every deployed instance healthy")}`);
|
|
156
|
+
if (unattributed.length) {
|
|
157
|
+
console.log(blue(`${unattributed.length}/${nodeIds.length} listed nodes are not recorded as any service's instance (dev machines, scripts, or instances whose node id file has not been read yet):`));
|
|
158
|
+
for (let nodeId of unattributed) {
|
|
159
|
+
console.log(blue(` ${nodeId}`));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
main().then(
|
|
165
|
+
() => process.exit(),
|
|
166
|
+
e => {
|
|
167
|
+
console.error((e as Error).stack || e);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
},
|
|
170
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { listPortMappings, resolveGateway } from "socket-function/src/forwardPort";
|
|
2
|
+
import { sort } from "socket-function/src/misc";
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
let ports = new Set(process.argv.slice(2).map(Number).filter(x => x));
|
|
6
|
+
let gateway = await resolveGateway();
|
|
7
|
+
console.log(`Gateway ${gateway.gatewayIP}, we are ${gateway.internalIP}`);
|
|
8
|
+
let mappings = await listPortMappings();
|
|
9
|
+
sort(mappings, x => x.externalPort);
|
|
10
|
+
console.log(`${mappings.length} UPnP mappings${ports.size && `, showing ports ${[...ports].join(", ")}` || ""}`);
|
|
11
|
+
for (let mapping of mappings) {
|
|
12
|
+
if (ports.size && !ports.has(mapping.externalPort)) continue;
|
|
13
|
+
let lease = mapping.leaseDuration && `lease ${mapping.leaseDuration}s left` || "permanent";
|
|
14
|
+
console.log(`${mapping.protocol} ${mapping.externalPort} -> ${mapping.internalClient}:${mapping.internalPort} ${mapping.enabled && "enabled" || "DISABLED"} ${lease} ${JSON.stringify(mapping.description)}`);
|
|
15
|
+
}
|
|
16
|
+
for (let port of ports) {
|
|
17
|
+
if (mappings.some(x => x.externalPort === port)) continue;
|
|
18
|
+
console.log(`${port}: NO MAPPING`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().then(
|
|
23
|
+
() => process.exit(),
|
|
24
|
+
e => {
|
|
25
|
+
console.error((e as Error).stack || e);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
},
|
|
28
|
+
);
|