mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-12 07:23:58 +00:00
Merge pull request #2404 from balena-os/polling-improvements
Polling improvements
This commit is contained in:
commit
3cca2b7ecd
27
package-lock.json
generated
27
package-lock.json
generated
@ -64,7 +64,7 @@
|
|||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
||||||
"fp-ts": "^2.16.5",
|
"fp-ts": "^2.16.5",
|
||||||
"got": "14.4.1",
|
"got": "^14.4.6",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"io-ts": "2.2.20",
|
"io-ts": "2.2.20",
|
||||||
"io-ts-reporters": "^2.0.1",
|
"io-ts-reporters": "^2.0.1",
|
||||||
@ -1225,13 +1225,13 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@sindresorhus/is": {
|
"node_modules/@sindresorhus/is": {
|
||||||
"version": "6.3.1",
|
"version": "7.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-6.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-7.0.1.tgz",
|
||||||
"integrity": "sha512-FX4MfcifwJyFOI2lPoX7PQxCqx8BG1HCho7WdiXwpEQx1Ycij0JxkfYtGK7yqNScrZGSlt6RE6sw8QYoH7eKnQ==",
|
"integrity": "sha512-QWLl2P+rsCJeofkDNIT3WFmb6NrRud1SUYW8dIhXK/46XFV8Q/g7Bsvib0Askb0reRLe+WYPeeE+l5cH7SlkuQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sindresorhus/is?sponsor=1"
|
"url": "https://github.com/sindresorhus/is?sponsor=1"
|
||||||
@ -7054,24 +7054,23 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/got": {
|
"node_modules/got": {
|
||||||
"version": "14.4.1",
|
"version": "14.4.6",
|
||||||
"resolved": "https://registry.npmjs.org/got/-/got-14.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/got/-/got-14.4.6.tgz",
|
||||||
"integrity": "sha512-IvDJbJBUeexX74xNQuMIVgCRRuNOm5wuK+OC3Dc2pnSoh1AOmgc7JVj7WC+cJ4u0aPcO9KZ2frTXcqK4W/5qTQ==",
|
"integrity": "sha512-rnhwfM/PhMNJ1i17k3DuDqgj0cKx3IHxBKVv/WX1uDKqrhi2Gv3l7rhPThR/Cc6uU++dD97W9c8Y0qyw9x0jag==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sindresorhus/is": "^6.3.1",
|
"@sindresorhus/is": "^7.0.1",
|
||||||
"@szmarczak/http-timer": "^5.0.1",
|
"@szmarczak/http-timer": "^5.0.1",
|
||||||
"cacheable-lookup": "^7.0.0",
|
"cacheable-lookup": "^7.0.0",
|
||||||
"cacheable-request": "^12.0.1",
|
"cacheable-request": "^12.0.1",
|
||||||
"decompress-response": "^6.0.0",
|
"decompress-response": "^6.0.0",
|
||||||
"form-data-encoder": "^4.0.2",
|
"form-data-encoder": "^4.0.2",
|
||||||
"get-stream": "^8.0.1",
|
|
||||||
"http2-wrapper": "^2.2.1",
|
"http2-wrapper": "^2.2.1",
|
||||||
"lowercase-keys": "^3.0.0",
|
"lowercase-keys": "^3.0.0",
|
||||||
"p-cancelable": "^4.0.1",
|
"p-cancelable": "^4.0.1",
|
||||||
"responselike": "^3.0.0",
|
"responselike": "^3.0.0",
|
||||||
"type-fest": "^4.19.0"
|
"type-fest": "^4.26.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20"
|
"node": ">=20"
|
||||||
@ -7110,9 +7109,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/got/node_modules/type-fest": {
|
"node_modules/got/node_modules/type-fest": {
|
||||||
"version": "4.20.0",
|
"version": "4.35.0",
|
||||||
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.35.0.tgz",
|
||||||
"integrity": "sha512-MBh+PHUHHisjXf4tlx0CFWoMdjx8zCMLJHOjnV1prABYZFHqtFOyauCIK2/7w4oIfwkF8iNhLtnJEfVY2vn3iw==",
|
"integrity": "sha512-2/AwEFQDFEy30iOLjrvHDIH7e4HEWH+f1Yl1bI5XMqzuoCUqwYCdxachgsgv0og/JdVZUhbfjcJAoHj5L1753A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "(MIT OR CC0-1.0)",
|
"license": "(MIT OR CC0-1.0)",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
||||||
"fp-ts": "^2.16.5",
|
"fp-ts": "^2.16.5",
|
||||||
"got": "14.4.1",
|
"got": "^14.4.6",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"io-ts": "2.2.20",
|
"io-ts": "2.2.20",
|
||||||
"io-ts-reporters": "^2.0.1",
|
"io-ts-reporters": "^2.0.1",
|
||||||
|
@ -63,7 +63,7 @@ export async function healthcheck() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check last time target state has been polled
|
// Check last time target state has been polled
|
||||||
const timeSinceLastFetch = process.hrtime(TargetState.lastFetch);
|
const timeSinceLastFetch = process.hrtime(TargetState.lastSuccessfulFetch);
|
||||||
const timeSinceLastFetchMs =
|
const timeSinceLastFetchMs =
|
||||||
timeSinceLastFetch[0] * 1000 + timeSinceLastFetch[1] / 1e6;
|
timeSinceLastFetch[0] * 1000 + timeSinceLastFetch[1] / 1e6;
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ const emitTargetState = (
|
|||||||
* We set a value rather then being undeclared because having it undefined
|
* We set a value rather then being undeclared because having it undefined
|
||||||
* adds more overhead to dealing with this value without any benefits.
|
* adds more overhead to dealing with this value without any benefits.
|
||||||
*/
|
*/
|
||||||
export let lastFetch: ReturnType<typeof process.hrtime> = process.hrtime();
|
export let lastSuccessfulFetch: ReturnType<typeof process.hrtime> =
|
||||||
|
process.hrtime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to update the target state
|
* Attempts to update the target state
|
||||||
@ -154,8 +155,6 @@ export const update = async (
|
|||||||
|
|
||||||
// Emit the target state and update the cache
|
// Emit the target state and update the cache
|
||||||
cache.emitted = emitTargetState(cache, force, isFromApi);
|
cache.emitted = emitTargetState(cache, force, isFromApi);
|
||||||
}).finally(() => {
|
|
||||||
lastFetch = process.hrtime();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,7 +187,11 @@ const poll = async (
|
|||||||
await update();
|
await update();
|
||||||
// Reset fetchErrors because we successfuly updated
|
// Reset fetchErrors because we successfuly updated
|
||||||
fetchErrors = 0;
|
fetchErrors = 0;
|
||||||
} catch {
|
lastSuccessfulFetch = process.hrtime();
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ApiResponseError)) {
|
||||||
|
log.error('Target state poll failed', e);
|
||||||
|
}
|
||||||
// Exponential back off if request fails
|
// Exponential back off if request fails
|
||||||
pollInterval = Math.min(appUpdatePollInterval, 15000 * 2 ** fetchErrors);
|
pollInterval = Math.min(appUpdatePollInterval, 15000 * 2 ** fetchErrors);
|
||||||
++fetchErrors;
|
++fetchErrors;
|
||||||
|
@ -335,7 +335,7 @@ describe('ApiBinder', () => {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await initModels(components, '/config-apibinder.json');
|
await initModels(components, '/config-apibinder.json');
|
||||||
previousLastFetch = TargetState.lastFetch;
|
previousLastFetch = TargetState.lastSuccessfulFetch;
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user