feat(xo-server-backup-reports): support task warnings (#3596)

This commit is contained in:
badrAZ
2018-10-25 12:22:35 +02:00
committed by Julien Fontanet
parent 30372e511e
commit 52aa5ff780
2 changed files with 22 additions and 4 deletions

View File

@@ -38,6 +38,7 @@
### Released packages ### Released packages
- xo-server-backup-reports v0.15.0
- xo-common v0.1.2 - xo-common v0.1.2
- @xen-orchestra/fs v0.4.0 - @xen-orchestra/fs v0.4.0
- complex-matcher v0.5.0 - complex-matcher v0.5.0

View File

@@ -50,6 +50,7 @@ const ICON_FAILURE = '🚨'
const ICON_INTERRUPTED = '⚠️' const ICON_INTERRUPTED = '⚠️'
const ICON_SKIPPED = '⏩' const ICON_SKIPPED = '⏩'
const ICON_SUCCESS = '✔' const ICON_SUCCESS = '✔'
const ICON_WARNING = '⚠️'
const STATUS_ICON = { const STATUS_ICON = {
failure: ICON_FAILURE, failure: ICON_FAILURE,
@@ -99,12 +100,13 @@ const isSkippedError = error =>
error.message === UNHEALTHY_VDI_CHAIN_ERROR || error.message === UNHEALTHY_VDI_CHAIN_ERROR ||
error.message === NO_SUCH_OBJECT_ERROR error.message === NO_SUCH_OBJECT_ERROR
const INDENT = ' '
const createGetTemporalDataMarkdown = formatDate => ( const createGetTemporalDataMarkdown = formatDate => (
start, start,
end, end,
nbIndent = 0 nbIndent = 0
) => { ) => {
const indent = ' '.repeat(nbIndent) const indent = INDENT.repeat(nbIndent)
const markdown = [`${indent}- **Start time**: ${formatDate(start)}`] const markdown = [`${indent}- **Start time**: ${formatDate(start)}`]
if (end !== undefined) { if (end !== undefined) {
@@ -117,6 +119,17 @@ const createGetTemporalDataMarkdown = formatDate => (
return markdown return markdown
} }
const addWarnings = (text, warnings, nbIndent = 0) => {
if (warnings === undefined) {
return
}
const indent = INDENT.repeat(nbIndent)
warnings.forEach(({ message }) => {
text.push(`${indent}- **${ICON_WARNING} ${message}**`)
})
}
class BackupReportsXoPlugin { class BackupReportsXoPlugin {
constructor (xo) { constructor (xo) {
this._xo = xo this._xo = xo
@@ -185,10 +198,9 @@ class BackupReportsXoPlugin {
`- **mode**: ${mode}`, `- **mode**: ${mode}`,
...getTemporalDataMarkdown(log.start, log.end), ...getTemporalDataMarkdown(log.start, log.end),
`- **Error**: ${log.result.message}`, `- **Error**: ${log.result.message}`,
'---',
'',
`*${pkg.name} v${pkg.version}*`,
] ]
addWarnings(markdown, log.warnings)
markdown.push('---', '', `*${pkg.name} v${pkg.version}*`)
markdown = markdown.join('\n') markdown = markdown.join('\n')
return this._sendReport({ return this._sendReport({
@@ -230,6 +242,7 @@ class BackupReportsXoPlugin {
`- **UUID**: ${vm !== undefined ? vm.uuid : vmId}`, `- **UUID**: ${vm !== undefined ? vm.uuid : vmId}`,
...getTemporalDataMarkdown(taskLog.start, taskLog.end), ...getTemporalDataMarkdown(taskLog.start, taskLog.end),
] ]
addWarnings(text, taskLog.warnings)
const failedSubTasks = [] const failedSubTasks = []
const snapshotText = [] const snapshotText = []
@@ -264,6 +277,7 @@ class BackupReportsXoPlugin {
}** (${id}) ${icon}`, }** (${id}) ${icon}`,
...getTemporalDataMarkdown(subTaskLog.start, subTaskLog.end, 2) ...getTemporalDataMarkdown(subTaskLog.start, subTaskLog.end, 2)
) )
addWarnings(remotesText, subTaskLog.warnings, 2)
if (subTaskLog.status === 'failure') { if (subTaskLog.status === 'failure') {
failedSubTasks.push(remote !== undefined ? remote.name : id) failedSubTasks.push(remote !== undefined ? remote.name : id)
remotesText.push('', errorMessage) remotesText.push('', errorMessage)
@@ -280,6 +294,7 @@ class BackupReportsXoPlugin {
` - **${srName}** (${srUuid}) ${icon}`, ` - **${srName}** (${srUuid}) ${icon}`,
...getTemporalDataMarkdown(subTaskLog.start, subTaskLog.end, 2) ...getTemporalDataMarkdown(subTaskLog.start, subTaskLog.end, 2)
) )
addWarnings(srsText, subTaskLog.warnings, 2)
if (subTaskLog.status === 'failure') { if (subTaskLog.status === 'failure') {
failedSubTasks.push(sr !== undefined ? sr.name_label : id) failedSubTasks.push(sr !== undefined ? sr.name_label : id)
srsText.push('', errorMessage) srsText.push('', errorMessage)
@@ -295,6 +310,7 @@ class BackupReportsXoPlugin {
} }
const operationInfoText = [] const operationInfoText = []
addWarnings(operationInfoText, operationLog.warnings, 3)
if (operationLog.status === 'success') { if (operationLog.status === 'success') {
const size = operationLog.result.size const size = operationLog.result.size
if (operationLog.message === 'merge') { if (operationLog.message === 'merge') {
@@ -410,6 +426,7 @@ class BackupReportsXoPlugin {
if (globalMergeSize !== 0) { if (globalMergeSize !== 0) {
markdown.push(`- **Merge size**: ${formatSize(globalMergeSize)}`) markdown.push(`- **Merge size**: ${formatSize(globalMergeSize)}`)
} }
addWarnings(markdown, log.warnings)
markdown.push('') markdown.push('')
if (nFailures !== 0) { if (nFailures !== 0) {