Skip to content

Commit

Permalink
Merge pull request #1494 from balena-io/no-async-before-processing
Browse files Browse the repository at this point in the history
Avoid any async operations for loki publish before processing logs
  • Loading branch information
flowzone-app[bot] authored Dec 12, 2023
2 parents d6799b8 + 79bf42c commit 9cd3d46
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 9cd3d46

Please sign in to comment.