Skip to content

Commit

Permalink
chore!: Switch to using specific log functions in KubeApi dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Jun 1, 2023
1 parent eee567b commit 0dd833c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/utility-features/kube-api/src/kube-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
});

Expand All @@ -765,17 +767,15 @@ 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) => {
// True if the current watch request was retried
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,
});

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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>);
});
Expand Down

0 comments on commit 0dd833c

Please sign in to comment.