diff --git a/.changeset/tall-timers-swim.md b/.changeset/tall-timers-swim.md new file mode 100644 index 0000000000000..a161740545b83 --- /dev/null +++ b/.changeset/tall-timers-swim.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes workspace statistics deployment data not updating on server version changes. diff --git a/apps/meteor/app/statistics/server/lib/statistics.ts b/apps/meteor/app/statistics/server/lib/statistics.ts index 29f09fef5386f..08711e20bfbe1 100644 --- a/apps/meteor/app/statistics/server/lib/statistics.ts +++ b/apps/meteor/app/statistics/server/lib/statistics.ts @@ -38,6 +38,7 @@ import { getImporterStatistics } from './getImporterStatistics'; import { getServicesStatistics } from './getServicesStatistics'; import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred'; import { isRunningMs } from '../../../../server/lib/isRunningMs'; +import { SystemLogger } from '../../../../server/lib/logger/system'; import { getControl } from '../../../../server/lib/migrations'; import { getSettingsStatistics } from '../../../../server/lib/statistics/getSettingsStatistics'; import { getMatrixFederationStatistics } from '../../../../server/services/federation/infrastructure/rocket-chat/adapters/Statistics'; @@ -599,4 +600,58 @@ export const statistics = { return rcStatistics; }, + async updateDeploymentData(): Promise { + try { + const lastStatistics = await Statistics.findLast(); + + if (!lastStatistics) { + return; + } + + const { mongoVersion, mongoStorageEngine } = await getMongoInfo(); + + const deploymentInfo: Partial = { + os: { + type: os.type(), + platform: os.platform(), + arch: os.arch(), + release: os.release(), + uptime: os.uptime(), + loadavg: os.loadavg(), + totalmem: os.totalmem(), + freemem: os.freemem(), + cpus: os.cpus(), + }, + process: { + nodeVersion: process.version, + pid: process.pid, + uptime: process.uptime(), + }, + deploy: { + method: process.env.DEPLOY_METHOD || 'tar', + platform: process.env.DEPLOY_PLATFORM || 'selfinstall', + }, + msEnabled: isRunningMs(), + mongoVersion, + mongoStorageEngine: mongoStorageEngine || '', + migration: await getControl(), + }; + + if (Info) { + deploymentInfo.version = Info.version; + } + + const { _id, ...baseStatistics } = lastStatistics; + + const newStatistics: Omit = { + ...baseStatistics, + ...deploymentInfo, + createdAt: new Date(), + }; + + await Statistics.insertOne(newStatistics); + } catch (error) { + SystemLogger.error({ msg: 'Error saving statistics with new deployment data', err: error }); + } + }, }; diff --git a/apps/meteor/server/startup/migrations/xrun.ts b/apps/meteor/server/startup/migrations/xrun.ts index 0344649f99935..fcf6bf8b5137b 100644 --- a/apps/meteor/server/startup/migrations/xrun.ts +++ b/apps/meteor/server/startup/migrations/xrun.ts @@ -3,6 +3,7 @@ import type { UpdateResult } from 'mongodb'; import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions'; import { settings } from '../../../app/settings/server'; +import { statistics } from '../../../app/statistics/server/lib/statistics'; import { migrateDatabase, onServerVersionChange } from '../../lib/migrations'; import { ensureCloudWorkspaceRegistered } from '../cloudRegistration'; @@ -62,5 +63,6 @@ export const performMigrationProcedure = async (): Promise => { await upsertPermissions(); await ensureCloudWorkspaceRegistered(); await moveRetentionSetting(); + await statistics.updateDeploymentData(); }); };