Log takeLock and releaseLock steps as system events

Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
Christina Ying Wang 2024-03-14 14:53:06 -07:00
parent fd7d58f89a
commit 7220e994dc
3 changed files with 22 additions and 0 deletions

View File

@ -5,6 +5,8 @@ export type EventTrackProperties = Dictionary<any>;
const mixpanelMask = [
'appId',
'force',
'services',
'delay',
'error',
'interval',

View File

@ -168,3 +168,13 @@ export const removeNetworkError: LogType = {
eventName: 'Network removal error',
humanName: 'Error removing network',
};
export const takeLock: LogType = {
eventName: 'Take update locks',
humanName: 'Taking update locks',
};
export const releaseLock: LogType = {
eventName: 'Release update locks',
humanName: 'Releasing update locks',
};

View File

@ -14,6 +14,8 @@ import * as config from '../config';
import * as lockfile from './lockfile';
import { NumericIdentifier, StringIdentifier, DockerName } from '../types';
import { takeGlobalLockRW } from './process-lock';
import * as logger from '../logger';
import * as logTypes from './log-types';
const decodedUid = NumericIdentifier.decode(process.env.LOCKFILE_UID);
export const LOCKFILE_UID = isRight(decodedUid) ? decodedUid.right : 65534;
@ -87,6 +89,12 @@ export async function takeLock(
services: string[],
force: boolean = false,
) {
logger.logSystemEvent(logTypes.takeLock, {
appId,
services,
force,
});
const release = await takeGlobalLockRW(appId);
try {
const actuallyLocked: string[] = [];
@ -122,6 +130,8 @@ export async function takeLock(
* Release all locks for an appId | appUuid.
*/
export async function releaseLock(appId: number) {
logger.logSystemEvent(logTypes.releaseLock, { appId });
const release = await takeGlobalLockRW(appId);
await dispose(appId, release);
}