Skip to content
Snippets Groups Projects
Unverified Commit a9f8c8e2 authored by Diego Sampaio's avatar Diego Sampaio Committed by GitHub
Browse files

regression: prevent unhandled exception from apps statistics (#32701)


* regression: prevent unhandled exception from apps statistics

* Update Apps-Engine with better error logs

---------

Co-authored-by: default avatarDouglas Gubert <douglas.gubert@gmail.com>
parent c6add10c
No related branches found
No related tags found
No related merge requests found
import { Apps } from '@rocket.chat/apps';
import { AppStatus, AppStatusUtils } from '@rocket.chat/apps-engine/definition/AppStatus';
import mem from 'mem';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { Info } from '../../../utils/rocketchat.info';
export type AppsStatistics = {
......@@ -10,7 +12,7 @@ export type AppsStatistics = {
totalFailed: number | false;
};
export async function getAppsStatistics(): Promise<AppsStatistics> {
async function _getAppsStatistics(): Promise<AppsStatistics> {
if (!Apps.self?.isInitialized()) {
return {
engineVersion: Info.marketplaceApiVersion,
......@@ -20,32 +22,45 @@ export async function getAppsStatistics(): Promise<AppsStatistics> {
};
}
const apps = await Apps.getManager().get();
try {
const apps = await Apps.getManager().get();
let totalInstalled = 0;
let totalActive = 0;
let totalFailed = 0;
let totalInstalled = 0;
let totalActive = 0;
let totalFailed = 0;
await Promise.all(
apps.map(async (app) => {
totalInstalled++;
await Promise.all(
apps.map(async (app) => {
totalInstalled++;
const status = await app.getStatus();
const status = await app.getStatus();
if (status === AppStatus.MANUALLY_DISABLED) {
totalFailed++;
}
if (status === AppStatus.MANUALLY_DISABLED) {
totalFailed++;
}
if (AppStatusUtils.isEnabled(status)) {
totalActive++;
}
}),
);
if (AppStatusUtils.isEnabled(status)) {
totalActive++;
}
}),
);
return {
engineVersion: Info.marketplaceApiVersion,
totalInstalled,
totalActive,
totalFailed,
};
return {
engineVersion: Info.marketplaceApiVersion,
totalInstalled,
totalActive,
totalFailed,
};
} catch (err: unknown) {
SystemLogger.error({ msg: 'Exception while getting Apps statistics', err });
return {
engineVersion: Info.marketplaceApiVersion,
totalInstalled: false,
totalActive: false,
totalFailed: false,
};
}
}
// since this function is called every 5s by `setPrometheusData` we're memoizing the result since the result won't change that often
export const getAppsStatistics = mem(_getAppsStatistics, { maxAge: 60000 });
......@@ -8509,8 +8509,8 @@ __metadata:
linkType: soft
 
"@rocket.chat/apps-engine@npm:alpha":
version: 1.43.0-alpha.783
resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.783"
version: 1.43.0-alpha.784
resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.784"
dependencies:
"@msgpack/msgpack": 3.0.0-beta2
adm-zip: ^0.5.9
......@@ -8526,7 +8526,7 @@ __metadata:
uuid: ~8.3.2
peerDependencies:
"@rocket.chat/ui-kit": "*"
checksum: f580ff051914e1c7866fcf42c46844641cd4ab8d09b35a2df8c6a1369d535d060d9b7450eb64e6c8c5c2ac716faf5bf8082b52c9856496b4a41a29d96a781575
checksum: b86ec5cf809dc06658be0ae24b72b746f373bf83e7ee381e4fe83d7a5f4754359004cdf4d0f89723861bf4a3c7841d5f78bbe280ee863e2c833e64f73f16b124
languageName: node
linkType: hard
 
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment