Skip to content

Commit

Permalink
[NEW] Warn admins about running multiple instances of the monolith (#…
Browse files Browse the repository at this point in the history
…26667)

Co-authored-by: Guilherme Gazzo <5263975+ggazzo@users.noreply.github.com>
  • Loading branch information
2 people authored and csuarez committed Aug 26, 2022
1 parent 04b918a commit 3fdf9b3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/meteor/client/views/admin/info/InformationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Page data-qa='admin-info'>
Expand All @@ -52,6 +53,7 @@ const InformationPage = memo(function InformationPage({

<Page.ScrollableContentWithShadow>
<Box marginBlock='none' marginInline='auto' width='full'>
{usingMultipleInstances && <Callout type='danger' title={t('Multiple_monolith_instances_alert')} marginBlockEnd='x16'></Callout>}
{alertOplogForMultipleInstances && (
<Callout
type='danger'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare module 'meteor/konecty:multiple-instances-status' {
namespace InstanceStatus {
function id(): string;

function registerInstance(name: string, instance: Record<string, unknown>): void;
}
}
1 change: 1 addition & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/server/models/raw/InstanceStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export class InstanceStatusRaw extends BaseRaw<IInstanceStatus> implements IInst
},
});
}

async getActiveInstanceCount(): Promise<number> {
return this.col.countDocuments({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) } });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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();
});
5 changes: 5 additions & 0 deletions apps/meteor/server/stream/streamBroadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`;

Expand Down
3 changes: 1 addition & 2 deletions packages/model-typings/src/models/IInstanceStatusModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IInstanceStatus> {
//
getActiveInstanceCount(): Promise<number>;
}

0 comments on commit 3fdf9b3

Please sign in to comment.