From 79bf42cb5fa44ab1be868df2440c546a205bb780 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Tue, 12 Dec 2023 10:17:02 +0000 Subject: [PATCH] Avoid any async operations for loki publish before processing logs This means the logs are processed before being cleared as is expected by the interface Change-type: patch --- src/features/device-logs/lib/backends/loki.ts | 6 +++--- src/features/device-logs/lib/struct.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/features/device-logs/lib/backends/loki.ts b/src/features/device-logs/lib/backends/loki.ts index c71a487c9..fadff718e 100644 --- a/src/features/device-logs/lib/backends/loki.ts +++ b/src/features/device-logs/lib/backends/loki.ts @@ -204,16 +204,16 @@ export class LokiBackend implements DeviceLogsBackend { } public async publish( - $ctx: LogContext, + ctx: LogContext, logs: Array, ): Promise { - const ctx = await assertLokiLogContext($ctx); const countLogs = logs.length; incrementPublishCallTotal(); incrementPublishLogMessagesTotal(countLogs); const streams = this.fromDeviceLogsToStreams(ctx, logs); + const lokiCtx = await assertLokiLogContext(ctx); try { - await this.push(ctx.belongs_to__application, streams); + await this.push(lokiCtx.belongs_to__application, streams); incrementPublishCallSuccessTotal(); } catch (err) { incrementPublishCallFailedTotal(); diff --git a/src/features/device-logs/lib/struct.ts b/src/features/device-logs/lib/struct.ts index c09087392..9695950a9 100644 --- a/src/features/device-logs/lib/struct.ts +++ b/src/features/device-logs/lib/struct.ts @@ -46,7 +46,9 @@ export type Subscription = (log: DeviceLog) => void; export interface DeviceLogsBackend { history(ctx: LogContext, count: number): Promise; available: boolean; - // `logs` will be mutated to empty and so must be handled synchronously + /** + * `logs` will be mutated to empty and so must be handled synchronously + */ publish(ctx: LogContext, logs: DeviceLog[]): Promise; subscribe(ctx: LogContext, subscription: Subscription): void; unsubscribe(ctx: LogContext, subscription: Subscription): void;