Skip to content

Commit 066b295

Browse files
fix: add statistics update in startup (RocketChat#38127)
1 parent 28a8d39 commit 066b295

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

.changeset/tall-timers-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes workspace statistics deployment data not updating on server version changes.

apps/meteor/app/statistics/server/lib/statistics.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { getImporterStatistics } from './getImporterStatistics';
3838
import { getServicesStatistics } from './getServicesStatistics';
3939
import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
4040
import { isRunningMs } from '../../../../server/lib/isRunningMs';
41+
import { SystemLogger } from '../../../../server/lib/logger/system';
4142
import { getControl } from '../../../../server/lib/migrations';
4243
import { getSettingsStatistics } from '../../../../server/lib/statistics/getSettingsStatistics';
4344
import { getMatrixFederationStatistics } from '../../../../server/services/federation/infrastructure/rocket-chat/adapters/Statistics';
@@ -599,4 +600,58 @@ export const statistics = {
599600

600601
return rcStatistics;
601602
},
603+
async updateDeploymentData(): Promise<void> {
604+
try {
605+
const lastStatistics = await Statistics.findLast();
606+
607+
if (!lastStatistics) {
608+
return;
609+
}
610+
611+
const { mongoVersion, mongoStorageEngine } = await getMongoInfo();
612+
613+
const deploymentInfo: Partial<IStats> = {
614+
os: {
615+
type: os.type(),
616+
platform: os.platform(),
617+
arch: os.arch(),
618+
release: os.release(),
619+
uptime: os.uptime(),
620+
loadavg: os.loadavg(),
621+
totalmem: os.totalmem(),
622+
freemem: os.freemem(),
623+
cpus: os.cpus(),
624+
},
625+
process: {
626+
nodeVersion: process.version,
627+
pid: process.pid,
628+
uptime: process.uptime(),
629+
},
630+
deploy: {
631+
method: process.env.DEPLOY_METHOD || 'tar',
632+
platform: process.env.DEPLOY_PLATFORM || 'selfinstall',
633+
},
634+
msEnabled: isRunningMs(),
635+
mongoVersion,
636+
mongoStorageEngine: mongoStorageEngine || '',
637+
migration: await getControl(),
638+
};
639+
640+
if (Info) {
641+
deploymentInfo.version = Info.version;
642+
}
643+
644+
const { _id, ...baseStatistics } = lastStatistics;
645+
646+
const newStatistics: Omit<IStats, '_id'> = {
647+
...baseStatistics,
648+
...deploymentInfo,
649+
createdAt: new Date(),
650+
};
651+
652+
await Statistics.insertOne(newStatistics);
653+
} catch (error) {
654+
SystemLogger.error({ msg: 'Error saving statistics with new deployment data', err: error });
655+
}
656+
},
602657
};

apps/meteor/server/startup/migrations/xrun.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { UpdateResult } from 'mongodb';
33

44
import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions';
55
import { settings } from '../../../app/settings/server';
6+
import { statistics } from '../../../app/statistics/server/lib/statistics';
67
import { migrateDatabase, onServerVersionChange } from '../../lib/migrations';
78
import { ensureCloudWorkspaceRegistered } from '../cloudRegistration';
89

@@ -62,5 +63,6 @@ export const performMigrationProcedure = async (): Promise<void> => {
6263
await upsertPermissions();
6364
await ensureCloudWorkspaceRegistered();
6465
await moveRetentionSetting();
66+
await statistics.updateDeploymentData();
6567
});
6668
};

0 commit comments

Comments
 (0)