Skip to content

Commit

Permalink
feat(backups): improve health check error messages (#8016)
Browse files Browse the repository at this point in the history
- waitObjectState already throw if timeout is reached
- gives more details to help user understand the issue
  - timeout reached while waiting for  ${refOrUuid} to be running
  - timeout reached while waiting for  ${refOrUuid} to report the
    driver version through the xen tools.
  • Loading branch information
fbeauchamp authored Sep 27, 2024
1 parent 0e9242b commit 558ea84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 7 additions & 17 deletions @xen-orchestra/backups/HealthCheckVmBackup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,25 @@ export class HealthCheckVmBackup {
}

// wait for the 'Running' event to be really stored in local xapi object cache

restoredVm = await xapi.waitObjectState(restoredVm.$ref, vm => vm.power_state === 'Running', {
timeout: remainingTimeout,
timeoutMessage: refOrUuid =>
`local xapi did not get Running state for VM ${refOrUuid} after ${timeout / 1000} second`,
})

const running = new Date()
remainingTimeout -= running - started

if (remainingTimeout < 0) {
throw new Error(`local xapi did not get Running state for VM ${restoredId} after ${timeout / 1000} second`)
}
// wait for the guest tool version to be defined
await xapi.waitObjectState(restoredVm.guest_metrics, gm => gm?.PV_drivers_version?.major !== undefined, {
timeout: remainingTimeout,
timeoutMessage: refOrUuid =>
`timeout reached while waiting for ${refOrUuid} to report the driver version through the Xen tools. Please check or update the Xen tools.`,
})

const guestToolsReady = new Date()
remainingTimeout -= guestToolsReady - running
if (remainingTimeout < 0) {
throw new Error(`local xapi did not get he guest tools check ${restoredId} after ${timeout / 1000} second`)
}

if (waitForScript) {
const startedRestoredVm = await xapi.waitObjectState(
Expand All @@ -79,19 +78,10 @@ export class HealthCheckVmBackup {
vm.xenstore_data['vm-data/xo-backup-health-check'] === 'failure'),
{
timeout: remainingTimeout,
timeoutMessage: refOrUuid =>
`timeout reached while waiting for ${refOrUuid} to report the startup script execution.`,
}
)
const scriptOk = new Date()
remainingTimeout -= scriptOk - guestToolsReady
if (remainingTimeout < 0) {
throw new Error(
`Backup health check script did not update vm-data/xo-backup-health-check of ${restoredId} after ${
timeout / 1000
} second, got ${
startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check']
} instead of 'success' or 'failure'`
)
}

if (startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check'] !== 'success') {
const message = startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check-error']
Expand Down
11 changes: 9 additions & 2 deletions @xen-orchestra/xapi/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ export class Xapi extends Base {

// wait for an object to be in a specified state

waitObjectState(refOrUuid, predicate, { timeout } = {}) {
waitObjectState(
refOrUuid,
predicate,
{
timeout,
timeoutMessage = refOrUuid => `waitObjectState: timeout reached before ${refOrUuid} in expected state`,
} = {}
) {
return new Promise((resolve, reject) => {
const object = this.getObject(refOrUuid, undefined)
if (object !== undefined && predicate(object)) {
Expand All @@ -248,7 +255,7 @@ export class Xapi extends Base {
})

if (timeout !== undefined) {
const error = new Error(`waitObjectState: timeout reached before ${refOrUuid} in expected state`)
const error = new Error(timeoutMessage(refOrUuid))
timeoutHandle = setTimeout(() => {
stop()
reject(error)
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `rest get --output $file` now displays progress information during download
- `rest post` and `rest put` now accept `--input $file` to upload a file and display progress information
- [Backup] Detect invalid VDI exports that are incorrectly reported as successful by XAPI
- [Backup/HealthCheck] Improve error messages on health check timeout (PR [#8016](https://github.com/vatesfr/xen-orchestra/pull/8016))

### Bug fixes

Expand All @@ -40,8 +41,10 @@
<!--packages-start-->

- @xen-orchestra/backups minor
- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
- @xen-orchestra/xapi minor
- xen-api minor
- xo-cli minor
- xo-server minor
Expand Down

0 comments on commit 558ea84

Please sign in to comment.