Allow scaling in getEndDateForRPO

RPO can now be scaled to allow a little extra grace in certain
circumstances.

Co-authored-by: Brian Gough <brian.gough@overleaf.com>
GitOrigin-RevId: fa60a9ffe966977e396b5645919ddd1451fb1b7a
This commit is contained in:
Andrew Rumble
2025-03-27 10:22:33 +00:00
committed by Copybot
parent 47f2bed47c
commit ded29d187b
3 changed files with 8 additions and 9 deletions

View File

@@ -21,15 +21,13 @@ export async function measurePendingChangesBeforeTime(beforeTime) {
/**
*
* @param {number} graceSeconds - Number of seconds projects are allowed before they must be backed up.
* @param {Date} graceTime
* @return {Promise<void>}
*/
export async function measureNeverBackedUpProjects(graceSeconds) {
const now = new Date()
const startOfGracePeriod = new Date(now - graceSeconds * 1000)
export async function measureNeverBackedUpProjects(graceTime) {
const neverBackedUpCount = await projectsCollection.countDocuments({
'overleaf.backup.lastBackedUpVersion': null,
_id: { $lt: objectIdFromDate(startOfGracePeriod) },
_id: { $lt: objectIdFromDate(graceTime) },
})
Metrics.gauge('backup_verification_never_backed_up', neverBackedUpCount)
}

View File

@@ -27,6 +27,6 @@ export async function healthCheck() {
await verifyProjectWithErrorContext(historyId)
}
await measurePendingChangesBeforeTime(getEndDateForRPO())
await measureNeverBackedUpProjects(RPO)
await measurePendingChangesBeforeTime(getEndDateForRPO(2))
await measureNeverBackedUpProjects(getEndDateForRPO(2))
}

View File

@@ -12,10 +12,11 @@ export function objectIdFromDate(time) {
}
/**
* @param {number} [factor] - Multiply RPO by this factor, default is 1
* @return {Date}
*/
export function getEndDateForRPO() {
return new Date(Date.now() - RPO)
export function getEndDateForRPO(factor = 1) {
return new Date(Date.now() - RPO * factor)
}
/**