1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Revert "Renderer file logging transport (#6795)" (#7245)

Renderer file logging still caused UI freezing (at least on apple silicon macs) when cluster frame was open and main frame was reloaded.

See #544

This reverts commit ac2d0e46ff.

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
This commit is contained in:
Sami Tiilikainen 2023-02-28 16:02:42 +02:00 committed by GitHub
parent c174965708
commit ec81af4e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 105 deletions

View File

@ -3,13 +3,20 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { createLogger, format } from "winston";
import type { Logger } from "./logger"; import type { Logger } from "./logger";
import winstonLoggerInjectable from "./winston-logger.injectable"; import { loggerTransportInjectionToken } from "./logger/transports";
const loggerInjectable = getInjectable({ const loggerInjectable = getInjectable({
id: "logger", id: "logger",
instantiate: (di): Logger => { instantiate: (di): Logger => {
const baseLogger = di.inject(winstonLoggerInjectable); const baseLogger = createLogger({
format: format.combine(
format.splat(),
format.simple(),
),
transports: di.injectMany(loggerTransportInjectionToken),
});
return { return {
debug: (message, ...data) => baseLogger.debug(message, ...data), debug: (message, ...data) => baseLogger.debug(message, ...data),

View File

@ -1,20 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { createLogger, format } from "winston";
import { loggerTransportInjectionToken } from "./logger/transports";
const winstonLoggerInjectable = getInjectable({
id: "winston-logger",
instantiate: (di) => createLogger({
format: format.combine(
format.splat(),
format.simple(),
),
transports: di.injectMany(loggerTransportInjectionToken),
}),
});
export default winstonLoggerInjectable;

View File

@ -46,9 +46,7 @@ export async function bootstrap(di: DiContainer) {
} }
try { try {
await initializeApp(() => { await initializeApp(() => unmountComponentAtNode(rootElem));
unmountComponentAtNode(rootElem);
});
} catch (error) { } catch (error) {
console.error(`[BOOTSTRAP]: view initialization error: ${error}`, { console.error(`[BOOTSTRAP]: view initialization error: ${error}`, {
origin: location.href, origin: location.href,

View File

@ -12,7 +12,6 @@ import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.
import loadExtensionsInjectable from "../../load-extensions.injectable"; import loadExtensionsInjectable from "../../load-extensions.injectable";
import loggerInjectable from "../../../../common/logger.injectable"; import loggerInjectable from "../../../../common/logger.injectable";
import showErrorNotificationInjectable from "../../../components/notifications/show-error-notification.injectable"; import showErrorNotificationInjectable from "../../../components/notifications/show-error-notification.injectable";
import closeRendererLogFileInjectable from "../../../logger/close-renderer-log-file.injectable";
const initClusterFrameInjectable = getInjectable({ const initClusterFrameInjectable = getInjectable({
id: "init-cluster-frame", id: "init-cluster-frame",
@ -30,7 +29,6 @@ const initClusterFrameInjectable = getInjectable({
emitAppEvent: di.inject(emitAppEventInjectable), emitAppEvent: di.inject(emitAppEventInjectable),
logger: di.inject(loggerInjectable), logger: di.inject(loggerInjectable),
showErrorNotification: di.inject(showErrorNotificationInjectable), showErrorNotification: di.inject(showErrorNotificationInjectable),
closeFileLogging: di.inject(closeRendererLogFileInjectable),
}); });
}, },
}); });

View File

@ -2,7 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { once } from "lodash";
import type { Cluster } from "../../../../common/cluster/cluster"; import type { Cluster } from "../../../../common/cluster/cluster";
import type { CatalogEntityRegistry } from "../../../api/catalog/entity/registry"; import type { CatalogEntityRegistry } from "../../../api/catalog/entity/registry";
import type { ShowNotification } from "../../../components/notifications"; import type { ShowNotification } from "../../../components/notifications";
@ -19,7 +18,6 @@ interface Dependencies {
emitAppEvent: EmitAppEvent; emitAppEvent: EmitAppEvent;
logger: Logger; logger: Logger;
showErrorNotification: ShowNotification; showErrorNotification: ShowNotification;
closeFileLogging: () => void;
} }
const logPrefix = "[CLUSTER-FRAME]:"; const logPrefix = "[CLUSTER-FRAME]:";
@ -32,7 +30,6 @@ export const initClusterFrame = ({
emitAppEvent, emitAppEvent,
logger, logger,
showErrorNotification, showErrorNotification,
closeFileLogging,
}: Dependencies) => }: Dependencies) =>
async (unmountRoot: () => void) => { async (unmountRoot: () => void) => {
// TODO: Make catalogEntityRegistry already initialized when passed as dependency // TODO: Make catalogEntityRegistry already initialized when passed as dependency
@ -76,14 +73,11 @@ export const initClusterFrame = ({
}); });
}); });
const onCloseFrame = once(() => { window.onbeforeunload = () => {
logger.info( logger.info(
`${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`, `${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`,
); );
closeFileLogging();
unmountRoot();
});
window.addEventListener("beforeunload", onCloseFrame); unmountRoot();
window.addEventListener("pagehide", onCloseFrame); };
}; };

View File

@ -13,7 +13,6 @@ import loggerInjectable from "../../../common/logger.injectable";
import { delay } from "../../../common/utils"; import { delay } from "../../../common/utils";
import { broadcastMessage } from "../../../common/ipc"; import { broadcastMessage } from "../../../common/ipc";
import { bundledExtensionsLoaded } from "../../../common/ipc/extension-handling"; import { bundledExtensionsLoaded } from "../../../common/ipc/extension-handling";
import closeRendererLogFileInjectable from "../../logger/close-renderer-log-file.injectable";
const initRootFrameInjectable = getInjectable({ const initRootFrameInjectable = getInjectable({
id: "init-root-frame", id: "init-root-frame",
@ -25,7 +24,6 @@ const initRootFrameInjectable = getInjectable({
const lensProtocolRouterRenderer = di.inject(lensProtocolRouterRendererInjectable); const lensProtocolRouterRenderer = di.inject(lensProtocolRouterRendererInjectable);
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const closeRendererLogFile = di.inject(closeRendererLogFileInjectable);
return async (unmountRoot: () => void) => { return async (unmountRoot: () => void) => {
catalogEntityRegistry.init(); catalogEntityRegistry.init();
@ -61,7 +59,7 @@ const initRootFrameInjectable = getInjectable({
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
logger.info("[ROOT-FRAME]: Unload app"); logger.info("[ROOT-FRAME]: Unload app");
closeRendererLogFile();
unmountRoot(); unmountRoot();
}); });
}; };

View File

@ -1,22 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import winstonLoggerInjectable from "../../common/winston-logger.injectable";
import rendererFileLoggerTransportInjectable from "./file-transport.injectable";
const closeRendererLogFileInjectable = getInjectable({
id: "close-renderer-log-file",
instantiate: (di) => {
const winstonLogger = di.inject(winstonLoggerInjectable);
const fileLoggingTransport = di.inject(rendererFileLoggerTransportInjectable);
return () => {
fileLoggingTransport.close?.();
winstonLogger.remove(fileLoggingTransport);
};
},
});
export default closeRendererLogFileInjectable;

View File

@ -1,44 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { transports } from "winston";
import directoryForLogsInjectable from "../../common/app-paths/directory-for-logs.injectable";
import { loggerTransportInjectionToken } from "../../common/logger/transports";
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
import currentlyInClusterFrameInjectable from "../routes/currently-in-cluster-frame.injectable";
import { getClusterIdFromHost } from "../utils";
const rendererFileLoggerTransportInjectable = getInjectable({
id: "renderer-file-logger-transport",
instantiate: (di) => {
let frameId: string;
const currentlyInClusterFrame = di.inject(
currentlyInClusterFrameInjectable,
);
if (currentlyInClusterFrame) {
const { host } = di.inject(windowLocationInjectable);
const clusterId = getClusterIdFromHost(host);
frameId = clusterId ? `cluster-${clusterId}` : "cluster";
} else {
frameId = "main";
}
return new transports.File({
handleExceptions: false,
level: "info",
filename: `lens-renderer-${frameId}.log`,
dirname: di.inject(directoryForLogsInjectable),
maxsize: 1024 * 1024,
maxFiles: 2,
tailable: true,
});
},
injectionToken: loggerTransportInjectionToken,
});
export default rendererFileLoggerTransportInjectable;