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

chore!: Switch to using specific log functions in KubeApi dependencies

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-05-26 11:53:29 -04:00
parent eee567b7f2
commit 0dd833c00b

View File

@ -33,7 +33,7 @@ import type { RequestInit, Response } from "@k8slens/node-fetch";
import type { Patch } from "rfc6902"; import type { Patch } from "rfc6902";
import assert from "assert"; import assert from "assert";
import type { PartialDeep } from "type-fest"; import type { PartialDeep } from "type-fest";
import type { Logger } from "@k8slens/logger"; import type { LogFunction } from "@k8slens/logger";
import { matches } from "lodash/fp"; import { matches } from "lodash/fp";
import { makeObservable, observable } from "mobx"; import { makeObservable, observable } from "mobx";
import type { ScaleCreateOptions } from "@k8slens/kube-object/src/types/scale"; import type { ScaleCreateOptions } from "@k8slens/kube-object/src/types/scale";
@ -273,7 +273,9 @@ export interface DeleteResourceDescriptor extends ResourceDescriptor {
} }
export interface KubeApiDependencies { export interface KubeApiDependencies {
readonly logger: Logger; logInfo: LogFunction;
logWarn: LogFunction;
logError: LogFunction;
readonly maybeKubeApi: KubeJsonApi | undefined; readonly maybeKubeApi: KubeJsonApi | undefined;
} }
@ -756,7 +758,7 @@ export class KubeApi<
const watchUrl = this.getWatchUrl(namespace); const watchUrl = this.getWatchUrl(namespace);
abortController.signal.addEventListener("abort", () => { abortController.signal.addEventListener("abort", () => {
this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) aborted ${watchUrl}`); this.dependencies.logInfo(`watch (${watchId}) aborted ${watchUrl}`);
clearTimeout(timedRetry); clearTimeout(timedRetry);
}); });
@ -765,9 +767,7 @@ export class KubeApi<
signal: abortController.signal, signal: abortController.signal,
}); });
this.dependencies.logger.info( this.dependencies.logInfo(`watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);
`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`,
);
responsePromise responsePromise
.then((response) => { .then((response) => {
@ -775,7 +775,7 @@ export class KubeApi<
let requestRetried = false; let requestRetried = false;
if (!response.ok) { if (!response.ok) {
this.dependencies.logger.warn(`[KUBE-API] watch (${watchId}) error response ${watchUrl}`, { this.dependencies.logWarn(`watch (${watchId}) error response ${watchUrl}`, {
status: response.status, status: response.status,
}); });
@ -794,7 +794,7 @@ export class KubeApi<
// Close current request // Close current request
abortController.abort(); abortController.abort();
this.dependencies.logger.info(`[KUBE-API] Watch timeout set, but not retried, retrying now`); this.dependencies.logInfo(`Watch timeout set, but not retried, retrying now`);
requestRetried = true; requestRetried = true;
@ -807,7 +807,7 @@ export class KubeApi<
if (!response.body || !response.body.readable) { if (!response.body || !response.body.readable) {
if (!response.body) { if (!response.body) {
this.dependencies.logger.warn(`[KUBE-API]: watch (${watchId}) did not return a body`); this.dependencies.logWarn(`watch (${watchId}) did not return a body`);
} }
requestRetried = true; requestRetried = true;
@ -829,7 +829,7 @@ export class KubeApi<
return; return;
} }
this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) ${eventName} ${watchUrl}`); this.dependencies.logInfo(`watch (${watchId}) ${eventName} ${watchUrl}`);
requestRetried = true; requestRetried = true;
@ -860,7 +860,7 @@ export class KubeApi<
}) })
.catch((error: unknown) => { .catch((error: unknown) => {
if (!abortController.signal.aborted) { if (!abortController.signal.aborted) {
this.dependencies.logger.error(`[KUBE-API] watch (${watchId}) threw ${watchUrl}`, error); this.dependencies.logError(`watch (${watchId}) threw ${watchUrl}`, error);
} }
callback(null, error as Record<string, unknown>); callback(null, error as Record<string, unknown>);
}); });