MCPcopy
hub / github.com/scality/cloudserver / fetchCapacityMetrics

Function fetchCapacityMetrics

lib/routes/veeam/utils.js:231–251  ·  view source on GitHub ↗

* Fetches capacity metrics from UtilizationService for a bucket. * Handles 404 gracefully (no metrics available yet, e.g. post-install), * returning a default bucketMetrics with the current date so callers always * receive a usable object. * * @param {object} bucketMd - bucket metadata * @para

(bucketMd, request, log)

Source from the content-addressed store, hash-verified

229 * on a real 404 the date defaults to new Date()
230 */
231async function fetchCapacityMetrics(bucketMd, request, log) {
232 const bucketKey = `${bucketMd._name}_${new Date(bucketMd._creationDate).getTime()}`;
233 try {
234 return await getUtilizationMetrics('bucket', bucketKey, null, {});
235 } catch (err) {
236 const statusCode = err.response?.status || err.statusCode || err.code;
237 if (statusCode === 404) {
238 log.warn('UtilizationService returned 404 when fetching capacity metrics', {
239 bucket: request.bucketName,
240 error: err.message || err.code,
241 });
242 return { date: new Date() };
243 }
244 log.error('error fetching capacity metrics from UtilizationService', {
245 bucket: request.bucketName,
246 error: err.message || err.code,
247 statusCode,
248 });
249 throw err;
250 }
251}
252
253/**
254 * Builds Veeam file data (XML content + response metadata) for a given request.

Callers 3

listVeeamFilesFunction · 0.85
buildVeeamFileDataFunction · 0.85
veeam-utils.jsFile · 0.85

Calls 2

warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected