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

Improve logging from getPortFromStream

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-07-18 16:25:25 -04:00
parent 6615d1bab8
commit d17319bf85
3 changed files with 11 additions and 4 deletions

View File

@ -16,7 +16,10 @@ import { TypedRegEx } from "typed-regex";
import type { Spawn } from "../child-process/spawn.injectable";
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 {
readonly proxyBinPath: string;

View File

@ -9,7 +9,10 @@ import { spawn } from "child_process";
import * as tcpPortUsed from "tcp-port-used";
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 {
clusterId: string;

View File

@ -20,6 +20,7 @@ interface GetPortArgs {
};
raw?: RegExpExecArray;
};
rawMatcher: string;
};
/**
* Called when the port is found
@ -27,7 +28,7 @@ interface GetPortArgs {
onFind?: () => void;
/**
* Timeout for how long to wait for the port.
* Default: 5s
* Default: 15s
*/
timeout?: number;
}
@ -61,7 +62,7 @@ export function getPortFrom(stream: Readable, args: GetPortArgs): Promise<number
};
const timeoutID = setTimeout(() => {
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"));
}, args.timeout ?? 15000);