Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): tell a throttled audit export apart from the row cap

Yudhi Armyndharis3691e41ca7e7
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index 6e73ebef7..d06fc1a62 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -695,7 +695,8 @@
"filteredServerDescription": "لا سجلات تطابق هذه المرشحات. عدّل مرشح الخطورة لتوسيع البحث."
},
"exportFailed": "تعذّر تصدير سجل التدقيق",
- "exportTruncated": "يغطي التصدير أحدث {{rows}} إدخال فقط. ضيّق مرشح الخطورة لتصدير الإدخالات الأقدم."
+ "exportTruncated": "يغطي التصدير أحدث {{rows}} إدخال فقط. ضيّق مرشح الخطورة لتصدير الإدخالات الأقدم.",
+ "exportThrottled": "يغطي التصدير أحدث {{rows}} إدخال فقط لأن البوابة تحدّ من قراءات سجل التدقيق. انتظر دقيقة ثم أعد التصدير."
},
"messageTester": {
"title": "اختبار الرسائل",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 660a0c955..50ab09c7c 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "Keine Protokolle passen auf diese Filter. Passe den Severity-Filter an, um die Suche zu erweitern."
},
"exportFailed": "Audit-Protokoll konnte nicht exportiert werden",
- "exportTruncated": "Der Export umfasst nur die neuesten {{rows}} Einträge. Grenze den Severity-Filter ein, um ältere Einträge zu exportieren."
+ "exportTruncated": "Der Export umfasst nur die neuesten {{rows}} Einträge. Grenze den Severity-Filter ein, um ältere Einträge zu exportieren.",
+ "exportThrottled": "Der Export umfasst nur die neuesten {{rows}} Einträge, weil das Gateway Abfragen des Audit-Logs drosselt. Warte eine Minute und exportiere erneut."
},
"messageTester": {
"title": "Nachrichtentester",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index bb192e779..c02fd5abf 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "No logs match these filters. Adjust the severity filter to widen the search."
},
"exportFailed": "Couldn't export the audit log",
- "exportTruncated": "The export covers only the newest {{rows}} entries. Narrow the severity filter to export older ones."
+ "exportTruncated": "The export covers only the newest {{rows}} entries. Narrow the severity filter to export older ones.",
+ "exportThrottled": "The export covers only the newest {{rows}} entries because the gateway is rate-limiting audit log reads. Wait a minute and export again."
},
"messageTester": {
"title": "Message Tester",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index ebb91d3a7..ac17efde4 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -633,7 +633,8 @@
"filteredServerDescription": "Ningún registro coincide con estos filtros. Ajusta el filtro de severidad para ampliar la búsqueda."
},
"exportFailed": "No se pudo exportar el registro de auditoría",
- "exportTruncated": "La exportación solo abarca las {{rows}} entradas más recientes. Restringe el filtro de severidad para exportar las más antiguas."
+ "exportTruncated": "La exportación solo abarca las {{rows}} entradas más recientes. Restringe el filtro de severidad para exportar las más antiguas.",
+ "exportThrottled": "La exportación solo abarca las {{rows}} entradas más recientes porque la puerta de enlace está limitando las lecturas del registro de auditoría. Espera un minuto y vuelve a exportar."
},
"messageTester": {
"title": "Probador de mensajes",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 97d45631c..064cac7e0 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -682,7 +682,8 @@
"filteredServerDescription": "Aucun journal ne correspond à ces filtres. Ajustez le filtre de gravité pour élargir la recherche."
},
"exportFailed": "Impossible d'exporter le journal d'audit",
- "exportTruncated": "L'export ne couvre que les {{rows}} entrées les plus récentes. Affinez le filtre de gravité pour exporter les plus anciennes."
+ "exportTruncated": "L'export ne couvre que les {{rows}} entrées les plus récentes. Affinez le filtre de gravité pour exporter les plus anciennes.",
+ "exportThrottled": "L'export ne couvre que les {{rows}} entrées les plus récentes, car la passerelle limite les lectures du journal d'audit. Attendez une minute, puis relancez l'export."
},
"messageTester": {
"title": "Testeur de messages",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 8c5078c22..f7980b3a3 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -687,7 +687,8 @@
"filteredServerDescription": "אין יומנים התואמים למסננים אלה. התאימו את מסנן החומרה כדי להרחיב את החיפוש."
},
"exportFailed": "לא ניתן לייצא את יומן הביקורת",
- "exportTruncated": "הייצוא כולל רק את {{rows}} הרשומות האחרונות. צמצמו את מסנן החומרה כדי לייצא רשומות ישנות יותר."
+ "exportTruncated": "הייצוא כולל רק את {{rows}} הרשומות האחרונות. צמצמו את מסנן החומרה כדי לייצא רשומות ישנות יותר.",
+ "exportThrottled": "הייצוא כולל רק את {{rows}} הרשומות האחרונות, כי השער מגביל קריאות של יומן הביקורת. המתינו דקה וייצאו שוב."
},
"messageTester": {
"title": "בדיקת הודעות",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index 448381312..5363930e3 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "इन फ़िल्टर से कोई लॉग मेल नहीं खाता। खोज को व्यापक बनाने के लिए गंभीरता फ़िल्टर को समायोजित करें।"
},
"exportFailed": "ऑडिट लॉग निर्यात नहीं किया जा सका",
- "exportTruncated": "निर्यात में केवल नवीनतम {{rows}} प्रविष्टियाँ शामिल हैं। पुरानी प्रविष्टियाँ निर्यात करने के लिए गंभीरता फ़िल्टर को सीमित करें।"
+ "exportTruncated": "निर्यात में केवल नवीनतम {{rows}} प्रविष्टियाँ शामिल हैं। पुरानी प्रविष्टियाँ निर्यात करने के लिए गंभीरता फ़िल्टर को सीमित करें।",
+ "exportThrottled": "गेटवे ऑडिट लॉग पढ़ने की दर सीमित कर रहा है, इसलिए निर्यात में केवल नवीनतम {{rows}} प्रविष्टियाँ शामिल हैं। एक मिनट रुकें और फिर से निर्यात करें।"
},
"messageTester": {
"title": "संदेश परीक्षक",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 611c6c459..0cd47df67 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -682,7 +682,8 @@
"filteredServerDescription": "Nessun log corrisponde a questi filtri. Modifica il filtro severità per ampliare la ricerca."
},
"exportFailed": "Impossibile esportare il log di controllo",
- "exportTruncated": "L'esportazione copre solo le {{rows}} voci più recenti. Restringi il filtro severità per esportare quelle più vecchie."
+ "exportTruncated": "L'esportazione copre solo le {{rows}} voci più recenti. Restringi il filtro severità per esportare quelle più vecchie.",
+ "exportThrottled": "L'esportazione copre solo le {{rows}} voci più recenti perché il gateway sta limitando le letture del registro di audit. Attendi un minuto ed esporta di nuovo."
},
"messageTester": {
"title": "Messaggio di prova",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 3f5fffd8f..1db55631d 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "이 필터에 일치하는 로그가 없습니다. 검색 범위를 넓히려면 심각도 필터를 조정하세요."
},
"exportFailed": "감사 로그를 내보내지 못했습니다",
- "exportTruncated": "내보내기에는 최신 항목 {{rows}}개만 포함됩니다. 이전 항목을 내보내려면 심각도 필터를 좁히세요."
+ "exportTruncated": "내보내기에는 최신 항목 {{rows}}개만 포함됩니다. 이전 항목을 내보내려면 심각도 필터를 좁히세요.",
+ "exportThrottled": "게이트웨이가 감사 로그 조회를 제한하고 있어 내보내기에는 최신 항목 {{rows}}개만 포함됩니다. 1분 후 다시 내보내세요."
},
"messageTester": {
"title": "메시지 테스터",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 03db2093e..d2028a571 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -633,7 +633,8 @@
"filteredServerDescription": "Nenhum log corresponde a estes filtros. Ajuste o filtro de severidade para ampliar a busca."
},
"exportFailed": "Não foi possível exportar o registro de auditoria",
- "exportTruncated": "A exportação cobre apenas as {{rows}} entradas mais recentes. Restrinja o filtro de severidade para exportar as mais antigas."
+ "exportTruncated": "A exportação cobre apenas as {{rows}} entradas mais recentes. Restrinja o filtro de severidade para exportar as mais antigas.",
+ "exportThrottled": "A exportação cobre apenas as {{rows}} entradas mais recentes porque o gateway está limitando as leituras do log de auditoria. Aguarde um minuto e exporte novamente."
},
"messageTester": {
"title": "Testador de mensagens",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 13f2734f0..dbbc299d6 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "ఈ ఫిల్టర్‌లకు సరిపోయే లాగ్‌లు లేవు. వెతుకులను విస్తరించడానికి తీవ్రత ఫిల్టర్‌ను సర్దుబాటు చేయండి."
},
"exportFailed": "ఆడిట్ లాగ్‌ను ఎక్స్‌పోర్ట్ చేయలేకపోయాం",
- "exportTruncated": "ఎక్స్‌పోర్ట్ తాజా {{rows}} ఎంట్రీలను మాత్రమే కవర్ చేస్తుంది. పాత ఎంట్రీలను ఎక్స్‌పోర్ట్ చేయడానికి తీవ్రత ఫిల్టర్‌ను కుదించండి."
+ "exportTruncated": "ఎక్స్‌పోర్ట్ తాజా {{rows}} ఎంట్రీలను మాత్రమే కవర్ చేస్తుంది. పాత ఎంట్రీలను ఎక్స్‌పోర్ట్ చేయడానికి తీవ్రత ఫిల్టర్‌ను కుదించండి.",
+ "exportThrottled": "గేట్‌వే ఆడిట్ లాగ్ రీడ్‌లను పరిమితం చేస్తున్నందున ఎక్స్‌పోర్ట్ తాజా {{rows}} ఎంట్రీలను మాత్రమే కవర్ చేస్తుంది. ఒక నిమిషం ఆగి మళ్లీ ఎక్స్‌పోర్ట్ చేయండి."
},
"messageTester": {
"title": "మెసేజ్ టెస్టర్",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index ad4997788..b00f9c7f3 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "Bu filtrelerle eşleşen log yok. Aramayı genişletmek için önem filtresini ayarlayın."
},
"exportFailed": "Denetim kaydı dışa aktarılamadı",
- "exportTruncated": "Dışa aktarma yalnızca en yeni {{rows}} kaydı kapsar. Daha eski kayıtları dışa aktarmak için önem filtresini daraltın."
+ "exportTruncated": "Dışa aktarma yalnızca en yeni {{rows}} kaydı kapsar. Daha eski kayıtları dışa aktarmak için önem filtresini daraltın.",
+ "exportThrottled": "Ağ geçidi denetim günlüğü okumalarını sınırladığı için dışa aktarma yalnızca en yeni {{rows}} kaydı kapsar. Bir dakika bekleyip yeniden dışa aktarın."
},
"messageTester": {
"title": "Mesaj Test Aracı",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index fc756e15b..869ecb28b 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "没有符合这些筛选条件的日志。请调整严重级别筛选以扩大搜索范围。"
},
"exportFailed": "无法导出审计日志",
- "exportTruncated": "导出仅涵盖最新的 {{rows}} 条记录。请缩小严重级别筛选范围以导出更早的条目。"
+ "exportTruncated": "导出仅涵盖最新的 {{rows}} 条记录。请缩小严重级别筛选范围以导出更早的条目。",
+ "exportThrottled": "网关正在限制审计日志的读取频率,导出仅涵盖最新的 {{rows}} 条记录。请等待一分钟后重新导出。"
},
"messageTester": {
"title": "消息测试器",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 33c1894c2..372ded8a5 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -678,7 +678,8 @@
"filteredServerDescription": "沒有符合這些篩選條件的日誌。請調整嚴重程度篩選以擴大搜尋範圍。"
},
"exportFailed": "無法匯出審計記錄",
- "exportTruncated": "匯出僅涵蓋最新的 {{rows}} 條記錄。請收窄嚴重程度篩選範圍以匯出較早的項目。"
+ "exportTruncated": "匯出僅涵蓋最新的 {{rows}} 條記錄。請收窄嚴重程度篩選範圍以匯出較早的項目。",
+ "exportThrottled": "閘道正在限制審計記錄的讀取頻率,匯出僅涵蓋最新的 {{rows}} 條記錄。請等待一分鐘後重新匯出。"
},
"messageTester": {
"title": "訊息測試器",
diff --git a/dashboard/src/pages/Logs.test.ts b/dashboard/src/pages/Logs.test.ts
index a9b01217b..02cd21f3b 100644
--- a/dashboard/src/pages/Logs.test.ts
+++ b/dashboard/src/pages/Logs.test.ts
@@ -55,6 +55,8 @@ function jsonResponse(data: unknown): Response {
let exportFailure: number | null = null;
// When set, the export's page walk sees a table of this many rows, served 200 at a time.
let exportTotal: number | null = null;
+// When set, every export page from this offset on is refused with a 429, as a tripped minute tier does.
+let exportThrottledFrom: number | null = null;
function installFetchStub(): void {
globalThis.fetch = ((input: RequestInfo | URL): Promise<Response> => {
@@ -62,6 +64,10 @@ function installFetchStub(): void {
if (exportFailure && url.includes('limit=200')) {
return Promise.resolve(new Response(JSON.stringify({ message: 'boom' }), { status: exportFailure }));
}
+ const offset = Number(new URL(url, 'http://localhost').searchParams.get('offset') ?? 0);
+ if (exportThrottledFrom !== null && url.includes('limit=200') && offset >= exportThrottledFrom) {
+ return Promise.resolve(new Response(JSON.stringify({ message: 'Too Many Requests' }), { status: 429 }));
+ }
if (exportTotal && url.includes('limit=200')) {
return Promise.resolve(jsonResponse({ data: Array(200).fill(LOG_FAILED_SEND), total: exportTotal }));
}
@@ -164,3 +170,23 @@ test('an export that stops at the row cap says so, counted in the UI language',
restore();
}
});
+
+test('an export stopped by the throttle says to wait, not to narrow the filter', async () => {
+ const { screen, fireEvent } = rtl;
+ const { downloads, restore } = recordDownloads();
+ exportTotal = 60_000;
+ exportThrottledFrom = 400;
+ try {
+ renderLogs();
+ await screen.findByText('infra.restart');
+ fireEvent.click(screen.getByRole('button', { name: 'Export CSV' }));
+ // The walk retries the refused page after one second and after two more before it stops.
+ await screen.findByText(/newest 400 entries because the gateway is rate-limiting/, {}, { timeout: 10_000 });
+ assert.equal(screen.queryByText(/Narrow the severity filter/), null, 'the throttle was reported as the row cap');
+ assert.equal(downloads.length, 1, 'the rows fetched before the throttle are still downloaded');
+ } finally {
+ exportTotal = null;
+ exportThrottledFrom = null;
+ restore();
+ }
+});
diff --git a/dashboard/src/pages/Logs.tsx b/dashboard/src/pages/Logs.tsx
index 1a02c16c4..64e6bab87 100644
--- a/dashboard/src/pages/Logs.tsx
+++ b/dashboard/src/pages/Logs.tsx
@@ -95,18 +95,22 @@ export function Logs() {
if (exporting) return;
setExporting(true);
try {
- const { items: all, truncated } = await fetchAllPages<AuditLog>((limit, offset) =>
- auditApi.list({ severity: severityParam, limit, offset }),
- );
+ const {
+ items: all,
+ truncated,
+ throttled,
+ } = await fetchAllPages<AuditLog>((limit, offset) => auditApi.list({ severity: severityParam, limit, offset }));
const q = searchQuery.toLowerCase();
const rows = q
? all.filter(l => l.action.toLowerCase().includes(q) || (l.errorMessage || '').toLowerCase().includes(q))
: all;
if (rows.length > 0) download(buildCsv(rows));
- // The cap keeps the newest rows (the API orders newest first); older ones are missing. The count
- // follows the UI language, not the browser's locale, so it reads right inside the sentence.
+ // Either stop keeps the newest rows (the API orders newest first); older ones are missing. A
+ // narrower filter gets past the cap, only waiting gets past the throttle. The count follows the UI
+ // language, not the browser's locale, so it reads right inside the sentence.
if (truncated) {
- toast.warning(t('logs.exportTruncated', { rows: all.length.toLocaleString(i18n.resolvedLanguage) }));
+ const rowCount = all.length.toLocaleString(i18n.resolvedLanguage);
+ toast.warning(t(throttled ? 'logs.exportThrottled' : 'logs.exportTruncated', { rows: rowCount }));
}
} catch (err) {
toast.error(t('logs.exportFailed'), err instanceof Error ? err.message : undefined);
diff --git a/dashboard/src/utils/fetchAllPages.test.ts b/dashboard/src/utils/fetchAllPages.test.ts
index f64729704..c08128b57 100644
--- a/dashboard/src/utils/fetchAllPages.test.ts
+++ b/dashboard/src/utils/fetchAllPages.test.ts
@@ -44,9 +44,10 @@ test('stops on an empty page even if total over-reports', async () => {
test('honours the safety cap, and says the result stopped short', async () => {
const { fetchPage } = fakeSource(10_000, 200);
- const { items: rows, truncated } = await fetchAllPages(fetchPage, { pageSize: 200, maxItems: 500 });
+ const { items: rows, truncated, throttled } = await fetchAllPages(fetchPage, { pageSize: 200, maxItems: 500 });
assert.equal(rows.length, 600); // stops at the first page that crosses the cap
assert.equal(truncated, true);
+ assert.equal(throttled, false, 'the cap was reported as a throttle');
});
test('a walk that ends exactly at the cap is not truncated', async () => {
@@ -132,7 +133,11 @@ test('a page still throttled past the one-second tier ends the walk with the row
// The per-minute or per-hour tier refused the route: keep what came in rather than wait and throw.
const { fetchPage, calls } = fakeSource(6_000, 200);
let attempts = 0;
- const { items: rows, truncated } = await fetchAllPages(
+ const {
+ items: rows,
+ truncated,
+ throttled,
+ } = await fetchAllPages(
async (limit, offset) => {
attempts++;
if (offset >= 1_000) throw httpError(429);
@@ -141,6 +146,7 @@ test('a page still throttled past the one-second tier ends the walk with the row
{ retryDelayMs: 0 },
);
assert.equal(truncated, true);
+ assert.equal(throttled, true, 'the throttle was reported as the row cap');
assert.equal(rows.length, 1_000);
assert.equal(attempts, calls.length + 3, 'the refused page was tried more than three times');
});
diff --git a/dashboard/src/utils/fetchAllPages.ts b/dashboard/src/utils/fetchAllPages.ts
index 87b8a09a2..053b00b40 100644
--- a/dashboard/src/utils/fetchAllPages.ts
+++ b/dashboard/src/utils/fetchAllPages.ts
@@ -39,12 +39,12 @@ async function retryThrottled<T>(fetchOnce: () => Promise<T>, delayMs: number):
* "last page" and silently truncates the result.
*
* `truncated` is set when the `maxItems` safety cap ended the walk while the server still had rows,
- * or when a page stayed throttled after rows were already in hand.
+ * or when a page stayed throttled after rows were already in hand; `throttled` tells the second apart.
*/
export async function fetchAllPages<T>(
fetchPage: (limit: number, offset: number) => Promise<Page<T>>,
{ pageSize = 200, maxItems = 10_000, retryDelayMs = 1000 }: FetchAllPagesOptions = {},
-): Promise<{ items: T[]; truncated: boolean }> {
+): Promise<{ items: T[]; truncated: boolean; throttled: boolean }> {
const all: T[] = [];
let offset = 0;
for (;;) {
@@ -52,13 +52,15 @@ export async function fetchAllPages<T>(
try {
page = await retryThrottled(() => fetchPage(pageSize, offset), retryDelayMs);
} catch (err) {
- if (all.length > 0 && (err as { status?: number }).status === 429) return { items: all, truncated: true };
+ if (all.length > 0 && (err as { status?: number }).status === 429) {
+ return { items: all, truncated: true, throttled: true };
+ }
throw err;
}
const { data, total } = page;
all.push(...data);
offset += data.length;
- if (data.length === 0 || offset >= total) return { items: all, truncated: false };
- if (all.length >= maxItems) return { items: all, truncated: true };
+ if (data.length === 0 || offset >= total) return { items: all, truncated: false, throttled: false };
+ if (all.length >= maxItems) return { items: all, truncated: true, throttled: false };
}
}