From ee4e176039aee7d0e5796d8fbc12fb9a262b3a57 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 14 Dec 2021 23:00:45 +0100 Subject: [PATCH] web/admin: fix invalid display for LDAP Source sync status Signed-off-by: Jens Langhammer --- .../charts/LDAPSyncStatusChart.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/web/src/pages/admin-overview/charts/LDAPSyncStatusChart.ts b/web/src/pages/admin-overview/charts/LDAPSyncStatusChart.ts index b4341a171..f8aebf80f 100644 --- a/web/src/pages/admin-overview/charts/LDAPSyncStatusChart.ts +++ b/web/src/pages/admin-overview/charts/LDAPSyncStatusChart.ts @@ -36,37 +36,41 @@ export class LDAPSyncStatusChart extends AKChart { async apiRequest(): Promise { const api = new SourcesApi(DEFAULT_CONFIG); const sources = await api.sourcesLdapList({}); - let healthy = 0; - let failed = 0; - let unsynced = 0; + const metrics: { [key: string]: number } = { + healthy: 0, + failed: 0, + unsynced: 0, + }; await Promise.all( sources.results.map(async (element) => { + // Each source should have 3 successful tasks, so the worst task overwrites + let sourceKey = "healthy"; try { const health = await api.sourcesLdapSyncStatusList({ slug: element.slug, }); + health.forEach((task) => { if (task.status !== StatusEnum.Successful) { - failed += 1; + sourceKey = "failed"; } const now = new Date().getTime(); const maxDelta = 3600000; // 1 hour if (!health || now - task.taskFinishTimestamp.getTime() > maxDelta) { - unsynced += 1; - } else { - healthy += 1; + sourceKey = "unsynced"; } }); } catch { - unsynced += 1; + sourceKey = "unsynced"; } + metrics[sourceKey] += 1; }), ); this.centerText = sources.pagination.count.toString(); return { - healthy: sources.pagination.count === 0 ? -1 : healthy, - failed, - unsynced, + healthy: sources.pagination.count === 0 ? -1 : metrics.healthy, + failed: metrics.failed, + unsynced: metrics.unsynced, }; }