1
0
mirror of https://github.com/lensapp/lens.git synced 2024-08-16 04:40:24 +03: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 assert from "assert";
import type { PartialDeep } from "type-fest";
import type { Logger } from "@k8slens/logger";
import type { LogFunction } from "@k8slens/logger";
import { matches } from "lodash/fp";
import { makeObservable, observable } from "mobx";
import type { ScaleCreateOptions } from "@k8slens/kube-object/src/types/scale";
@ -273,7 +273,9 @@ export interface DeleteResourceDescriptor extends ResourceDescriptor {
}
export interface KubeApiDependencies {
readonly logger: Logger;
logInfo: LogFunction;
logWarn: LogFunction;
logError: LogFunction;
readonly maybeKubeApi: KubeJsonApi | undefined;
}
@ -756,7 +758,7 @@ export class KubeApi<
const watchUrl = this.getWatchUrl(namespace);
abortController.signal.addEventListener("abort", () => {
this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) aborted ${watchUrl}`);
this.dependencies.logInfo(`watch (${watchId}) aborted ${watchUrl}`);
clearTimeout(timedRetry);
});
@ -765,9 +767,7 @@ export class KubeApi<
signal: abortController.signal,
});
this.dependencies.logger.info(
`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`,
);
this.dependencies.logInfo(`watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);
responsePromise
.then((response) => {
@ -775,7 +775,7 @@ export class KubeApi<
let requestRetried = false;
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,
});
@ -794,7 +794,7 @@ export class KubeApi<
// Close current request
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;
@ -807,7 +807,7 @@ export class KubeApi<
if (!response.body || !response.body.readable) {
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;
@ -829,7 +829,7 @@ export class KubeApi<
return;
}
this.dependencies.logger.info(`[KUBE-API] watch (${watchId}) ${eventName} ${watchUrl}`);
this.dependencies.logInfo(`watch (${watchId}) ${eventName} ${watchUrl}`);
requestRetried = true;
@ -860,7 +860,7 @@ export class KubeApi<
})
.catch((error: unknown) => {
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>);
});