From 3fdf9b3a68be8efc72d6b3a97c7191951d36dc58 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen <55164754+pierre-lehnen-rc@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:27:27 -0300 Subject: [PATCH] [NEW] Warn admins about running multiple instances of the monolith (#26667) Co-authored-by: Guilherme Gazzo <5263975+ggazzo@users.noreply.github.com> --- apps/meteor/client/views/admin/info/InformationPage.tsx | 4 +++- .../meteor/konecty-multiple-instances-status.d.ts | 2 ++ apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json | 1 + apps/meteor/server/models/raw/InstanceStatus.ts | 4 ++++ apps/meteor/server/startup/{instance.js => instance.ts} | 9 +++++++++ apps/meteor/server/stream/streamBroadcast.js | 5 +++++ .../model-typings/src/models/IInstanceStatusModel.ts | 3 +-- 7 files changed, 25 insertions(+), 3 deletions(-) rename apps/meteor/server/startup/{instance.js => instance.ts} (67%) diff --git a/apps/meteor/client/views/admin/info/InformationPage.tsx b/apps/meteor/client/views/admin/info/InformationPage.tsx index 4085bfc43f8ed..86dc85b3c5691 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 && ( ): void; } } diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index dcdbf293d52bc..af4d7a8b633b8 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -3305,6 +3305,7 @@ "Msgs": "Msgs", "multi": "multi", "multi_line": "multi line", + "Multiple_monolith_instances_alert": "You are operating multiple instances... some features will not behave as designed.", "Mute": "Mute", "Mute_and_dismiss": "Mute and dismiss", "Mute_all_notifications": "Mute all notifications", diff --git a/apps/meteor/server/models/raw/InstanceStatus.ts b/apps/meteor/server/models/raw/InstanceStatus.ts index 6c7eea58f5a4a..039d8fa18afc3 100644 --- a/apps/meteor/server/models/raw/InstanceStatus.ts +++ b/apps/meteor/server/models/raw/InstanceStatus.ts @@ -13,4 +13,8 @@ export class InstanceStatusRaw extends BaseRaw 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.ts similarity index 67% rename from apps/meteor/server/startup/instance.js rename to apps/meteor/server/startup/instance.ts index 426a81ae01554..6e9230c560716 100644 --- a/apps/meteor/server/startup/instance.js +++ b/apps/meteor/server/startup/instance.ts @@ -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/apps/meteor/server/stream/streamBroadcast.js b/apps/meteor/server/stream/streamBroadcast.js index 5a4cd0567b0ab..e92ed4cab0977 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}`; diff --git a/packages/model-typings/src/models/IInstanceStatusModel.ts b/packages/model-typings/src/models/IInstanceStatusModel.ts index 9203c5d56e326..dd6aa4d76bc72 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; }