From ad6de71826322498a2c13627a758f2c97652c2aa Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Thu, 4 Feb 2021 19:19:11 +0200 Subject: [PATCH] Add more log entries on start up (#1955) * Add more log entries on start up Signed-off-by: Lauri Nevala * And log entry about shell sync Signed-off-by: Lauri Nevala * Refactoring Signed-off-by: Lauri Nevala * Add new line Signed-off-by: Lauri Nevala * Apply suggestions from code review Co-authored-by: Sebastian Malton Signed-off-by: Lauri Nevala Co-authored-by: Jari Kolehmainen Co-authored-by: Sebastian Malton --- src/common/utils/app-version.ts | 11 +++++++++++ src/main/developer-tools.ts | 3 +++ src/main/index.ts | 23 +++++++++++++++++++++++ src/main/lens-proxy.ts | 2 +- src/main/router.ts | 3 ++- src/main/routes/index.ts | 1 + src/main/routes/version-route.ts | 13 +++++++++++++ src/main/window-manager.ts | 10 ++++++++++ 8 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/main/routes/version-route.ts diff --git a/src/common/utils/app-version.ts b/src/common/utils/app-version.ts index a45f5a55bb..d625f44cd7 100644 --- a/src/common/utils/app-version.ts +++ b/src/common/utils/app-version.ts @@ -1,3 +1,4 @@ +import requestPromise from "request-promise-native"; import packageInfo from "../../../package.json"; export function getAppVersion(): string { @@ -11,3 +12,13 @@ export function getBundledKubectlVersion(): string { export function getBundledExtensions(): string[] { return packageInfo.lens?.extensions || []; } + +export async function getAppVersionFromProxyServer(proxyPort: number): Promise { + const response = await requestPromise({ + method: "GET", + uri: `http://localhost:${proxyPort}/version`, + resolveWithFullResponse: true + }); + + return JSON.parse(response.body).version; +} diff --git a/src/main/developer-tools.ts b/src/main/developer-tools.ts index 3a3d5009f8..d0d7e2ae01 100644 --- a/src/main/developer-tools.ts +++ b/src/main/developer-tools.ts @@ -1,9 +1,12 @@ +import logger from "./logger"; + /** * Installs Electron developer tools in the development build. * The dependency is not bundled to the production build. */ export const installDeveloperTools = async () => { if (process.env.NODE_ENV === "development") { + logger.info("๐Ÿค“ Installing developer tools"); const { default: devToolsInstaller, REACT_DEVELOPER_TOOLS } = await import("electron-devtools-installer"); return devToolsInstaller([REACT_DEVELOPER_TOOLS]); diff --git a/src/main/index.ts b/src/main/index.ts index 2b7817f093..af24026a5e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -26,6 +26,7 @@ import { InstalledExtension, extensionDiscovery } from "../extensions/extension- import type { LensExtensionId } from "../extensions/lens-extension"; import { installDeveloperTools } from "./developer-tools"; import { filesystemProvisionerStore } from "./extension-filesystem"; +import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils"; import { bindBroadcastHandlers } from "../common/ipc"; const workingDir = path.join(app.getPath("appData"), appName); @@ -62,6 +63,7 @@ if (process.env.LENS_DISABLE_GPU) { app.on("ready", async () => { logger.info(`๐Ÿš€ Starting Lens from "${workingDir}"`); + logger.info("๐Ÿš Syncing shell environment"); await shellSync(); bindBroadcastHandlers(); @@ -70,6 +72,7 @@ app.on("ready", async () => { app.exit(); }); + logger.info(`๐Ÿ“ก Checking for app updates`); const updater = new AppUpdater(); updater.start(); @@ -78,6 +81,7 @@ app.on("ready", async () => { await installDeveloperTools(); + logger.info("๐Ÿ’พ Loading stores"); // preload await Promise.all([ userStore.load(), @@ -89,6 +93,7 @@ app.on("ready", async () => { // find free port try { + logger.info("๐Ÿ”‘ Getting free port for LensProxy server"); proxyPort = await getFreePort(); } catch (error) { logger.error(error); @@ -101,6 +106,7 @@ app.on("ready", async () => { // run proxy try { + logger.info("๐Ÿ”Œ Starting LensProxy"); // eslint-disable-next-line unused-imports/no-unused-vars-ts proxyServer = LensProxy.create(proxyPort, clusterManager); } catch (error) { @@ -109,10 +115,27 @@ app.on("ready", async () => { app.exit(); } + // test proxy connection + try { + logger.info("๐Ÿ”Ž Testing LensProxy connection ..."); + const versionFromProxy = await getAppVersionFromProxyServer(proxyPort); + + if (getAppVersion() !== versionFromProxy) { + logger.error(`Proxy server responded with invalid response`); + } + logger.info("โšก LensProxy connection OK"); + } catch (error) { + logger.error("Checking proxy server connection failed", error); + } + extensionLoader.init(); extensionDiscovery.init(); + + logger.info("๐Ÿ–ฅ๏ธ Starting WindowManager"); windowManager = WindowManager.getInstance(proxyPort); + logger.info("๐Ÿงฉ Initializing extensions"); + // call after windowManager to see splash earlier try { const extensions = await extensionDiscovery.load(); diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index e4f6ab4a34..c58f3eb2e4 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -29,7 +29,7 @@ export class LensProxy { listen(port = this.port): this { this.proxyServer = this.buildCustomProxy().listen(port); - logger.info(`LensProxy server has started at ${this.origin}`); + logger.info(`[LENS-PROXY]: Proxy server has started at ${this.origin}`); return this; } diff --git a/src/main/router.ts b/src/main/router.ts index 6e98d0ce0c..875bd319b5 100644 --- a/src/main/router.ts +++ b/src/main/router.ts @@ -5,7 +5,7 @@ import path from "path"; import { readFile } from "fs-extra"; import { Cluster } from "./cluster"; import { apiPrefix, appName, publicPath, isDevelopment, webpackDevServerPort } from "../common/vars"; -import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute } from "./routes"; +import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute, versionRoute } from "./routes"; import logger from "./logger"; export interface RouterRequestOpts { @@ -143,6 +143,7 @@ export class Router { this.handleStaticFile(params.path, response, req); }); + this.router.add({ method: "get", path: "/version"}, versionRoute.getVersion.bind(versionRoute)); this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute)); // Watch API diff --git a/src/main/routes/index.ts b/src/main/routes/index.ts index 5bc5b3f3dd..c2fd222631 100644 --- a/src/main/routes/index.ts +++ b/src/main/routes/index.ts @@ -4,3 +4,4 @@ export * from "./port-forward-route"; export * from "./watch-route"; export * from "./helm-route"; export * from "./resource-applier-route"; +export * from "./version-route"; diff --git a/src/main/routes/version-route.ts b/src/main/routes/version-route.ts new file mode 100644 index 0000000000..81ada9eca7 --- /dev/null +++ b/src/main/routes/version-route.ts @@ -0,0 +1,13 @@ +import { LensApiRequest } from "../router"; +import { LensApi } from "../lens-api"; +import { getAppVersion } from "../../common/utils"; + +class VersionRoute extends LensApi { + public async getVersion(request: LensApiRequest) { + const { response } = request; + + this.respondJson(response, { version: getAppVersion()}, 200); + } +} + +export const versionRoute = new VersionRoute(); diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index bf7458afa0..691aa7c66b 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -8,6 +8,7 @@ import { initMenu } from "./menu"; import { initTray } from "./tray"; import { Singleton } from "../common/utils"; import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames"; +import logger from "./logger"; export class WindowManager extends Singleton { protected mainWindow: BrowserWindow; @@ -81,10 +82,19 @@ export class WindowManager extends Singleton { this.splashWindow = null; app.dock?.hide(); // hide icon in dock (mac-os) }); + + this.mainWindow.webContents.on("did-fail-load", (_event, code, desc) => { + logger.error(`[WINDOW-MANAGER]:ย Failed to load Main window`, { code, desc }); + }); + + this.mainWindow.webContents.on("did-finish-load", () => { + logger.info("[WINDOW-MANAGER]: Main window loaded"); + }); } try { if (showSplash) await this.showSplash(); + logger.info(`[WINDOW-MANAGER]:ย Loading Main window from url: ${this.mainUrl} ...`); await this.mainWindow.loadURL(this.mainUrl); this.mainWindow.show(); this.splashWindow?.close();