From c77016ea4459bd3bb48f0661cf2c65e06995bb74 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Fri, 4 Sep 2020 11:42:32 +0200 Subject: [PATCH] feat(xo-server-usage-report): ignore replicated VMs (#5241) Fixes #4778 --- CHANGELOG.unreleased.md | 4 +++ packages/xo-server-usage-report/src/index.js | 32 +++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 154c5e87a..18dc5aafc 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -7,6 +7,8 @@ > Users must be able to say: “Nice enhancement, I'm eager to test it” +- [Usage report] Exclude replicated VMs from the VMs evolution [#4778](https://github.com/vatesfr/xen-orchestra/issues/4778) (PR [#5241](https://github.com/vatesfr/xen-orchestra/pull/5241)) + ### Bug fixes > Users must be able to say: “I had this issue, happy to know it's fixed” @@ -27,3 +29,5 @@ > - major: if the change breaks compatibility > > In case of conflict, the highest (lowest in previous list) `$version` wins. + +- xo-server-usage-report minor diff --git a/packages/xo-server-usage-report/src/index.js b/packages/xo-server-usage-report/src/index.js index f9d1bbcc4..ad48ddea3 100644 --- a/packages/xo-server-usage-report/src/index.js +++ b/packages/xo-server-usage-report/src/index.js @@ -405,16 +405,26 @@ async function getSrsStats({ xo, xoObjects }) { } function computeGlobalVmsStats({ haltedVms, vmsStats, xo }) { - const allVms = concat( - map(vmsStats, vm => ({ - uuid: vm.uuid, - name: vm.name, - })), - map(haltedVms, vm => ({ - uuid: vm.uuid, - name: vm.name_label, - })) - ) + const allVms = vmsStats.map(vm => ({ + uuid: vm.uuid, + name: vm.name, + })) + + haltedVms.forEach(vm => { + const isReplication = + 'start' in vm.blockedOperations && + vm.tags.some( + tag => tag === 'Disaster Recovery' || tag === 'Continuous Replication' + ) + + // Exclude replicated VMs because they keep being created/destroyed due to the implementation + if (!isReplication) { + allVms.push({ + uuid: vm.uuid, + name: vm.name_label, + }) + } + }) return Object.assign( computeMeans(vmsStats, [ @@ -426,7 +436,7 @@ function computeGlobalVmsStats({ haltedVms, vmsStats, xo }) { 'netTransmission', ]), { - number: allVms.length, + number: vmsStats.length + haltedVms.length, allVms, } )