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
- xo-server-backup-reports v0.15.0
- xo-common v0.1.2
- @xen-orchestra/fs v0.4.0
- complex-matcher v0.5.0

View File

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