From 273ae4aecdb666a50bc9b76b220cd7e3fe3b2609 Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Thu, 27 Feb 2025 16:21:22 +0000 Subject: [PATCH] Split healthCheck out into separate module GitOrigin-RevId: 847d00b696fe6d82f4bd5fea8f9130437c68e7b2 --- services/history-v1/backup-verifier-app.mjs | 2 +- .../history-v1/backupVerifier/healthCheck.mjs | 24 +++++++++++++++++++ .../history-v1/storage/lib/backupVerifier.mjs | 20 ---------------- 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 services/history-v1/backupVerifier/healthCheck.mjs diff --git a/services/history-v1/backup-verifier-app.mjs b/services/history-v1/backup-verifier-app.mjs index de427a3765..e2af11a4c9 100644 --- a/services/history-v1/backup-verifier-app.mjs +++ b/services/history-v1/backup-verifier-app.mjs @@ -7,9 +7,9 @@ import { promisify } from 'node:util' import express from 'express' import logger from '@overleaf/logger' import Metrics from '@overleaf/metrics' +import { healthCheck } from './backupVerifier/healthCheck.mjs' import { BackupCorruptedError, - healthCheck, verifyBlob, } from './storage/lib/backupVerifier.mjs' import { mongodb } from './storage/index.js' diff --git a/services/history-v1/backupVerifier/healthCheck.mjs b/services/history-v1/backupVerifier/healthCheck.mjs new file mode 100644 index 0000000000..48cd187c9a --- /dev/null +++ b/services/history-v1/backupVerifier/healthCheck.mjs @@ -0,0 +1,24 @@ +import config from 'config' +import { verifyProjectWithErrorContext } from '../storage/lib/backupVerifier.mjs' + +/** @type {Array} */ +const HEALTH_CHECK_PROJECTS = JSON.parse(config.get('healthCheckProjects')) + +export async function healthCheck() { + if (!Array.isArray(HEALTH_CHECK_PROJECTS)) { + throw new Error('expected healthCheckProjects to be an array') + } + if (HEALTH_CHECK_PROJECTS.length !== 2) { + throw new Error('expected 2 healthCheckProjects') + } + if (!HEALTH_CHECK_PROJECTS.some(id => id.length === 24)) { + throw new Error('expected mongo id in healthCheckProjects') + } + if (!HEALTH_CHECK_PROJECTS.some(id => id.length < 24)) { + throw new Error('expected postgres id in healthCheckProjects') + } + + for (const historyId of HEALTH_CHECK_PROJECTS) { + await verifyProjectWithErrorContext(historyId) + } +} diff --git a/services/history-v1/storage/lib/backupVerifier.mjs b/services/history-v1/storage/lib/backupVerifier.mjs index 83952768c2..bbe8941dd7 100644 --- a/services/history-v1/storage/lib/backupVerifier.mjs +++ b/services/history-v1/storage/lib/backupVerifier.mjs @@ -220,26 +220,6 @@ export async function verifyProject(historyId, endTimestamp) { export class BackupCorruptedError extends OError {} export class BackupRPOViolationError extends OError {} - -const HEALTH_CHECK_PROJECTS = JSON.parse(config.get('healthCheckProjects')) -export async function healthCheck() { - if (!Array.isArray(HEALTH_CHECK_PROJECTS)) { - throw new Error('expected healthCheckProjects to be an array') - } - if (HEALTH_CHECK_PROJECTS.length !== 2) { - throw new Error('expected 2 healthCheckProjects') - } - if (!HEALTH_CHECK_PROJECTS.some(id => id.length === 24)) { - throw new Error('expected mongo id in healthCheckProjects') - } - if (!HEALTH_CHECK_PROJECTS.some(id => id.length < 24)) { - throw new Error('expected postgres id in healthCheckProjects') - } - - for (const historyId of HEALTH_CHECK_PROJECTS) { - await verifyProjectWithErrorContext(historyId) - } -} export class BackupCorruptedMissingBlobError extends BackupCorruptedError {} export class BackupCorruptedInvalidBlobError extends BackupCorruptedError {} export class BackupRPOViolationChunkNotBackedUpError extends OError {}