Update Harbor client and gateway integration workflows
This commit is contained in:
@@ -44,6 +44,7 @@ interface RequestOptions {
|
||||
ipv4?: boolean;
|
||||
follow?: boolean;
|
||||
resolve?: string | null;
|
||||
timeoutMs?: number;
|
||||
}
|
||||
|
||||
interface RequestResult {
|
||||
@@ -179,7 +180,9 @@ async function request(probe: BaseProbe, path: PathKind, proxyPort: number, exec
|
||||
ipv4 = false,
|
||||
follow = true,
|
||||
resolve = null,
|
||||
timeoutMs = 6_000,
|
||||
}: RequestOptions = {}): Promise<RequestResult> {
|
||||
const boundedTimeoutMs = Math.min(30_000, Math.max(1_000, Math.round(timeoutMs)));
|
||||
const args = [
|
||||
'--silent',
|
||||
'--show-error',
|
||||
@@ -189,9 +192,9 @@ async function request(probe: BaseProbe, path: PathKind, proxyPort: number, exec
|
||||
'--proto-redir',
|
||||
'=https',
|
||||
'--connect-timeout',
|
||||
'3',
|
||||
String(Math.min(3_000, boundedTimeoutMs) / 1_000),
|
||||
'--max-time',
|
||||
'6',
|
||||
String(boundedTimeoutMs / 1_000),
|
||||
'--user-agent',
|
||||
'Harbor-Diagnostics/1',
|
||||
'--output',
|
||||
@@ -379,6 +382,8 @@ async function siteProbe(
|
||||
proxyPort: number,
|
||||
execute: CurlExecutor,
|
||||
sampleCount = 1,
|
||||
timeoutMs = 6_000,
|
||||
retryFailure = true,
|
||||
): Promise<SiteProbeResult> {
|
||||
if (probe.validationError) return {
|
||||
id: probe.id,
|
||||
@@ -391,12 +396,12 @@ async function siteProbe(
|
||||
stage: 'validation',
|
||||
error: probe.validationError,
|
||||
};
|
||||
const options = { follow: probe.follow !== false, resolve: probe.resolve };
|
||||
const options = { follow: probe.follow !== false, resolve: probe.resolve, timeoutMs };
|
||||
const samples = [];
|
||||
for (let attempt = 0; attempt < sampleCount; attempt += 1) {
|
||||
samples.push(await request(probe, path, proxyPort, execute, options));
|
||||
}
|
||||
if (sampleCount === 1 && samples[0] && !samples[0].ok) {
|
||||
if (retryFailure && sampleCount === 1 && samples[0] && !samples[0].ok) {
|
||||
samples.push(await request(probe, path, proxyPort, execute, options));
|
||||
}
|
||||
const status = mostCommon(samples.map(siteStatus)) || 'unavailable';
|
||||
@@ -469,15 +474,18 @@ async function probeTarget(
|
||||
path: PathKind,
|
||||
proxyPort: number,
|
||||
execute: CurlExecutor,
|
||||
timeoutMs = 6_000,
|
||||
sampleCount = TARGET_SAMPLE_COUNT,
|
||||
retryFailure = true,
|
||||
): Promise<ConnectivityPathResult> {
|
||||
const network = target.kind === 'network'
|
||||
? await networkProbe(path, proxyPort, execute, TARGET_SAMPLE_COUNT)
|
||||
? await networkProbe(path, proxyPort, execute, sampleCount)
|
||||
: null;
|
||||
const ip = target.kind === 'ip'
|
||||
? await ipProbe(target.probe, path, proxyPort, execute, TARGET_SAMPLE_COUNT)
|
||||
? await ipProbe(target.probe, path, proxyPort, execute, sampleCount)
|
||||
: null;
|
||||
const site = target.kind === 'site'
|
||||
? await siteProbe(target.probe, path, proxyPort, execute, TARGET_SAMPLE_COUNT)
|
||||
? await siteProbe(target.probe, path, proxyPort, execute, sampleCount, timeoutMs, retryFailure)
|
||||
: null;
|
||||
const ipv4Sources = ip?.family === 4 ? [ip] : [];
|
||||
const ipv6Source = ip?.family === 6 ? ip : null;
|
||||
@@ -537,7 +545,25 @@ export function createConnectivityDiagnosticsService({
|
||||
assessment: assessConnectivity(direct, vpn),
|
||||
};
|
||||
}
|
||||
async function runVpn({ services = [], target: targetId = null, timeoutMs = 6_000 }: {
|
||||
services?: unknown;
|
||||
target?: unknown;
|
||||
timeoutMs?: number;
|
||||
}) {
|
||||
const requestedServices = typeof targetId === 'string' && targetId.startsWith('site:custom-')
|
||||
? (Array.isArray(services) ? services : []).filter((service) => `site:${String(record(service).id || '')}` === targetId)
|
||||
: [];
|
||||
const customProbes = await prepareCustomProbes(requestedServices, lookup);
|
||||
const siteProbes = [...SITE_PROBES, ...customProbes];
|
||||
const target = resolveTarget(targetId, siteProbes);
|
||||
if (!target || target.kind !== 'site') throw new Error('Failover check ожидает site target');
|
||||
return {
|
||||
checkedAt: now(),
|
||||
vpn: await probeTarget(target, 'vpn', proxyPort, execute, timeoutMs, TARGET_SAMPLE_COUNT, false),
|
||||
};
|
||||
}
|
||||
return {
|
||||
run: runOnce,
|
||||
runVpn,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user