From bf828686fb96a5ec1c0d9e67acb3ccde1ff86852 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 29 Jan 2020 16:14:28 -0300 Subject: [PATCH] [FIX] App removal was moving logs to the trash collection (#16362) * [FIX] App removal was moving logs to the trash collection It may cause a huge delay and memory overload if the app contains a huge history of logs * Add indexes and expire logs after 30 days * Add instance id to apps engine logs --- app/apps/client/admin/appLogs.html | 4 ++++ app/apps/server/storage/logs-storage.js | 3 +++ app/models/server/models/apps-logs-model.js | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/app/apps/client/admin/appLogs.html b/app/apps/client/admin/appLogs.html index 47e901331c8..2200921d8f3 100644 --- a/app/apps/client/admin/appLogs.html +++ b/app/apps/client/admin/appLogs.html @@ -31,6 +31,10 @@
+ {{#if log.instanceId}} + Instance: {{log.instanceId}} + {{/if}} + {{#each entry in log.entries}}
{{ entry.severity }}: {{ entry.timestamp }} (Caller: {{ entry.caller }})
diff --git a/app/apps/server/storage/logs-storage.js b/app/apps/server/storage/logs-storage.js index 78ef627ba59..005a69e70c8 100644 --- a/app/apps/server/storage/logs-storage.js +++ b/app/apps/server/storage/logs-storage.js @@ -1,5 +1,6 @@ import { AppConsole } from '@rocket.chat/apps-engine/server/logging'; import { AppLogStorage } from '@rocket.chat/apps-engine/server/storage'; +import { InstanceStatus } from 'meteor/konecty:multiple-instances-status'; export class AppRealLogsStorage extends AppLogStorage { constructor(model) { @@ -25,6 +26,8 @@ export class AppRealLogsStorage extends AppLogStorage { return new Promise((resolve, reject) => { const item = AppConsole.toStorageEntry(appId, logger); + item.instanceId = InstanceStatus.id(); + try { const id = this.db.insert(item); diff --git a/app/models/server/models/apps-logs-model.js b/app/models/server/models/apps-logs-model.js index a2888e3ba06..0de6844df63 100644 --- a/app/models/server/models/apps-logs-model.js +++ b/app/models/server/models/apps-logs-model.js @@ -3,5 +3,13 @@ import { Base } from './_Base'; export class AppsLogsModel extends Base { constructor() { super('apps_logs'); + + this.tryEnsureIndex({ appId: 1 }); + this.tryEnsureIndex({ _updatedAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 }); + } + + // Bypass trash collection + remove(query) { + return this._db.originals.remove(query); } }