Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Warn admins about running multiple instances of the monolith #26667

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}