From 20bd4451963b55bac6321acb097713176bb89408 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 11:50:33 -0300 Subject: [PATCH 1/5] Troubleshoot_Disable_Statistics_Generator --- .../rocketchat-i18n/i18n/en.i18n.json | 2 -- apps/meteor/server/cron/statistics.ts | 24 +++---------------- apps/meteor/server/settings/troubleshoot.ts | 15 +++++------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index a0f6d0e0c6a8..7e40f9f283a9 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -5174,8 +5174,6 @@ "Troubleshoot_Disable_Presence_Broadcast_Alert": "This setting prevents all instances form sending the status changes of the users to their clients keeping all the users with their presence status from the first load!", "Troubleshoot_Disable_Sessions_Monitor": "Disable Sessions Monitor", "Troubleshoot_Disable_Sessions_Monitor_Alert": "This setting stops the processing of user sessions causing the statistics to stop working correctly!", - "Troubleshoot_Disable_Statistics_Generator": "Disable Statistics Generator", - "Troubleshoot_Disable_Statistics_Generator_Alert": "This setting stops the processing all statistics making the info page outdated until someone clicks on the refresh button and may cause other missing information around the system!", "Troubleshoot_Disable_Workspace_Sync": "Disable Workspace Sync", "Troubleshoot_Disable_Workspace_Sync_Alert": "This setting stops the sync of this server with Rocket.Chat's cloud and may cause issues with marketplace and enteprise licenses!", "Troubleshoot_Disable_Teams_Mention": "Disable Teams mention", diff --git a/apps/meteor/server/cron/statistics.ts b/apps/meteor/server/cron/statistics.ts index b6f58b66d383..27c1fc064e25 100644 --- a/apps/meteor/server/cron/statistics.ts +++ b/apps/meteor/server/cron/statistics.ts @@ -32,28 +32,10 @@ async function generateStatistics(logger: Logger): Promise { } export async function statsCron(logger: Logger): Promise { - if (settings.get('Troubleshoot_Disable_Statistics_Generator')) { - return; - } - const name = 'Generate and save statistics'; + await generateStatistics(logger); - let previousValue: boolean; - settings.watch('Troubleshoot_Disable_Statistics_Generator', async (value) => { - if (value === previousValue) { - return; - } - previousValue = value; - - if (value) { - await cronJobs.remove(name); - return; - } - - await generateStatistics(logger); - - const now = new Date(); + const now = new Date(); - await cronJobs.add(name, `12 ${now.getHours()} * * *`, async () => generateStatistics(logger)); - }); + await cronJobs.add(name, `12 ${now.getHours()} * * *`, async () => generateStatistics(logger)); } diff --git a/apps/meteor/server/settings/troubleshoot.ts b/apps/meteor/server/settings/troubleshoot.ts index bc1cd1484301..a73cc2afd10f 100644 --- a/apps/meteor/server/settings/troubleshoot.ts +++ b/apps/meteor/server/settings/troubleshoot.ts @@ -19,7 +19,6 @@ export const createTroubleshootSettings = () => i18nDescription: 'Troubleshoot_Disable_Presence_Broadcast_Alert', enableQuery: { _id: 'Presence_broadcast_disabled', value: false }, }); - await this.add('Troubleshoot_Disable_Instance_Broadcast', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Instance_Broadcast_Alert', @@ -32,18 +31,16 @@ export const createTroubleshootSettings = () => type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Livechat_Activity_Monitor_Alert', }); - await this.add('Troubleshoot_Disable_Statistics_Generator', false, { - type: 'boolean', - i18nDescription: 'Troubleshoot_Disable_Statistics_Generator_Alert', - }); await this.add('Troubleshoot_Disable_Data_Exporter_Processor', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Data_Exporter_Processor_Alert', }); - await this.add('Troubleshoot_Disable_Workspace_Sync', false, { - type: 'boolean', - i18nDescription: 'Troubleshoot_Disable_Workspace_Sync_Alert', - }); + + // await this.add('Troubleshoot_Disable_Workspace_Sync', false, { + // type: 'boolean', + // i18nDescription: 'Troubleshoot_Disable_Workspace_Sync_Alert', + // }); + await this.add('Troubleshoot_Disable_Teams_Mention', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Teams_Mention_Alert', From 6b976d1555d9a1df25903a1f0ee10eb1354aafad Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 11:52:59 -0300 Subject: [PATCH 2/5] Troubleshoot_Disable_Workspace_Sync --- apps/meteor/app/cloud/server/index.ts | 26 +++++-------------- .../rocketchat-i18n/i18n/en.i18n.json | 2 -- apps/meteor/server/settings/troubleshoot.ts | 5 ---- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/apps/meteor/app/cloud/server/index.ts b/apps/meteor/app/cloud/server/index.ts index 4bb1f634978e..c7e783d4d5aa 100644 --- a/apps/meteor/app/cloud/server/index.ts +++ b/apps/meteor/app/cloud/server/index.ts @@ -2,7 +2,6 @@ import { cronJobs } from '@rocket.chat/cron'; import { Meteor } from 'meteor/meteor'; import { SystemLogger } from '../../../server/lib/logger/system'; -import { settings } from '../../settings/server'; import { connectWorkspace } from './functions/connectWorkspace'; import { getWorkspaceAccessToken } from './functions/getWorkspaceAccessToken'; import { getWorkspaceAccessTokenWithScope } from './functions/getWorkspaceAccessTokenWithScope'; @@ -13,24 +12,6 @@ import './methods'; const licenseCronName = 'Cloud Workspace Sync'; Meteor.startup(async () => { - // run token/license sync if registered - let TroubleshootDisableWorkspaceSync: boolean; - settings.watch('Troubleshoot_Disable_Workspace_Sync', async (value) => { - if (TroubleshootDisableWorkspaceSync === value) { - return; - } - TroubleshootDisableWorkspaceSync = value; - - if (value) { - return cronJobs.remove(licenseCronName); - } - - setImmediate(() => syncWorkspace()); - await cronJobs.add(licenseCronName, '0 */12 * * *', async () => { - await syncWorkspace(); - }); - }); - const { workspaceRegistered } = await retrieveRegistrationStatus(); if (process.env.REG_TOKEN && process.env.REG_TOKEN !== '' && !workspaceRegistered) { @@ -43,9 +24,14 @@ Meteor.startup(async () => { console.log('Successfully registered with token provided by REG_TOKEN!'); } catch (e: any) { - SystemLogger.error('An error occured registering with token.', e.message); + SystemLogger.error('An error occurred registering with token.', e.message); } } + + setImmediate(() => syncWorkspace()); + await cronJobs.add(licenseCronName, '0 */12 * * *', async () => { + await syncWorkspace(); + }); }); export { getWorkspaceAccessToken, getWorkspaceAccessTokenWithScope }; diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 7e40f9f283a9..c52640641a75 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -5174,8 +5174,6 @@ "Troubleshoot_Disable_Presence_Broadcast_Alert": "This setting prevents all instances form sending the status changes of the users to their clients keeping all the users with their presence status from the first load!", "Troubleshoot_Disable_Sessions_Monitor": "Disable Sessions Monitor", "Troubleshoot_Disable_Sessions_Monitor_Alert": "This setting stops the processing of user sessions causing the statistics to stop working correctly!", - "Troubleshoot_Disable_Workspace_Sync": "Disable Workspace Sync", - "Troubleshoot_Disable_Workspace_Sync_Alert": "This setting stops the sync of this server with Rocket.Chat's cloud and may cause issues with marketplace and enteprise licenses!", "Troubleshoot_Disable_Teams_Mention": "Disable Teams mention", "Troubleshoot_Disable_Teams_Mention_Alert": "This setting disables the teams mention feature. User's won't be able to mention a Team by name in a message and get its members notified.", "True": "True", diff --git a/apps/meteor/server/settings/troubleshoot.ts b/apps/meteor/server/settings/troubleshoot.ts index a73cc2afd10f..84dc2cffaba4 100644 --- a/apps/meteor/server/settings/troubleshoot.ts +++ b/apps/meteor/server/settings/troubleshoot.ts @@ -36,11 +36,6 @@ export const createTroubleshootSettings = () => i18nDescription: 'Troubleshoot_Disable_Data_Exporter_Processor_Alert', }); - // await this.add('Troubleshoot_Disable_Workspace_Sync', false, { - // type: 'boolean', - // i18nDescription: 'Troubleshoot_Disable_Workspace_Sync_Alert', - // }); - await this.add('Troubleshoot_Disable_Teams_Mention', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Teams_Mention_Alert', From 817f267250ac5482929f6a6cf8687abf2878e13f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 13:35:46 -0300 Subject: [PATCH 3/5] review --- apps/meteor/server/settings/troubleshoot.ts | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/meteor/server/settings/troubleshoot.ts b/apps/meteor/server/settings/troubleshoot.ts index 84dc2cffaba4..9b4a76d38f06 100644 --- a/apps/meteor/server/settings/troubleshoot.ts +++ b/apps/meteor/server/settings/troubleshoot.ts @@ -1,4 +1,7 @@ +import semver from 'semver'; + import { settingsRegistry } from '../../app/settings/server'; +import { Info } from '../../app/utils/rocketchat.info'; export const createTroubleshootSettings = () => settingsRegistry.addGroup('Troubleshoot', async function () { @@ -19,6 +22,7 @@ export const createTroubleshootSettings = () => i18nDescription: 'Troubleshoot_Disable_Presence_Broadcast_Alert', enableQuery: { _id: 'Presence_broadcast_disabled', value: false }, }); + await this.add('Troubleshoot_Disable_Instance_Broadcast', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Instance_Broadcast_Alert', @@ -31,13 +35,34 @@ export const createTroubleshootSettings = () => type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Livechat_Activity_Monitor_Alert', }); + await this.add('Troubleshoot_Disable_Data_Exporter_Processor', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Data_Exporter_Processor_Alert', }); - await this.add('Troubleshoot_Disable_Teams_Mention', false, { type: 'boolean', i18nDescription: 'Troubleshoot_Disable_Teams_Mention_Alert', }); + + if (!semver.lt(Info.version, '7.0.0')) { + console.log('remove troubleshoot this setting at next major (7.0.0).'); + } + + // TODO: remove this setting at next major (7.0.0) + await this.add('Troubleshoot_Disable_Statistics_Generator', false, { + type: 'boolean', + i18nDescription: 'Troubleshoot_Disable_Statistics_Generator_Alert', + private: true, + hidden: true, + readonly: true, + }); + // TODO: remove this setting at next major (7.0.0) + await this.add('Troubleshoot_Disable_Workspace_Sync', false, { + type: 'boolean', + i18nDescription: 'Troubleshoot_Disable_Workspace_Sync_Alert', + private: true, + hidden: true, + readonly: true, + }); }); From 68ae76e15ef0a1cc19a7c57d547475e8f0c996e6 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 14:49:06 -0300 Subject: [PATCH 4/5] Apply suggestions from code review --- apps/meteor/server/settings/troubleshoot.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/meteor/server/settings/troubleshoot.ts b/apps/meteor/server/settings/troubleshoot.ts index 9b4a76d38f06..8de085725eca 100644 --- a/apps/meteor/server/settings/troubleshoot.ts +++ b/apps/meteor/server/settings/troubleshoot.ts @@ -45,10 +45,6 @@ export const createTroubleshootSettings = () => i18nDescription: 'Troubleshoot_Disable_Teams_Mention_Alert', }); - if (!semver.lt(Info.version, '7.0.0')) { - console.log('remove troubleshoot this setting at next major (7.0.0).'); - } - // TODO: remove this setting at next major (7.0.0) await this.add('Troubleshoot_Disable_Statistics_Generator', false, { type: 'boolean', From 41d1155df07d6441741eed0f640a026a4453a3cf Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 18 Sep 2023 14:59:41 -0300 Subject: [PATCH 5/5] lint --- apps/meteor/server/settings/troubleshoot.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/meteor/server/settings/troubleshoot.ts b/apps/meteor/server/settings/troubleshoot.ts index 8de085725eca..bfecb1a344f6 100644 --- a/apps/meteor/server/settings/troubleshoot.ts +++ b/apps/meteor/server/settings/troubleshoot.ts @@ -1,7 +1,4 @@ -import semver from 'semver'; - import { settingsRegistry } from '../../app/settings/server'; -import { Info } from '../../app/utils/rocketchat.info'; export const createTroubleshootSettings = () => settingsRegistry.addGroup('Troubleshoot', async function () {