fix(api-quota): Quota reset now also logs storage diff. Log now includes zero valued fields ZMS-128 (#640)

* Log storage diff for quota usage recalculation API endpoint. Also logs 0

* include _set as required key as well
This commit is contained in:
NickOvt 2024-02-29 10:32:40 +02:00 committed by GitHub
parent 9f704f7c5d
commit 64c6b5e63c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 11 deletions

7
api.js
View file

@ -467,7 +467,7 @@ module.exports = done => {
emit: (key, message) => log.info('Gelf', JSON.stringify(message))
};
loggelf = message => {
loggelf = (message, requiredKeys = []) => {
if (typeof message === 'string') {
message = {
short_message: message
@ -484,7 +484,8 @@ module.exports = done => {
message.timestamp = Date.now() / 1000;
message._component = component;
Object.keys(message).forEach(key => {
if (!message[key]) {
if (!message[key] && !requiredKeys.includes(key)) {
// remove the key if it empty/falsy/undefined/null and it is not required to stay
delete message[key];
}
});
@ -538,7 +539,7 @@ module.exports = done => {
settingsHandler = new SettingsHandler({ db: db.database });
server.loggelf = message => loggelf(message);
server.loggelf = (message, requiredKeys = []) => loggelf(message, requiredKeys);
server.lock = new Lock({
redis: db.redis,

View file

@ -1705,14 +1705,18 @@ module.exports = (db, server, userHandler, settingsHandler) => {
});
}
server.loggelf({
short_message: '[QUOTA] reset',
_mail_action: 'quota',
_user: userData._id,
_set: Number(storageUsed) || 0,
_previous_storage_used: Number(updateResponse.value.storageUsed) || 0,
_storage_used: Number(storageUsed) || 0
});
server.loggelf(
{
short_message: '[QUOTA] reset',
_mail_action: 'quota',
_user: userData._id,
_set: Number(storageUsed) || 0,
_previous_storage_used: Number(updateResponse.value.storageUsed) || 0,
_storage_used: Number(storageUsed) || 0,
_storage_diff: Math.abs((Number(updateResponse.value.storageUsed) || 0) - (Number(storageUsed) || 0))
},
['_previous_storage_used', '_storage_used', '_storage_diff', '_set']
);
return res.json({
success: true,