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

fix(usage-report): avoid report failure when previous stats are invalid #8240

Merged
merged 2 commits into from
Jan 20, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”

- Fix SR tags not being listed in tag selectors (PR [#8251](https://github.com/vatesfr/xen-orchestra/pull/8251))
- [Plugins/usage-report] Prevent the report creation from failing over and over when previous stats file is empty or incorrect (PR [#8240](https://github.com/vatesfr/xen-orchestra/pull/8240))
- [Backups/Logs] Display mirror backup transfer size (PR [#8224](https://github.com/vatesfr/xen-orchestra/pull/8224))
- [Settings/Remotes] Only allow using encryption when using data block storage to prevent errors during backups (PR [#8244](https://github.com/vatesfr/xen-orchestra/pull/8244))

Expand All @@ -43,6 +44,7 @@
- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
- xo-server patch
- xo-server-usage-report patch
- xo-web patch

<!--packages-end-->
9 changes: 8 additions & 1 deletion packages/xo-server-usage-report/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,14 @@ async function storeStats({ data, storedStatsPath }) {

async function computeEvolution({ storedStatsPath, ...newStats }) {
try {
const oldStats = JSON.parse(await pReadFile(storedStatsPath, 'utf8'))
const fileContent = await pReadFile(storedStatsPath, 'utf8')
let oldStats
try {
oldStats = JSON.parse(fileContent)
} catch {
log.warn('Invalid or empty json stats file')
return
}
const newStatsVms = newStats.vms
const oldStatsVms = oldStats.global.vms
const newStatsHosts = newStats.hosts
Expand Down
Loading