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 {
private checkMethods = new Map<
string,
(record: RecordRule, address: string) => Promise<ConnectResult>
>();
>();
private availableRecordRules: RecordRule[];
private async filterRecordRules() {
this.availableRecordRules = [];
await Promise.all(this.config.cdnRecords.map(async (rule) => {
if (rule.protocol === 'tcp' && rule.source) {
this.message(`Checking source ${rule.source}:${rule.port}.`);
try {
const ms = await this.checkTcpProcess(rule.source, rule.port)
this.availableRecordRules.push(rule);
this.message(`Source ${rule.source}:${rule.port} is good: ${ms} ms.`)
} catch (e) {
this.message(`Skipping rule ${rule.match} fo source ${rule.source}:${rule.port}r unhealthy: ${e.toString()}`)
}
} 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}`);
await Promise.all(
this.config.cdnRecords.map(async (rule) => {
if (rule.protocol === 'tcp' && rule.source) {
this.message(`Checking source ${rule.source}:${rule.port}.`);
try {
const ms = await this.checkTcpProcess(rule.source, rule.port);
this.availableRecordRules.push(rule);
this.message(
`Source ${rule.source}:${rule.port} is good: ${ms} ms.`,
);
} catch (e) {
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')
) {
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 {
this.message(`Source domain ${domain} is good.`);
availableTestDomains.push(domain);
this.message(
`Skipping rule ${rule.match} for no available sources.`,
);
}
}
if (availableTestDomains.length) {
rule.testDomains = availableTestDomains;
this.availableRecordRules.push(rule);
} 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) {
try {
await axios.get(url, {
headers: {Host: hostHeader},
headers: { Host: hostHeader },
timeout: this.config.timeout,
validateStatus: (status) => status < 500,
});
......@@ -311,6 +331,13 @@ class Checker {
const matchCDNRecord = this.availableRecordRules.find((r) =>
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 isCDN = this.isCDNRecord(record);
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