Commit 9109bce0 authored by nanahira's avatar nanahira

fix

parent befacbb3
Pipeline #10228 failed with stages
in 56 seconds
...@@ -90,23 +90,40 @@ class Checker { ...@@ -90,23 +90,40 @@ class Checker {
private async filterRecordRules() { private async filterRecordRules() {
this.availableRecordRules = []; this.availableRecordRules = [];
await Promise.all(this.config.cdnRecords.map(async (rule) => { await Promise.all(
this.config.cdnRecords.map(async (rule) => {
if (rule.protocol === 'tcp' && rule.source) { if (rule.protocol === 'tcp' && rule.source) {
this.message(`Checking source ${rule.source}:${rule.port}.`); this.message(`Checking source ${rule.source}:${rule.port}.`);
try { try {
const ms = await this.checkTcpProcess(rule.source, rule.port) const ms = await this.checkTcpProcess(rule.source, rule.port);
this.availableRecordRules.push(rule); this.availableRecordRules.push(rule);
this.message(`Source ${rule.source}:${rule.port} is good: ${ms} ms.`) this.message(
`Source ${rule.source}:${rule.port} is good: ${ms} ms.`,
);
} catch (e) { } catch (e) {
this.message(`Skipping rule ${rule.match} fo source ${rule.source}:${rule.port}r unhealthy: ${e.toString()}`) this.message(
`Skipping rule ${rule.match} fo source ${rule.source}:${
rule.port
} unhealthy: ${e.toString()}`,
);
} }
} else if (rule.source && (rule.protocol === 'http' || rule.protocol === 'https')) { } else if (
rule.source &&
(rule.protocol === 'http' || rule.protocol === 'https')
) {
const availableTestDomains: string[] = []; const availableTestDomains: string[] = [];
for (const domain of rule.testDomains) { for (const domain of rule.testDomains) {
this.message(`Checking source domain ${domain}:${rule.port}.`); this.message(`Checking source domain ${domain}:${rule.port}.`);
const errMessage = await this.tryConnectHttp(rule.protocol, domain, rule.port, domain); const errMessage = await this.tryConnectHttp(
rule.protocol,
domain,
rule.port,
domain,
);
if (errMessage) { if (errMessage) {
this.message(`Skipping domain ${domain} of rule ${rule.match} for bad source: ${errMessage}`); this.message(
`Skipping domain ${domain} of rule ${rule.match} for bad source: ${errMessage}`,
);
} else { } else {
this.message(`Source domain ${domain} is good.`); this.message(`Source domain ${domain} is good.`);
availableTestDomains.push(domain); availableTestDomains.push(domain);
...@@ -116,18 +133,21 @@ class Checker { ...@@ -116,18 +133,21 @@ class Checker {
rule.testDomains = availableTestDomains; rule.testDomains = availableTestDomains;
this.availableRecordRules.push(rule); this.availableRecordRules.push(rule);
} else { } else {
this.message(`Skipping rule ${rule.match} for no available sources.`); this.message(
`Skipping rule ${rule.match} for no available sources.`,
);
} }
} else { } else {
this.availableRecordRules.push(rule); 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