Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APM-12044 update http agent properties to improve prefix generation #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class Config {
host: "localhost",
port: 8011
},
checkForUpdatesAtBoot: true,
checkForUpdatesAtBoot: false,
pidFile: "bgpalerter.pid",
fadeOffSeconds: 360,
checkFadeOffGroupsSeconds: 30
Expand Down
3 changes: 1 addition & 2 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if (global.DRY_RUN) {
}];
}

config.volume = config.volume || global.EXTERNAL_VOLUME_DIRECTORY || "";
config.volume = config.volume || global.EXTERNAL_VOLUME_DIRECTORY || "/app";

if (config.volume && config.volume.length) {
if (config.volume.slice(-1) !== "/") {
Expand All @@ -81,7 +81,6 @@ if (config.volume && config.volume.length) {
} else {
console.log("Impossible to load config.yml");
throw new Error("Impossible to load config.yml");

}

const errorTransport = new FileLogger({
Expand Down
13 changes: 11 additions & 2 deletions src/generatePrefixesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const clientId = "ntt-bgpalerter";
const rpki = new RpkiValidator({clientId});
import axiosEnrich from "./utils/axiosEnrich";

import https from 'https';

const httpsAgentOptions = {
keepAlive: (process.env.KEEP_ALIVE || 'true') === 'true',
maxSockets: parseInt(process.env.MAX_SOCKETS || '10', 10)
}
console.log(`Using HTTPS Agent Options: ${JSON.stringify(httpsAgentOptions)}`);
axios.defaults.httpsAgent = new https.Agent(httpsAgentOptions);
jeff-leong marked this conversation as resolved.
Show resolved Hide resolved

module.exports = function generatePrefixes(inputParameters) {
let {
Expand Down Expand Up @@ -153,6 +161,7 @@ module.exports = function generatePrefixes(inputParameters) {
.catch((error) => {
logger(error);
logger(`RIPEstat prefix-overview query failed: cannot retrieve information for ${prefix}`);
throw error;
});
};

Expand Down Expand Up @@ -275,7 +284,7 @@ module.exports = function generatePrefixes(inputParameters) {
.then(list => list.filter(i => !exclude.includes(i.prefix)))
.then(list => {

return batchPromises(40, list, i => {
return batchPromises(10, list, i => {
return generateRule(i.prefix, asn, false, null, false);
})
.then(() => list.map(i => i.prefix));
Expand Down Expand Up @@ -308,7 +317,7 @@ module.exports = function generatePrefixes(inputParameters) {

const getBaseRules = (prefixes) => {
if (prefixes) {
return batchPromises(40, prefixes, p => {
return batchPromises(10, prefixes, p => {
return generateRule(p, null, false, null, false);
})
.then(() => prefixes);
Expand Down
22 changes: 14 additions & 8 deletions src/utils/axiosEnrich.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import md5 from "md5";

const attempts = {};
const numAttempts = 2;
const numAttempts = 5;

const retry = function (axios, error) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const key = md5(JSON.stringify(error.config));
attempts[key] = attempts[key] || 0;
attempts[key]++;
if (attempts[key] <= numAttempts) {
resolve(axios.request(error.config));
} else {
try {
const key = md5(JSON.stringify(error.config));

attempts[key] = attempts[key] || 0;
attempts[key]++;
if (attempts[key] <= numAttempts) {
resolve(axios.request(error.config));
} else {
reject(error);
}
} catch (error) {
reject(error);
}
}, 2000);
}, 10000);
});
}


export default function(axios, httpsAgent, userAgent) {

// Set agent/proxy
Expand Down