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

Add guards to prevent activation errors slipping through (#5845)

* Add guards to prevent activation errors slipping through

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Make sure all logging has a message, output less errors when prometheus fails

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Improve logging from getPortFromStream

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-07-18 23:05:41 -07:00 committed by GitHub
parent 0d2aea0101
commit 81c18a6cad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 17 deletions

View File

@ -340,15 +340,35 @@ export class Cluster implements ClusterModel, ClusterState {
} }
if (this.disconnected || !this.accessible) { if (this.disconnected || !this.accessible) {
await this.reconnect(); try {
this.broadcastConnectUpdate("Starting connection ...");
await this.reconnect();
} catch (error) {
this.broadcastConnectUpdate(`Failed to start connection: ${error}`, true);
return;
}
} }
this.broadcastConnectUpdate("Refreshing connection status ..."); try {
await this.refreshConnectionStatus(); this.broadcastConnectUpdate("Refreshing connection status ...");
await this.refreshConnectionStatus();
} catch (error) {
this.broadcastConnectUpdate(`Failed to connection status: ${error}`, true);
return;
}
if (this.accessible) { if (this.accessible) {
this.broadcastConnectUpdate("Refreshing cluster accessibility ..."); try {
await this.refreshAccessibility(); this.broadcastConnectUpdate("Refreshing cluster accessibility ...");
await this.refreshAccessibility();
} catch (error) {
this.broadcastConnectUpdate(`Failed to refresh accessibility: ${error}`, true);
return;
}
// download kubectl in background, so it's not blocking dashboard // download kubectl in background, so it's not blocking dashboard
this.ensureKubectl() this.ensureKubectl()
.catch(error => this.dependencies.logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error)); .catch(error => this.dependencies.logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error));

View File

@ -78,4 +78,4 @@ export default winston.createLogger({
format.simple(), format.simple(),
), ),
transports, transports,
}); }) as Logger;

View File

@ -16,7 +16,10 @@ import { TypedRegEx } from "typed-regex";
import type { Spawn } from "../child-process/spawn.injectable"; import type { Spawn } from "../child-process/spawn.injectable";
import type { Logger } from "../../common/logger"; import type { Logger } from "../../common/logger";
const startingServeRegex = TypedRegEx("starting to serve on (?<address>.+)", "i"); const startingServeMatcher = "starting to serve on (?<address>.+)";
const startingServeRegex = Object.assign(TypedRegEx(startingServeMatcher, "i"), {
rawMatcher: startingServeMatcher,
});
export interface KubeAuthProxyDependencies { export interface KubeAuthProxyDependencies {
readonly proxyBinPath: string; readonly proxyBinPath: string;

View File

@ -132,8 +132,7 @@ export class Kubectl {
return this.path; return this.path;
} catch (err) { } catch (err) {
logger.error("Failed to ensure kubectl, fallback to the bundled version"); logger.error("Failed to ensure kubectl, fallback to the bundled version", err);
logger.error(err);
return this.getBundledPath(); return this.getBundledPath();
} }
@ -146,7 +145,7 @@ export class Kubectl {
return this.dirname; return this.dirname;
} catch (err) { } catch (err) {
logger.error(err); logger.error("Failed to get biniary directory", err);
return ""; return "";
} }

View File

@ -31,11 +31,11 @@ const loadMetricsFor = (getMetrics: GetMetrics) => async (promQueries: string[],
} catch (error) { } catch (error) {
if (isRequestError(error)) { if (isRequestError(error)) {
if (lastAttempt || (error.statusCode && error.statusCode >= 400 && error.statusCode < 500)) { if (lastAttempt || (error.statusCode && error.statusCode >= 400 && error.statusCode < 500)) {
logger.error("[Metrics]: metrics not available", error?.response ? error.response?.body : error); throw new Error("Metrics not available", { cause: error });
throw new Error("Metrics not available");
} }
} else if (error instanceof Error) {
throw new Error("Metrics not available", { cause: error });
} else { } else {
logger.error("[Metrics]: metrics not available", error);
throw new Error("Metrics not available"); throw new Error("Metrics not available");
} }

View File

@ -9,7 +9,10 @@ import { spawn } from "child_process";
import * as tcpPortUsed from "tcp-port-used"; import * as tcpPortUsed from "tcp-port-used";
import { TypedRegEx } from "typed-regex"; import { TypedRegEx } from "typed-regex";
const internalPortRegex = TypedRegEx("^forwarding from (?<address>.+) ->", "i"); const internalPortMatcher = "^forwarding from (?<address>.+) ->";
const internalPortRegex = Object.assign(TypedRegEx(internalPortMatcher, "i"), {
rawMatcher: internalPortMatcher,
});
export interface PortForwardArgs { export interface PortForwardArgs {
clusterId: string; clusterId: string;

View File

@ -20,6 +20,7 @@ interface GetPortArgs {
}; };
raw?: RegExpExecArray; raw?: RegExpExecArray;
}; };
rawMatcher: string;
}; };
/** /**
* Called when the port is found * Called when the port is found
@ -27,7 +28,7 @@ interface GetPortArgs {
onFind?: () => void; onFind?: () => void;
/** /**
* Timeout for how long to wait for the port. * Timeout for how long to wait for the port.
* Default: 5s * Default: 15s
*/ */
timeout?: number; timeout?: number;
} }
@ -61,7 +62,7 @@ export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number
}; };
const timeoutID = setTimeout(() => { const timeoutID = setTimeout(() => {
stream.off("data", handler); stream.off("data", handler);
logger.warn(`[getPortFrom]: failed to retrieve port via ${args.lineRegex.toString()}: ${logLines}`); logger.warn(`[getPortFrom]: failed to retrieve port via ${args.lineRegex.rawMatcher}`, logLines);
reject(new Error("failed to retrieve port from stream")); reject(new Error("failed to retrieve port from stream"));
}, args.timeout ?? 15000); }, args.timeout ?? 15000);

View File

@ -121,7 +121,7 @@ export class ThemeStore {
try { try {
this.applyActiveTheme(); this.applyActiveTheme();
} catch (err) { } catch (err) {
logger.error(err); logger.error(`Failed to apply active theme: ${err}`);
this.dependencies.userStore.resetTheme(); this.dependencies.userStore.resetTheme();
} }
}, { }, {