Fix target poll healthcheck

The Target.lastFetch time compared when performing the healthcheck
resets any time a poll is attempted no matter the outcome. This changes
the behavior so the time is reset only on a successful poll

Change-type: patch
This commit is contained in:
Felipe Lalanne 2025-02-26 16:25:03 -03:00
parent c88cf6a259
commit f8bdb14335
No known key found for this signature in database
GPG Key ID: 03E696BFD472B26A
3 changed files with 5 additions and 5 deletions

View File

@ -63,7 +63,7 @@ export async function healthcheck() {
}
// Check last time target state has been polled
const timeSinceLastFetch = process.hrtime(TargetState.lastFetch);
const timeSinceLastFetch = process.hrtime(TargetState.lastSuccessfulFetch);
const timeSinceLastFetchMs =
timeSinceLastFetch[0] * 1000 + timeSinceLastFetch[1] / 1e6;

View File

@ -87,7 +87,8 @@ const emitTargetState = (
* We set a value rather then being undeclared because having it undefined
* 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
@ -154,8 +155,6 @@ export const update = async (
// Emit the target state and update the cache
cache.emitted = emitTargetState(cache, force, isFromApi);
}).finally(() => {
lastFetch = process.hrtime();
});
};
@ -188,6 +187,7 @@ const poll = async (
await update();
// Reset fetchErrors because we successfuly updated
fetchErrors = 0;
lastSuccessfulFetch = process.hrtime();
} catch {
// Exponential back off if request fails
pollInterval = Math.min(appUpdatePollInterval, 15000 * 2 ** fetchErrors);

View File

@ -335,7 +335,7 @@ describe('ApiBinder', () => {
before(async () => {
await initModels(components, '/config-apibinder.json');
previousLastFetch = TargetState.lastFetch;
previousLastFetch = TargetState.lastSuccessfulFetch;
});
after(async () => {