mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-19 03:06:27 +00:00
Use mutation for adding service/image ids to logs to reduce allocations
Change-type: patch
This commit is contained in:
parent
d685ccacb2
commit
3d73bf3e91
@ -12,7 +12,7 @@ import {
|
|||||||
LogBackend,
|
LogBackend,
|
||||||
LogMessage,
|
LogMessage,
|
||||||
} from './logging';
|
} from './logging';
|
||||||
import logMonitor from './logging/monitor';
|
import logMonitor, { MonitorHook } from './logging/monitor';
|
||||||
|
|
||||||
import * as globalEventBus from './event-bus';
|
import * as globalEventBus from './event-bus';
|
||||||
import superConsole from './lib/supervisor-console';
|
import superConsole from './lib/supervisor-console';
|
||||||
@ -109,9 +109,7 @@ export function enable(value: boolean = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function log(message: LogMessage) {
|
export function log(message: LogMessage) {
|
||||||
if (backend != null) {
|
backend?.log(message);
|
||||||
backend.log(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logSystemMessage(
|
export function logSystemMessage(
|
||||||
@ -139,9 +137,10 @@ export function lock(containerId: string): Bluebird.Disposer<() => void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ServiceInfo = { serviceId: number; imageId: number };
|
||||||
export function attach(
|
export function attach(
|
||||||
containerId: string,
|
containerId: string,
|
||||||
serviceInfo: { serviceId: number; imageId: number },
|
{ serviceId, imageId }: ServiceInfo,
|
||||||
): Bluebird<void> {
|
): Bluebird<void> {
|
||||||
// First detect if we already have an attached log stream
|
// First detect if we already have an attached log stream
|
||||||
// for this container
|
// for this container
|
||||||
@ -150,9 +149,14 @@ export function attach(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Bluebird.using(lock(containerId), async () => {
|
return Bluebird.using(lock(containerId), async () => {
|
||||||
await logMonitor.attach(containerId, (message) => {
|
await logMonitor.attach(
|
||||||
log({ ...serviceInfo, ...message });
|
containerId,
|
||||||
});
|
(message: Parameters<MonitorHook>[0] & Partial<ServiceInfo>) => {
|
||||||
|
message.serviceId = serviceId;
|
||||||
|
message.imageId = imageId;
|
||||||
|
log(message);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,7 @@ import * as db from '../db';
|
|||||||
import { spawnJournalctl, toJournalDate } from '../lib/journald';
|
import { spawnJournalctl, toJournalDate } from '../lib/journald';
|
||||||
import log from '../lib/supervisor-console';
|
import log from '../lib/supervisor-console';
|
||||||
|
|
||||||
export type MonitorHook = ({
|
export type MonitorHook = (message: {
|
||||||
message,
|
|
||||||
isStdErr,
|
|
||||||
}: {
|
|
||||||
message: string;
|
message: string;
|
||||||
isStdErr: boolean;
|
isStdErr: boolean;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user