From bc0a6716ba23f7e7cf59ea36846f52a998c22f25 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Mon, 19 Aug 2024 17:32:34 +0200 Subject: [PATCH] Reserved storage size in the dashboard isn't useful ... display allocated/scheduled storage instead. Relates to: https://github.com/harvester/harvester/issues/6362 Signed-off-by: Volker Theile --- .../HarvesterHostBasic.vue | 2 +- .../formatters/HarvesterStorageUsed.vue | 105 +++++++++--------- .../list/harvesterhci.io.dashboard.vue | 99 ++++++++--------- pkg/harvester/list/harvesterhci.io.host.vue | 2 +- shell/assets/translations/en-us.yaml | 1 + shell/components/HardwareResourceGauge.vue | 14 ++- 6 files changed, 116 insertions(+), 107 deletions(-) diff --git a/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue b/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue index 3f7e86c673b..28d9f486922 100644 --- a/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue +++ b/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue @@ -268,7 +268,7 @@ export default { diff --git a/pkg/harvester/formatters/HarvesterStorageUsed.vue b/pkg/harvester/formatters/HarvesterStorageUsed.vue index 97ec63ea3dc..edd4d417e27 100644 --- a/pkg/harvester/formatters/HarvesterStorageUsed.vue +++ b/pkg/harvester/formatters/HarvesterStorageUsed.vue @@ -23,77 +23,76 @@ export default { default: '' }, - showReserved: { + showAllocated: { type: Boolean, default: false, }, }, - data() { - return {}; + async fetch() { + const inStore = this.$store.getters['currentProduct'].inStore; + + this.longhornSettings = await this.$store.dispatch(`${ inStore }/findAll`, { type: LONGHORN.SETTINGS }); }, - computed: { - usage() { - const inStore = this.$store.getters['currentProduct'].inStore; - const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`) || {}; + data() { + const inStore = this.$store.getters['currentProduct'].inStore; + const longhornSettings = this.$store.getters[`${ inStore }/all`](LONGHORN.SETTINGS) || []; - return longhornNode?.used || 0; - }, + return { longhornSettings }; + }, - reserved() { + computed: { + storageStats() { + const stats = { + used: 0, + scheduled: 0, + maximum: 0, + reserved: 0, + total: 0 + }; const inStore = this.$store.getters['currentProduct'].inStore; - const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`); - let reserved = 0; + const node = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`) || {}; + const storageOverProvisioningPercentageSetting = this.longhornSettings.find(s => s.id === 'longhorn-system/storage-over-provisioning-percentage'); + const disks = node?.spec?.disks || {}; + const diskStatus = node?.status?.diskStatus || {}; - const disks = longhornNode?.spec?.disks || {}; + stats.used += node?.spec?.allowScheduling ? node.used : 0; - Object.values(disks).map((disk) => { - if (disk.allowScheduling) { - reserved += disk.storageReserved; - } + Object.keys(disks).map((key) => { + stats.scheduled += node?.spec?.allowScheduling ? (diskStatus[key]?.storageScheduled || 0) : 0; + stats.reserved += disks[key]?.storageReserved || 0; }); - - return reserved; - }, - - total() { - const inStore = this.$store.getters['currentProduct'].inStore; - const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`); - let out = 0; - - const diskStatus = longhornNode?.status?.diskStatus || {}; - - Object.values(diskStatus).map((disk) => { - if (disk?.storageMaximum) { - out += disk.storageMaximum; - } + Object.values(diskStatus).map((diskStat) => { + stats.maximum += diskStat?.storageMaximum || 0; }); - return out; + stats.total = ((stats.maximum - stats.reserved) * Number(storageOverProvisioningPercentageSetting?.value ?? 0)) / 100; + + return stats; }, units() { - const exponent = exponentNeeded(this.total, 1024); + const exponent = exponentNeeded(this.storageStats.maximum, 1024); return `${ UNITS[exponent] }iB`; }, used() { - let out = this.formatter(this.usage || 0); + let out = this.formatter(this.storageStats.used); if (!Number.parseFloat(out) > 0) { - out = this.formatter(this.usage || 0, { canRoundToZero: false }); + out = this.formatter(this.storageStats.used, { canRoundToZero: false }); } return out; }, - formatReserved() { - let out = this.formatter(this.reserved || 0); + formatAllocated() { + let out = this.formatter(this.storageStats.scheduled); if (!Number.parseFloat(out) > 0) { - out = this.formatter(this.reserved || 0, { canRoundToZero: false }); + out = this.formatter(this.storageStats.scheduled, { canRoundToZero: false }); } return out; @@ -102,15 +101,15 @@ export default { usedAmountTemplateValues() { return { used: this.used, - total: this.formatter(this.total || 0), + total: this.formatter(this.storageStats.maximum), unit: this.units, }; }, - reservedAmountTemplateValues() { + allocatedAmountTemplateValues() { return { - used: this.formatReserved, - total: this.formatter(this.total || 0), + used: this.formatAllocated, + total: this.formatter(this.storageStats.total), unit: this.units, }; }, @@ -118,7 +117,7 @@ export default { methods: { formatter(value, format) { - const minExponent = exponentNeeded(this.total, 1024); + const minExponent = exponentNeeded(this.storageStats.maximum, 1024); const formatOptions = { addSuffix: false, increment: 1024, @@ -137,21 +136,21 @@ export default {