From 3af4b4a7d39f4f77a83b5d0bd5143772e3da9aa2 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 30 Oct 2024 12:45:43 +0000 Subject: [PATCH 1/2] Avoid asynchronously fetching the loki backend during the write path This avoids an issue where we clear the logs buffer before the loki write path has a chance to consume/transform it Change-type: patch --- src/features/device-logs/lib/store.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/features/device-logs/lib/store.ts b/src/features/device-logs/lib/store.ts index 0f3fe31ff..592b53870 100644 --- a/src/features/device-logs/lib/store.ts +++ b/src/features/device-logs/lib/store.ts @@ -132,6 +132,8 @@ function handleStoreErrors(req: Request, res: Response, err: Error) { res.status(500).end(); } +const lokiBackend = LOKI_ENABLED ? await getLokiBackend() : undefined; + const publishBackend = LOKI_ENABLED ? async ( backend: DeviceLogsBackend, @@ -140,7 +142,7 @@ const publishBackend = LOKI_ENABLED ) => { const publishingToRedis = backend.publish(ctx, buffer); const publishingToLoki = shouldPublishToLoki() - ? (await getLokiBackend()).publish(ctx, buffer).catch((err) => { + ? lokiBackend?.publish(ctx, buffer).catch((err) => { captureException(err, 'Failed to publish logs to Loki'); }) : undefined; From f40297f694fe42ec4bad8e84d9ba5c67b53d1b42 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 30 Oct 2024 12:46:23 +0000 Subject: [PATCH 2/2] Remove backend address info from error log Change-type: patch --- src/features/device-logs/lib/backends/loki.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/device-logs/lib/backends/loki.ts b/src/features/device-logs/lib/backends/loki.ts index 7b3cc2201..a5a3bb34e 100644 --- a/src/features/device-logs/lib/backends/loki.ts +++ b/src/features/device-logs/lib/backends/loki.ts @@ -181,7 +181,7 @@ export class LokiBackend implements DeviceLogsBackend { streams.push(...queryResponse.getStreamsList()); }); call.on('error', (error: Error & { details: string }) => { - const message = `Failed to query logs from ${lokiQueryAddress} for device ${ctx.uuid}`; + const message = `Failed to query logs for device ${ctx.uuid}`; captureException(error, message); reject(new BadRequestError(message)); });