Handle connectivity diagnostics failures
Build and Deploy Gateway / build-and-push (push) Successful in 13s
Build and Deploy Gateway / deploy (push) Successful in 13s

This commit is contained in:
2026-08-07 20:58:18 +03:00
parent 12375006d3
commit 0c376c72aa
6 changed files with 30 additions and 11 deletions
+9 -3
View File
@@ -1,7 +1,7 @@
import http from 'node:http';
import { HarborError } from '../shared/errors.js';
function request(socketPath, pathname, method = 'GET', body = null) {
function request(socketPath, pathname, method = 'GET', body = null, timeoutMs = 6000) {
return new Promise((resolve, reject) => {
const encoded = body == null ? null : JSON.stringify(body);
const req = http.request({
@@ -29,7 +29,7 @@ function request(socketPath, pathname, method = 'GET', body = null) {
});
});
req.on('error', reject);
req.setTimeout(6000, () => req.destroy(new Error('Dataplane не ответил за 6 секунд')));
req.setTimeout(timeoutMs, () => req.destroy(new Error(`Dataplane не ответил за ${Math.ceil(timeoutMs / 1000)} секунд`)));
req.end(encoded);
});
}
@@ -56,7 +56,13 @@ export function createDataplaneClient(socketPath, send = request) {
observeTraffic: () => send(socketPath, '/device-traffic', 'GET'),
observeDevicePolicy: () => send(socketPath, '/device-policy', 'GET'),
applyDevicePolicies: (devices) => send(socketPath, '/device-policy', 'PUT', { devices }),
runConnectivityDiagnostics: () => send(socketPath, '/diagnostics/connectivity', 'POST'),
runConnectivityDiagnostics: async () => {
try {
return await send(socketPath, '/diagnostics/connectivity', 'POST', null, 15_000);
} catch (cause) {
throw new HarborError('DIAGNOSTICS_FAILED', { cause });
}
},
apply: () => update('/apply', 'POST'),
restart: () => update('/restart', 'POST'),
stop: () => update('/stop', 'POST'),