Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander Chan b0e1e45757 ft: ZENKO-595 extend crr stats with failed info 2018-06-26 15:07:49 -07:00
3 changed files with 85 additions and 1 deletions

View File

@ -251,6 +251,82 @@ class Metrics {
}); });
} }
getFailedObjects(site, cnt, callback) {
let limit = cnt;
let cb = callback;
if (cnt && typeof cnt === 'function') {
cb = cnt;
limit = 10;
}
let queryString;
if (site === 'all') {
queryString = 'bb:crr:failed:*'; // all objects
} else {
if (!this._validSites.includes(site)) {
this._logger.error('invlaid site name provided', {
method: 'Metrics.getFailedObjects',
});
return cb(errors.RouteNotFound);
}
queryString = `bb:crr:failed:*:${site}`; // specific site
}
return this._redisClient.scan(queryString, undefined,
(err, failedKeys) => {
if (err) {
this._logger(`Redis error ${err.message} when` +
'scanning for keys', {
error: err,
method: 'Metrics.getFailedObjects',
});
return cb(errors.InternalError);
}
const reducedKeys = [...new Set(failedKeys)];
return this._statsClient.getFailedObjects(this._logger,
reducedKeys, limit,
(err, res) => {
if (err) {
this._logger(`Redis error ${err.message} when ` +
'retrieving keys', {
error: err,
method: 'Metrics.getFailedObjects',
});
return cb(errors.InternalError);
}
return this._handleBatchFailResults(res, cb);
});
});
}
_handleBatchFailResults(res, cb) {
if (res.length < 1) {
this._logger.debug('empty list returned from batch');
return cb(null, []);
}
console.log('entries', require('util').inspect(res, { depth: null }));
return cb(null, []);
// const preSortResults = [];
// for(let i = 0; i < res.length; ++i) {
// const [cmdErr, ent] = res[i];
// if (cmdErr) {
// this._logger.error('Redis batch cmd error', {
// error: err,
// method: 'Metrics._handleBatchFailResults',
// });
// return cb(cmdErr);
// }
// console.log('entries', en);
// // let entry =;
// // try {
// // const tmp = JSON.parse(ent);
// // const entry = JSON.parse(tmp.value);
// // } catch (err) {
// // }
// // preSortResults.push({
// // bucket:
// // });
// }
}
/** /**
* Get all metrics * Get all metrics
* @param {object} details - route details from lib/api/routes.js * @param {object} details - route details from lib/api/routes.js

View File

@ -57,6 +57,14 @@ class StatsModel extends StatsClient {
return array; return array;
} }
getFailedObjects(log, ids, cb) {
if (!this._redis) {
return cb(null, []);
}
const reqsFail = ids.map(id => ['get', id]);
return this._redis.batch(reqsFail, cb);
}
/** /**
* wrapper on `getStats` that handles a list of keys * wrapper on `getStats` that handles a list of keys
* override the method to reduce the returned 2d array from `_getCount` * override the method to reduce the returned 2d array from `_getCount`

View File

@ -3,7 +3,7 @@
"engines": { "engines": {
"node": ">=6.9.5" "node": ">=6.9.5"
}, },
"version": "8.0.0", "version": "8.0.0-zenko-595",
"description": "Common utilities for the S3 project components", "description": "Common utilities for the S3 project components",
"main": "index.js", "main": "index.js",
"repository": { "repository": {