From 64591e731e0d5d40cc9a9a75b4c6070b94c9c220 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 21 May 2021 12:40:10 +0200 Subject: [PATCH] api: status: graceful-degrade when a datastore lookup fails This can happen if the underlying storage failed, in which case we do not want to fail the whole API call, as it should report the status of all datastores. So rather add the error inline to the related store entry and continue. Allows to nicely visualize those stores in the gui. Signed-off-by: Thomas Lamprecht --- src/api2/status.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api2/status.rs b/src/api2/status.rs index 55f489f7..3aff91e7 100644 --- a/src/api2/status.rs +++ b/src/api2/status.rs @@ -55,6 +55,7 @@ use crate::config::acl::{ }, history: { type: Array, + optional: true, description: "A list of usages of the past (last Month).", items: { type: Number, @@ -69,6 +70,11 @@ use crate::config::acl::{ of RRD data of the last Month. Missing if there are not enough data points yet.\ If the estimate lies in the past, the usage is decreasing.", }, + "error": { + type: String, + optional: true, + description: "An error description, for example, when the datastore could not be looked up.", + }, }, }, }, @@ -97,7 +103,19 @@ pub fn datastore_status( continue; } - let datastore = DataStore::lookup_datastore(&store)?; + let datastore = match DataStore::lookup_datastore(&store) { + Ok(datastore) => datastore, + Err(err) => { + list.push(json!({ + "store": store, + "total": -1, + "used": -1, + "avail": -1, + "error": err.to_string() + })); + continue; + } + }; let status = crate::tools::disks::disk_usage(&datastore.base_path())?; let mut entry = json!({