Renderer file logging through IPC (#7300)

* Renderer file logging through IPC

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Remove pagehide event listener as it may cause UI to freeze

Pagehide was needed in cluster frame to better handle main frame close/reload situation. But even empty pagehide listener in cluster frame seems to freeze the UI at least on some situations (multiple clusters open).

Beforeunload is not always executed in cluster frame when main frame is reloaded/closed, leaving log files open. To fix that, `stopIpcLoggingInjectable` is introduced to close all log files.

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Remove unnecessary formatting changes

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Lint fix

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Winston logger override

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Remove usage of doGeneralOverrides as it has been removed

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Update imports to match the new base

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Remove unnecessary id

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Review improvements

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Extract beforeunload listener to injectable

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

* Typo fix

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

---------

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
This commit is contained in:
Sami Tiilikainen authored and GitHub committed 2023-03-21 15:04:22 -04:00
1 parent 517e2fe17d
commit 48db54ec9e
24 files changed
+836 -76

No files matched your search

@@ -22,62 +22,51 @@ interface Dependencies {
const logPrefix = "[CLUSTER-FRAME]:";
export const initClusterFrame = ({
hostedCluster,
loadExtensions,
catalogEntityRegistry,
frameRoutingId,
emitAppEvent,
logger,
showErrorNotification,
}: Dependencies) =>
async (unmountRoot: () => void) => {
export const initClusterFrame =
({
hostedCluster,
loadExtensions,
catalogEntityRegistry,
frameRoutingId,
emitAppEvent,
logger,
showErrorNotification,
}: Dependencies) =>
async () => {
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
catalogEntityRegistry.init();
catalogEntityRegistry.init();
logger.info(
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`,
);
await requestSetClusterFrameId(hostedCluster.id);
await when(() => hostedCluster.ready.get()); // cluster.activate() is done at this point
catalogEntityRegistry.activeEntity = hostedCluster.id;
// Only load the extensions once the catalog has been populated.
// Note that the Catalog might still have unprocessed entities until the extensions are fully loaded.
when(
() => catalogEntityRegistry.items.get().length > 0,
() =>
loadExtensions(),
{
timeout: 15_000,
onError: (error) => {
logger.warn(
"[CLUSTER-FRAME]: error from activeEntity when()",
error,
);
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
},
},
);
setTimeout(() => {
emitAppEvent({
name: "cluster",
action: "open",
params: {
clusterId: hostedCluster.id,
},
});
});
window.onbeforeunload = () => {
logger.info(
`${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`,
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`,
);
unmountRoot();
await requestSetClusterFrameId(hostedCluster.id);
await when(() => hostedCluster.ready.get()); // cluster.activate() is done at this point
catalogEntityRegistry.activeEntity = hostedCluster.id;
// Only load the extensions once the catalog has been populated.
// Note that the Catalog might still have unprocessed entities until the extensions are fully loaded.
when(
() => catalogEntityRegistry.items.get().length > 0,
() => loadExtensions(),
{
timeout: 15_000,
onError: (error) => {
logger.warn("[CLUSTER-FRAME]: error from activeEntity when()", error);
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded.");
},
},
);
setTimeout(() => {
emitAppEvent({
name: "cluster",
action: "open",
params: {
clusterId: hostedCluster.id,
},
});
});
};
};
@@ -9,7 +9,6 @@ import lensProtocolRouterRendererInjectable from "../../protocol-handler/lens-pr
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
import registerIpcListenersInjectable from "../../ipc/register-ipc-listeners.injectable";
import loadExtensionsInjectable from "../load-extensions.injectable";
import loggerInjectable from "../../../common/logger.injectable";
import { delay } from "@k8slens/utilities";
import { broadcastMessage } from "../../../common/ipc";
import { bundledExtensionsLoaded } from "../../../common/ipc/extension-handling";
@@ -23,9 +22,8 @@ const initRootFrameInjectable = getInjectable({
const bindProtocolAddRouteHandlers = di.inject(bindProtocolAddRouteHandlersInjectable);
const lensProtocolRouterRenderer = di.inject(lensProtocolRouterRendererInjectable);
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
const logger = di.inject(loggerInjectable);
return async (unmountRoot: () => void) => {
return async () => {
catalogEntityRegistry.init();
try {
@@ -56,12 +54,6 @@ const initRootFrameInjectable = getInjectable({
window.addEventListener("online", () => broadcastMessage("network:online"));
registerIpcListeners();
window.addEventListener("beforeunload", () => {
logger.info("[ROOT-FRAME]: Unload app");
unmountRoot();
});
};
},
});