From 35aaf8781dfcc1dc94c056ca5b4460d58b7bc8f3 Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 23 Aug 2022 19:36:47 -0300 Subject: [PATCH 1/2] [NEW] Warn admins about running multiple instances of the monolith --- apps/meteor/client/views/admin/info/InformationPage.tsx | 4 +++- apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json | 1 + apps/meteor/server/models/raw/InstanceStatus.ts | 4 ++++ apps/meteor/server/startup/instance.js | 9 +++++++++ .../model-typings/src/models/IInstanceStatusModel.ts | 3 +-- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/meteor/client/views/admin/info/InformationPage.tsx b/apps/meteor/client/views/admin/info/InformationPage.tsx index 4085bfc43f8e..86dc85b3c569 100644 --- a/apps/meteor/client/views/admin/info/InformationPage.tsx +++ b/apps/meteor/client/views/admin/info/InformationPage.tsx @@ -33,7 +33,8 @@ const InformationPage = memo(function InformationPage({ return null; } - const alertOplogForMultipleInstances = statistics && statistics.instanceCount > 1 && !statistics.oplogEnabled; + const usingMultipleInstances = statistics?.instanceCount > 1; + const alertOplogForMultipleInstances = usingMultipleInstances && !statistics.oplogEnabled; return ( @@ -52,6 +53,7 @@ const InformationPage = memo(function InformationPage({ + {usingMultipleInstances && } {alertOplogForMultipleInstances && ( implements IInst }, }); } + + async getActiveInstanceCount(): Promise { + return this.col.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } }); + } } diff --git a/apps/meteor/server/startup/instance.js b/apps/meteor/server/startup/instance.js index 426a81ae0155..6e9230c56071 100644 --- a/apps/meteor/server/startup/instance.js +++ b/apps/meteor/server/startup/instance.js @@ -2,8 +2,13 @@ import os from 'os'; import { Meteor } from 'meteor/meteor'; import { InstanceStatus } from 'meteor/konecty:multiple-instances-status'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; +import { InstanceStatus as InstanceStatusRaw } from '@rocket.chat/models'; import { startStreamBroadcast } from '../stream/streamBroadcast'; +import { Logger } from '../lib/logger/Logger'; + +const logger = new Logger('InstanceStartup'); Meteor.startup(function () { const instance = { @@ -25,5 +30,9 @@ Meteor.startup(function () { InstanceStatus.registerInstance('rocket.chat', instance); + if (Promise.await(InstanceStatusRaw.getActiveInstanceCount()) > 1) { + logger.warn(TAPi18n.__('Multiple_monolith_instances_alert')); + } + return startStreamBroadcast(); }); diff --git a/packages/model-typings/src/models/IInstanceStatusModel.ts b/packages/model-typings/src/models/IInstanceStatusModel.ts index 9203c5d56e32..dd6aa4d76bc7 100644 --- a/packages/model-typings/src/models/IInstanceStatusModel.ts +++ b/packages/model-typings/src/models/IInstanceStatusModel.ts @@ -2,7 +2,6 @@ import type { IInstanceStatus } from '@rocket.chat/core-typings'; import type { IBaseModel } from './IBaseModel'; -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface IInstanceStatusModel extends IBaseModel { - // + getActiveInstanceCount(): Promise; } From 483ffadd25f4cfb5a74ee49181ab1e33bbf3da13 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 24 Aug 2022 13:49:27 -0300 Subject: [PATCH 2/2] Review --- .../externals/meteor/konecty-multiple-instances-status.d.ts | 2 ++ apps/meteor/server/startup/{instance.js => instance.ts} | 0 apps/meteor/server/stream/streamBroadcast.js | 5 +++++ 3 files changed, 7 insertions(+) rename apps/meteor/server/startup/{instance.js => instance.ts} (100%) diff --git a/apps/meteor/definition/externals/meteor/konecty-multiple-instances-status.d.ts b/apps/meteor/definition/externals/meteor/konecty-multiple-instances-status.d.ts index 2e90067003eb..b64056618399 100644 --- a/apps/meteor/definition/externals/meteor/konecty-multiple-instances-status.d.ts +++ b/apps/meteor/definition/externals/meteor/konecty-multiple-instances-status.d.ts @@ -1,5 +1,7 @@ declare module 'meteor/konecty:multiple-instances-status' { namespace InstanceStatus { function id(): string; + + function registerInstance(name: string, instance: Record): void; } } diff --git a/apps/meteor/server/startup/instance.js b/apps/meteor/server/startup/instance.ts similarity index 100% rename from apps/meteor/server/startup/instance.js rename to apps/meteor/server/startup/instance.ts diff --git a/apps/meteor/server/stream/streamBroadcast.js b/apps/meteor/server/stream/streamBroadcast.js index 5a4cd0567b0a..e92ed4cab097 100644 --- a/apps/meteor/server/stream/streamBroadcast.js +++ b/apps/meteor/server/stream/streamBroadcast.js @@ -4,6 +4,7 @@ import { InstanceStatus } from 'meteor/konecty:multiple-instances-status'; import { check } from 'meteor/check'; import { DDP } from 'meteor/ddp'; import { InstanceStatus as InstanceStatusRaw } from '@rocket.chat/models'; +import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { Logger } from '../lib/logger/Logger'; import { hasPermission } from '../../app/authorization/server'; @@ -67,6 +68,10 @@ function startMatrixBroadcast() { added: Meteor.bindEnvironment((record) => { cache.set(record._id, record); + if (cache.size() > 1) { + logger.warn(TAPi18n.__('Multiple_monolith_instances_alert')); + } + const subPath = getURL('', { cdn: false, full: false }); let instance = `${record.extraInformation.host}:${record.extraInformation.port}${subPath}`;