Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid any async operations for loki publish before processing logs #1494

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading