Compare commits

...

4 Commits

Author SHA1 Message Date
Naren f30414f385 request log 2022-07-27 14:14:27 -07:00
Naren 6c3919405a request log 2022-07-26 20:56:00 -07:00
Naren 59a65d584d request log 2022-07-26 14:42:37 -07:00
Naren dfa3626337 logs 2022-07-26 13:49:40 -07:00
3 changed files with 96 additions and 2 deletions

View File

@ -41,6 +41,10 @@ function getAmzRestoreResHeader(objMD) {
* @return {ArsenalError|undefined} - undefined if the conditions for RestoreObject are fulfilled
*/
function _validateStartRestore(objectMD, log) {
log.info('calling _validateStartRestore', {
objectMD,
method: 'object-restore',
});
const isLocationCold = locationConstraints[objectMD.dataStoreName]?.isCold;
if (!isLocationCold) {
// return InvalidObjectState error if the object is not in cold storage,
@ -149,6 +153,11 @@ function isObjectAlreadyRestored(objectMD, log) {
*
*/
function _updateRestoreInfo(objectMD, restoreParam, log) {
log.info('calling _updateRestoreInfo', {
objectMD,
restoreParam,
method: 'object-restore',
});
if (!objectMD.archive) {
log.debug('objectMD.archive doesn\'t exits', {
objectMD,
@ -185,14 +194,31 @@ function _updateRestoreInfo(objectMD, restoreParam, log) {
*
*/
function startRestore(objectMD, restoreParam, log, cb) {
log.info('calling startRestore', {
objectMD,
restoreParam,
method: 'object-restore',
});
log.info('Validating if restore can be done or not.');
const checkResultError = _validateStartRestore(objectMD, log);
if (checkResultError) {
log.info('_validateStartRestore erro', {
objectMD,
restoreParam,
method: 'object-restore',
err: checkResultError,
});
return cb(checkResultError);
}
log.info('Updating restore information.');
const updateResultError = _updateRestoreInfo(objectMD, restoreParam, log);
if (updateResultError) {
log.info('_validateStartRestore erro', {
objectMD,
restoreParam,
method: 'object-restore',
err: updateResultError,
});
return cb(updateResultError);
}
return cb(null, isObjectAlreadyRestored(objectMD, log));

View File

@ -35,13 +35,21 @@ function checkTierSupported(restoreInfo) {
*/
function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
const METHOD = 'objectRestore';
const mtd = 'object-restore';
const { bucketName, objectKey } = request;
log.info('object restore called', {
method: mtd,
});
log.debug('processing request', { method: METHOD });
const decodedVidResult = decodeVersionId(request.query);
if (decodedVidResult instanceof Error) {
log.info('invalid versionid query', {
method: mtd,
request,
});
log.trace('invalid versionId query',
{
method: METHOD,
@ -66,12 +74,21 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
function validateBucketAndObject(next) {
return mdUtils.metadataValidateBucketAndObj(mdValueParams, log, (err, bucketMD, objectMD) => {
if (err) {
log.info('metadata validate bucket and obj failed', {
method: mtd,
err,
});
log.trace('request authorization failed', { method: METHOD, error: err });
return next(err);
}
// Call back error if object metadata could not be obtained
if (!objectMD) {
const err = decodedVidResult ? errors.NoSuchVersion : errors.NoSuchKey;
log.info('no object md', {
method: mtd,
bucket: bucketName,
key: objectKey,
});
log.trace('error no object metadata found', { method: METHOD, error: err });
return next(err, bucketMD);
}
@ -82,6 +99,12 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
if (decodedVidResult) {
err = errors.MethodNotAllowed;
}
log.info('version is a delete marker', {
method: mtd,
bucket: bucketName,
key: objectKey,
err,
});
log.trace('version is a delete marker', { method: METHOD, error: err });
return next(err, bucketMD, objectMD);
}
@ -97,11 +120,24 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
log.trace('parsing object restore information');
return parseRestoreRequestXml(request.post, log, (err, restoreInfo) => {
if (err) {
log.info('parse restore xml error', {
method: mtd,
bucket: bucketName,
key: objectKey,
err,
request: request.post,
});
return next(err, bucketMD, objectMD, restoreInfo);
}
log.info('it parsed xml of the request body.', { method: METHOD, value: restoreInfo });
const checkTierResult = checkTierSupported(restoreInfo);
if (checkTierResult instanceof Error) {
log.info('tier error', {
method: mtd,
bucket: bucketName,
key: objectKey,
restoreInfo,
});
return next(checkTierResult);
}
return next(null, bucketMD, objectMD, restoreInfo);
@ -109,6 +145,11 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
},
// start restore process
function startRestore(bucketMD, objectMD, restoreInfo, next) {
log.info('calling startRestore', {
method: mtd,
bucket: bucketName,
key: objectKey,
});
return coldStorage.startRestore(objectMD, restoreInfo, log,
(err, _isObjectRestored) => {
isObjectRestored = _isObjectRestored;
@ -117,14 +158,33 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
},
function updateObjectMD(bucketMD, objectMD, next) {
const params = objectMD.versionId ? { versionId: objectMD.versionId } : {};
log.info('calling updateObjectMD', {
method: mtd,
bucket: bucketName,
key: objectKey,
objMD: objectMD,
});
metadata.putObjectMD(bucketMD.getName(), objectKey, objectMD, params,
log, err => next(err, bucketMD, objectMD));
log, err => next(err, { bucketMD, objectMD }));
},
],
(err, bucketMD) => {
(err, res) => {
const { bucketMD, objectMD } = res;
log.info('updated md', {
method: mtd,
bucket: bucketName,
key: objectKey,
objMD: objectMD,
});
// generate CORS response header
const responseHeaders = collectCorsHeaders(request.headers.origin, request.method, bucketMD);
if (err) {
log.info('final error', {
method: mtd,
bucket: bucketName,
key: objectKey,
err,
});
log.trace('error processing request',
{
method: METHOD,
@ -138,6 +198,13 @@ function objectRestore(metadata, mdUtils, userInfo, request, log, callback) {
userInfo,
bucket: bucketName,
});
log.info('sending response', {
method: mtd,
bucket: bucketName,
key: objectKey,
response: responseHeaders,
statusCode: isObjectRestored ? '200' : '202',
});
if (isObjectRestored) {
monitoring.promMetrics(
'POST', bucketName, '200', 'restoreObject');

View File

@ -150,6 +150,7 @@ class S3Server {
vault,
},
};
logger.info('custom-log');
routes(req, res, params, logger, _config);
}