Skip to content

Commit

Permalink
Avoid any async operations for loki publish before processing logs
Browse files Browse the repository at this point in the history
This means the logs are processed before being cleared as is expected
by the interface

Change-type: patch
  • Loading branch information
Page- committed Dec 12, 2023
1 parent d6799b8 commit 79bf42c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/features/device-logs/lib/backends/loki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ export class LokiBackend implements DeviceLogsBackend {
}

public async publish(
$ctx: LogContext,
ctx: LogContext,
logs: Array<DeviceLog & { version?: number }>,
): Promise<any> {
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();
Expand Down
4 changes: 3 additions & 1 deletion src/features/device-logs/lib/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export type Subscription = (log: DeviceLog) => void;
export interface DeviceLogsBackend {
history(ctx: LogContext, count: number): Promise<DeviceLog[]>;
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<any>;
subscribe(ctx: LogContext, subscription: Subscription): void;
unsubscribe(ctx: LogContext, subscription: Subscription): void;
Expand Down

0 comments on commit 79bf42c

Please sign in to comment.