Skip to content

Commit

Permalink
Add quota support in Backbeat
Browse files Browse the repository at this point in the history
- Backbeat may send internal API requests that will evaluate
  quotas. This change fixes these scenarios, as they were
  trying to push finalizer hooks to an empty object.

Issue: CLDSRV-586
  • Loading branch information
williamlardier authored and francoisferrand committed Dec 2, 2024
1 parent c5a0480 commit f930943
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,10 @@ function routeBackbeat(clientIP, request, response, log) {
_normalizeBackbeatRequest(request);
const requestContexts = prepareRequestContexts('objectReplicate', request);

// Ensure backbeat operations like expiration can properly use quotas
// eslint-disable-next-line no-param-reassign
request.finalizerHooks = [];

// proxy api requests to Backbeat API server
if (request.resourceType === 'api') {
if (!config.backbeat) {
Expand Down Expand Up @@ -1518,16 +1522,24 @@ function routeBackbeat(clientIP, request, response, log) {
return backbeatRoutes[request.method][request.resourceType]
[request.query.operation](request, response, log, next);
}],
err => {
if (err) {
return responseJSONBody(err, null, response, log);
}
log.debug('backbeat route response sent successfully',
{ method: request.method,
bucketName: request.bucketName,
objectKey: request.objectKey });
return undefined;
});
err => async.forEachLimit(
// Finalizer hooks are used in a quota context and ensure consistent
// metrics in case of API errors. No operation required if the API
// completed successfully.
request.finalizerHooks,
5,
(hook, done) => hook(err, done),
() => {
if (err) {
return responseJSONBody(err, null, response, log);
}
log.debug('backbeat route response sent successfully',
{ method: request.method,
bucketName: request.bucketName,
objectKey: request.objectKey });
return undefined;
},
));
}


Expand Down

0 comments on commit f930943

Please sign in to comment.