Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: always log and display full remote errors #6216

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion @xen-orchestra/fs/src/abstract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncMapSettled from '@xen-orchestra/async-map/legacy'
import getStream from 'get-stream'
import { coalesceCalls } from '@vates/coalesce-calls'
import { createLogger } from '@xen-orchestra/log'
import { fromCallback, fromEvent, ignoreErrors, timeout } from 'promise-toolbox'
import { limitConcurrency } from 'limit-concurrency-decorator'
import { parse } from 'xo-remote-parser'
Expand All @@ -11,6 +12,8 @@ import { synchronized } from 'decorator-synchronized'
import { basename, dirname, normalize as normalizePath } from './_path'
import { createChecksumStream, validChecksumOfReadStream } from './checksum'

const { warn } = createLogger('@xen-orchestra:fs')

const checksumFile = file => file + '.checksum'
const computeRate = (hrtime, size) => {
const seconds = hrtime[0] + hrtime[1] / 1e9
Expand Down Expand Up @@ -357,11 +360,12 @@ export default class RemoteHandlerAbstract {
readRate: computeRate(readDuration, SIZE),
}
} catch (error) {
warn(`error while testing the remote at step ${step}`, { error })
return {
success: false,
step,
file: testFileName,
error: error.message || String(error),
error,
}
} finally {
ignoreErrors.call(this._unlink(testFileName))
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- [load-balancer] Fix density mode failing to shutdown hosts (PR [#6253](https://github.com/vatesfr/xen-orchestra/pull/6253))
- [Health] Make "Too many snapshots" table sortable by number of snapshots (PR [#6255](https://github.com/vatesfr/xen-orchestra/pull/6255))
- [Remote] Show complete errors instead of only a potentially missing message (PR [#6216](https://github.com/vatesfr/xen-orchestra/pull/6216))

### Packages to release

Expand All @@ -31,6 +32,7 @@

<!--packages-start-->

- @xen-orchestra/fs patch
- @xen-orchestra/xapi minor
- xo-server minor
- xo-web patch
Expand Down
9 changes: 8 additions & 1 deletion packages/xo-server/src/models/remote.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Collection from '../collection/redis.mjs'
import Model from '../model.mjs'
import { forEach } from '../utils.mjs'
import { forEach, serializeError } from '../utils.mjs'

import { parseProp } from './utils.mjs'

Expand All @@ -18,6 +18,7 @@ export class Remotes extends Collection {
forEach(remotes, remote => {
remote.benchmarks = parseProp('remote', remote, 'benchmarks')
remote.enabled = remote.enabled === 'true'
remote.error = parseProp('remote', remote, 'error', remote.error)
})
return remotes
}
Expand All @@ -29,6 +30,12 @@ export class Remotes extends Collection {
if (benchmarks !== undefined) {
remote.benchmarks = JSON.stringify(benchmarks)
}

const { error } = remote
if (error !== undefined) {
remote.error = JSON.stringify(typeof error === 'object' ? serializeError(error) : error)
}

return remote
})
)
Expand Down
6 changes: 3 additions & 3 deletions packages/xo-server/src/xo-mixins/remotes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default class {

try {
await handler.sync()
ignoreErrors.call(this._updateRemote(id, { error: '' }))
ignoreErrors.call(this._updateRemote(id, { error: null }))
} catch (error) {
ignoreErrors.call(this._updateRemote(id, { error: error.message }))
ignoreErrors.call(this._updateRemote(id, { error }))
throw error
}

Expand All @@ -103,7 +103,7 @@ export default class {
writeRate,
}
await this._updateRemote(remoteId, {
error: '',
error: null,
benchmarks:
remote.benchmarks !== undefined
? [...remote.benchmarks.slice(-49), benchmark] // store 50 benchmarks
Expand Down
8 changes: 6 additions & 2 deletions packages/xo-web/src/xo-app/settings/remotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import {

import Remote from './remote'

const formatError = error => (typeof error === 'string' ? error : JSON.stringify(error, null, 2).replace(/\\n/g, '\n'))

const _changeUrlElement = (value, { remote, element }) =>
editRemote(remote, {
url: format({ ...remote, [element]: value === null ? undefined : value }),
})
const _showError = remote => alert(_('remoteConnectionFailed'), remote.error)
const _showError = remote => alert(_('remoteConnectionFailed'), <pre>{formatError(remote.error)}</pre>)
const _editRemoteName = (name, { remote }) => editRemote(remote, { name })
const _editRemoteOptions = (options, { remote }) => editRemote(remote, { options: options !== '' ? options : null })

Expand Down Expand Up @@ -331,7 +333,9 @@ const INDIVIDUAL_ACTIONS = [
<p>
<dl className='dl-horizontal'>
<dt>{_('remoteTestError')}</dt>
<dd>{answer.error}</dd>
<dd>
<pre>{formatError(answer.error)}</pre>
</dd>
<dt>{_('remoteTestStep')}</dt>
<dd>{answer.step}</dd>
</dl>
Expand Down