logs: use context logger in client drivers

This commit is contained in:
Danil Uzlov 2025-03-24 21:42:05 +00:00
parent 2e29580a64
commit f897bf6133
1 changed files with 29 additions and 29 deletions

View File

@ -156,9 +156,9 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
return access_modes; return access_modes;
} }
assertCapabilities(capabilities) { assertCapabilities(capabilities, callContext) {
const driver = this; const driver = this;
this.ctx.logger.verbose("validating capabilities: %j", capabilities); callContext.logger.verbose("validating capabilities: %j", capabilities);
let message = null; let message = null;
let fs_types = driver.getFsTypes(); let fs_types = driver.getFsTypes();
@ -548,7 +548,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async CreateVolume(call) { async CreateVolume(call, callContext) {
const driver = this; const driver = this;
const config_key = driver.getConfigKey(); const config_key = driver.getConfigKey();
@ -560,7 +560,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
call.request.volume_capabilities && call.request.volume_capabilities &&
call.request.volume_capabilities.length > 0 call.request.volume_capabilities.length > 0
) { ) {
const result = this.assertCapabilities(call.request.volume_capabilities); const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) { if (result.valid !== true) {
throw new GrpcError(grpc.status.INVALID_ARGUMENT, result.message); throw new GrpcError(grpc.status.INVALID_ARGUMENT, result.message);
} }
@ -661,7 +661,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
driver.ctx.logger.debug( callContext.logger.debug(
"controller volume source path: %s", "controller volume source path: %s",
source_path source_path
); );
@ -740,7 +740,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
break; break;
// must be available when adverstising CLONE_VOLUME // must be available when advertising CLONE_VOLUME
// create snapshot first, then clone // create snapshot first, then clone
case "volume": case "volume":
source_path = driver.getControllerVolumePath( source_path = driver.getControllerVolumePath(
@ -754,7 +754,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
driver.ctx.logger.debug( callContext.logger.debug(
"controller volume source path: %s", "controller volume source path: %s",
source_path source_path
); );
@ -770,7 +770,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
// set mode // set mode
if (this.options[config_key].dirPermissionsMode) { if (this.options[config_key].dirPermissionsMode) {
driver.ctx.logger.verbose( callContext.logger.verbose(
"setting dir mode to: %s on dir: %s", "setting dir mode to: %s on dir: %s",
this.options[config_key].dirPermissionsMode, this.options[config_key].dirPermissionsMode,
volume_path volume_path
@ -783,14 +783,14 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
this.options[config_key].dirPermissionsUser || this.options[config_key].dirPermissionsUser ||
this.options[config_key].dirPermissionsGroup this.options[config_key].dirPermissionsGroup
) { ) {
driver.ctx.logger.verbose( callContext.logger.verbose(
"setting ownership to: %s:%s on dir: %s", "setting ownership to: %s:%s on dir: %s",
this.options[config_key].dirPermissionsUser, this.options[config_key].dirPermissionsUser,
this.options[config_key].dirPermissionsGroup, this.options[config_key].dirPermissionsGroup,
volume_path volume_path
); );
if (this.getNodeIsWindows()) { if (this.getNodeIsWindows()) {
driver.ctx.logger.warn("chown not implemented on windows"); callContext.logger.warn("chown not implemented on windows");
} else { } else {
await driver.exec("chown", [ await driver.exec("chown", [
(this.options[config_key].dirPermissionsUser (this.options[config_key].dirPermissionsUser
@ -840,7 +840,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async DeleteVolume(call) { async DeleteVolume(call, callContext) {
const driver = this; const driver = this;
const volume_id = call.request.volume_id; const volume_id = call.request.volume_id;
@ -873,7 +873,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async ControllerExpandVolume(call) { async ControllerExpandVolume(call, callContext) {
throw new GrpcError( throw new GrpcError(
grpc.status.UNIMPLEMENTED, grpc.status.UNIMPLEMENTED,
`operation not supported by driver` `operation not supported by driver`
@ -885,7 +885,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async GetCapacity(call) { async GetCapacity(call, callContext) {
const driver = this; const driver = this;
if ( if (
@ -902,7 +902,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
} }
if (call.request.volume_capabilities) { if (call.request.volume_capabilities) {
const result = this.assertCapabilities(call.request.volume_capabilities); const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) { if (result.valid !== true) {
return { available_capacity: 0 }; return { available_capacity: 0 };
@ -925,7 +925,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async ListVolumes(call) { async ListVolumes(call, callContext) {
throw new GrpcError( throw new GrpcError(
grpc.status.UNIMPLEMENTED, grpc.status.UNIMPLEMENTED,
`operation not supported by driver` `operation not supported by driver`
@ -936,7 +936,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async ListSnapshots(call) { async ListSnapshots(call, callContext) {
throw new GrpcError( throw new GrpcError(
grpc.status.UNIMPLEMENTED, grpc.status.UNIMPLEMENTED,
`operation not supported by driver` `operation not supported by driver`
@ -963,7 +963,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async CreateSnapshot(call) { async CreateSnapshot(call, callContext) {
const driver = this; const driver = this;
const config_key = driver.getConfigKey(); const config_key = driver.getConfigKey();
@ -1003,7 +1003,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
driver.ctx.logger.verbose("requested snapshot name: %s", name); callContext.logger.verbose("requested snapshot name: %s", name);
let invalid_chars; let invalid_chars;
invalid_chars = name.match(/[^a-z0-9_\-:.+]+/gi); invalid_chars = name.match(/[^a-z0-9_\-:.+]+/gi);
@ -1020,7 +1020,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
// https://stackoverflow.com/questions/32106243/regex-to-remove-all-non-alpha-numeric-and-replace-spaces-with/32106277 // https://stackoverflow.com/questions/32106243/regex-to-remove-all-non-alpha-numeric-and-replace-spaces-with/32106277
name = name.replace(/[^a-z0-9_\-:.+]+/gi, ""); name = name.replace(/[^a-z0-9_\-:.+]+/gi, "");
driver.ctx.logger.verbose("cleansed snapshot name: %s", name); callContext.logger.verbose("cleansed snapshot name: %s", name);
const volume_path = driver.getControllerVolumePath(source_volume_id); const volume_path = driver.getControllerVolumePath(source_volume_id);
//const volume_path = "/home/thansen/beets/"; //const volume_path = "/home/thansen/beets/";
//const volume_path = "/var/lib/docker/"; //const volume_path = "/var/lib/docker/";
@ -1044,11 +1044,11 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
await driver.cloneDir(volume_path, snapshot_path).finally(() => { await driver.cloneDir(volume_path, snapshot_path).finally(() => {
SNAPSHOTS_CUT_IN_FLIGHT.delete(name); SNAPSHOTS_CUT_IN_FLIGHT.delete(name);
}); });
driver.ctx.logger.info( callContext.logger.info(
`filecopy backup finished: snapshot_id=${snapshot_id}, path=${volume_path}` `filecopy backup finished: snapshot_id=${snapshot_id}, path=${volume_path}`
); );
} else { } else {
driver.ctx.logger.debug( callContext.logger.debug(
`filecopy backup already cut: ${snapshot_id}` `filecopy backup already cut: ${snapshot_id}`
); );
} }
@ -1099,7 +1099,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
if (response.length > 0) { if (response.length > 0) {
snapshot_exists = true; snapshot_exists = true;
const snapshot = response[response.length - 1]; const snapshot = response[response.length - 1];
driver.ctx.logger.debug( callContext.logger.debug(
`restic backup already cut: ${snapshot.id}` `restic backup already cut: ${snapshot.id}`
); );
const stats = await restic.stats([snapshot.id]); const stats = await restic.stats([snapshot.id]);
@ -1136,7 +1136,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
return message.message_type == "summary"; return message.message_type == "summary";
}); });
snapshot_id = summary.snapshot_id; snapshot_id = summary.snapshot_id;
driver.ctx.logger.info( callContext.logger.info(
`restic backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${ `restic backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${
summary.total_duration | 0 summary.total_duration | 0
}s` }s`
@ -1194,7 +1194,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
snapshot_id = snapshot.id; snapshot_id = snapshot.id;
driver.ctx.logger.info( callContext.logger.info(
`restic backup successfully applied additional tags: new_snapshot_id=${snapshot_id}, original_snapshot_id=${original_snapshot_id} path=${volume_path}` `restic backup successfully applied additional tags: new_snapshot_id=${snapshot_id}, original_snapshot_id=${original_snapshot_id} path=${volume_path}`
); );
} }
@ -1233,7 +1233,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
if (response.length > 0) { if (response.length > 0) {
snapshot_exists = true; snapshot_exists = true;
const snapshot = response[response.length - 1]; const snapshot = response[response.length - 1];
driver.ctx.logger.debug( callContext.logger.debug(
`kopia snapshot already cut: ${snapshot.id}` `kopia snapshot already cut: ${snapshot.id}`
); );
@ -1262,7 +1262,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
1000; 1000;
size_bytes = response.rootEntry.summ.size; size_bytes = response.rootEntry.summ.size;
driver.ctx.logger.info( callContext.logger.info(
`kopia backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${ `kopia backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${
total_duration | 0 total_duration | 0
}s` }s`
@ -1305,7 +1305,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async DeleteSnapshot(call) { async DeleteSnapshot(call, callContext) {
const driver = this; const driver = this;
let snapshot_id = call.request.snapshot_id; let snapshot_id = call.request.snapshot_id;
@ -1393,7 +1393,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
* *
* @param {*} call * @param {*} call
*/ */
async ValidateVolumeCapabilities(call) { async ValidateVolumeCapabilities(call, callContext) {
const driver = this; const driver = this;
const volume_id = call.request.volume_id; const volume_id = call.request.volume_id;
@ -1414,7 +1414,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
); );
} }
const result = this.assertCapabilities(call.request.volume_capabilities); const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) { if (result.valid !== true) {
return { message: result.message }; return { message: result.message };