mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Detect log follow requests (#3890)
* detect log follow requests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor to use getBoolean Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor to use getBoolean Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor to use getBoolean Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
2c3d89556c
commit
642c6f0d72
@ -18,4 +18,39 @@
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
export * from "./parse-query";
|
||||
|
||||
import { isLongRunningRequest } from "../lens-proxy";
|
||||
|
||||
describe("isLongRunningRequest", () => {
|
||||
it("returns true on watches", () => {
|
||||
["watch=true", "watch=1", "watch"].forEach((param) => {
|
||||
expect(
|
||||
isLongRunningRequest(`/api/v1/namespaces/default/pods?${param}`)
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false on disabled watches", () => {
|
||||
["watch=false", "watch=0", ""].forEach((param) => {
|
||||
expect(
|
||||
isLongRunningRequest(`/api/v1/namespaces/default/pods?${param}`)
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it("returns true on follows", () => {
|
||||
["follow=true", "follow=1", "follow"].forEach((param) => {
|
||||
expect(
|
||||
isLongRunningRequest(`/api/v1/namespaces/default/pods/foo/log?${param}`)
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false on disabled follows", () => {
|
||||
["follow=false", "follow=0", ""].forEach((param) => {
|
||||
expect(
|
||||
isLongRunningRequest(`/api/v1/namespaces/default/pods/foo/log?${param}`)
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -117,10 +117,10 @@ export class ContextHandler {
|
||||
return `http://127.0.0.1:${this.kubeAuthProxy.port}${path}`;
|
||||
}
|
||||
|
||||
async getApiTarget(isWatchRequest = false): Promise<httpProxy.ServerOptions> {
|
||||
const timeout = isWatchRequest ? 4 * 60 * 60 * 1000 : 30000; // 4 hours for watch request, 30 seconds for the rest
|
||||
async getApiTarget(isLongRunningRequest = false): Promise<httpProxy.ServerOptions> {
|
||||
const timeout = isLongRunningRequest ? 4 * 60 * 60_000 : 30_000; // 4 hours for long running request, 30 seconds for the rest
|
||||
|
||||
if (isWatchRequest) {
|
||||
if (isLongRunningRequest) {
|
||||
return this.newApiTarget(timeout);
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ import { Singleton } from "../common/utils";
|
||||
import type { Cluster } from "./cluster";
|
||||
import type { ProxyApiRequestArgs } from "./proxy-functions";
|
||||
import { appEventBus } from "../common/event-bus";
|
||||
import { getBoolean } from "./utils/parse-query";
|
||||
|
||||
type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null;
|
||||
|
||||
@ -40,6 +41,15 @@ export interface LensProxyFunctions {
|
||||
kubeApiRequest: (args: ProxyApiRequestArgs) => void | Promise<void>;
|
||||
}
|
||||
|
||||
const watchParam = "watch";
|
||||
const followParam = "follow";
|
||||
|
||||
export function isLongRunningRequest(reqUrl: string) {
|
||||
const url = new URL(reqUrl, "http://localhost");
|
||||
|
||||
return getBoolean(url.searchParams, watchParam) || getBoolean(url.searchParams, followParam);
|
||||
}
|
||||
|
||||
export class LensProxy extends Singleton {
|
||||
protected origin: string;
|
||||
protected proxyServer: http.Server;
|
||||
@ -174,9 +184,8 @@ export class LensProxy extends Singleton {
|
||||
if (req.url.startsWith(apiKubePrefix)) {
|
||||
delete req.headers.authorization;
|
||||
req.url = req.url.replace(apiKubePrefix, "");
|
||||
const isWatchRequest = req.url.includes("watch=");
|
||||
|
||||
return contextHandler.getApiTarget(isWatchRequest);
|
||||
return contextHandler.getApiTarget(isLongRunningRequest(req.url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ import type { LensApiRequest } from "../router";
|
||||
import { helmService } from "../helm/helm-service";
|
||||
import logger from "../logger";
|
||||
import { respondJson, respondText } from "../utils/http-responses";
|
||||
import { getBoolean } from "./utils/parse-query";
|
||||
import { getBoolean } from "../utils/parse-query";
|
||||
|
||||
export class HelmApiRoute {
|
||||
static async listCharts(request: LensApiRequest) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user