Commit 9109bce0 authored by nanahira's avatar nanahira

fix

parent befacbb3
Pipeline #10228 failed with stages
in 56 seconds
...@@ -85,49 +85,69 @@ class Checker { ...@@ -85,49 +85,69 @@ class Checker {
private checkMethods = new Map< private checkMethods = new Map<
string, string,
(record: RecordRule, address: string) => Promise<ConnectResult> (record: RecordRule, address: string) => Promise<ConnectResult>
>(); >();
private availableRecordRules: RecordRule[]; private availableRecordRules: RecordRule[];
private async filterRecordRules() { private async filterRecordRules() {
this.availableRecordRules = []; this.availableRecordRules = [];
await Promise.all(this.config.cdnRecords.map(async (rule) => { await Promise.all(
if (rule.protocol === 'tcp' && rule.source) { this.config.cdnRecords.map(async (rule) => {
this.message(`Checking source ${rule.source}:${rule.port}.`); if (rule.protocol === 'tcp' && rule.source) {
try { this.message(`Checking source ${rule.source}:${rule.port}.`);
const ms = await this.checkTcpProcess(rule.source, rule.port) try {
this.availableRecordRules.push(rule); const ms = await this.checkTcpProcess(rule.source, rule.port);
this.message(`Source ${rule.source}:${rule.port} is good: ${ms} ms.`) this.availableRecordRules.push(rule);
} catch (e) { this.message(
this.message(`Skipping rule ${rule.match} fo source ${rule.source}:${rule.port}r unhealthy: ${e.toString()}`) `Source ${rule.source}:${rule.port} is good: ${ms} ms.`,
} );
} else if (rule.source && (rule.protocol === 'http' || rule.protocol === 'https')) { } catch (e) {
const availableTestDomains: string[] = []; this.message(
for (const domain of rule.testDomains) { `Skipping rule ${rule.match} fo source ${rule.source}:${
this.message(`Checking source domain ${domain}:${rule.port}.`); rule.port
const errMessage = await this.tryConnectHttp(rule.protocol, domain, rule.port, domain); } unhealthy: ${e.toString()}`,
if (errMessage) { );
this.message(`Skipping domain ${domain} of rule ${rule.match} for bad source: ${errMessage}`); }
} else if (
rule.source &&
(rule.protocol === 'http' || rule.protocol === 'https')
) {
const availableTestDomains: string[] = [];
for (const domain of rule.testDomains) {
this.message(`Checking source domain ${domain}:${rule.port}.`);
const errMessage = await this.tryConnectHttp(
rule.protocol,
domain,
rule.port,
domain,
);
if (errMessage) {
this.message(
`Skipping domain ${domain} of rule ${rule.match} for bad source: ${errMessage}`,
);
} else {
this.message(`Source domain ${domain} is good.`);
availableTestDomains.push(domain);
}
}
if (availableTestDomains.length) {
rule.testDomains = availableTestDomains;
this.availableRecordRules.push(rule);
} else { } else {
this.message(`Source domain ${domain} is good.`); this.message(
availableTestDomains.push(domain); `Skipping rule ${rule.match} for no available sources.`,
);
} }
}
if (availableTestDomains.length) {
rule.testDomains = availableTestDomains;
this.availableRecordRules.push(rule);
} else { } else {
this.message(`Skipping rule ${rule.match} for no available sources.`); this.availableRecordRules.push(rule);
} }
} else { }),
this.availableRecordRules.push(rule); );
}
}))
} }
private async connectHttpProcess(url: string, hostHeader: string) { private async connectHttpProcess(url: string, hostHeader: string) {
try { try {
await axios.get(url, { await axios.get(url, {
headers: {Host: hostHeader}, headers: { Host: hostHeader },
timeout: this.config.timeout, timeout: this.config.timeout,
validateStatus: (status) => status < 500, validateStatus: (status) => status < 500,
}); });
...@@ -311,6 +331,13 @@ class Checker { ...@@ -311,6 +331,13 @@ class Checker {
const matchCDNRecord = this.availableRecordRules.find((r) => const matchCDNRecord = this.availableRecordRules.find((r) =>
record.RR.match(r.match), record.RR.match(r.match),
); );
if (!matchCDNRecord) {
// source down
this.message(
`Will skip record ${record.RR}.${this.config.domain} => ${record.Value} because source is down.`,
);
continue;
}
const { port, protocol } = matchCDNRecord; const { port, protocol } = matchCDNRecord;
const isCDN = this.isCDNRecord(record); const isCDN = this.isCDNRecord(record);
const recordInfo: DomainRecordInfo = { const recordInfo: DomainRecordInfo = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment