From d48b399150f3b01924def06cc3f90329f612c7be Mon Sep 17 00:00:00 2001 From: pshenmic Date: Sat, 24 Aug 2024 15:41:54 +0700 Subject: [PATCH] feat(dashmate): compress doctor report and other improvements (#2071) Co-authored-by: Ivan Shumkov --- .yarnrc.yml | 1 - packages/dashmate/src/commands/doctor.js | 23 +++---------------- .../dashmate/src/config/obfuscateConfig.js | 9 ++------ packages/dashmate/src/doctor/report.js | 4 ++-- 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index 5023b0d81db..34231a77e3b 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -14,7 +14,6 @@ npmAuditExcludePackages: - "@grpc/grpc-js" # TODO: Remove when gRPC stack is updated - "@humanwhocodes/config-array" # TODO: Update eslint - "@humanwhocodes/object-schema" # TODO: Update eslint - - elliptic # TODO: Update elliptic when fix for 1098397 is released - micromatch # TODO: remove when new micromatch will be released https://github.com/advisories/GHSA-952p-6rrq-rcjv packageExtensions: diff --git a/packages/dashmate/src/commands/doctor.js b/packages/dashmate/src/commands/doctor.js index 49bbdf19607..c66e18c754d 100644 --- a/packages/dashmate/src/commands/doctor.js +++ b/packages/dashmate/src/commands/doctor.js @@ -103,7 +103,6 @@ export default class DoctorCommand extends ConfigBaseCommand { { title: 'Core status', task: async (ctx) => { - const externalIp = config.get('externalIp'); const rpcClient = createRpcClient({ port: config.get('core.rpc.port'), user: 'dashmate', @@ -113,7 +112,7 @@ export default class DoctorCommand extends ConfigBaseCommand { const coreCalls = [ rpcClient.getBestChainLock(), - rpcClient.quorum('list'), + rpcClient.quorum('listextended'), rpcClient.getBlockchainInfo(), rpcClient.getPeerInfo(), ]; @@ -130,10 +129,6 @@ export default class DoctorCommand extends ConfigBaseCommand { masternodeStatus, ] = (await Promise.allSettled(coreCalls)).map((e) => e.value?.result || e.reason); - // remove external ip address from peers - obfuscateObjectRecursive(getPeerInfo, (field, value) => (typeof value === 'string' - ? value.replaceAll(externalIp, hideString(externalIp)) : value)); - ctx.report.setServiceInfo('core', 'bestChainLock', getBestChainLock); ctx.report.setServiceInfo('core', 'quorums', quorums); ctx.report.setServiceInfo('core', 'blockchainInfo', getBlockchainInfo); @@ -145,7 +140,6 @@ export default class DoctorCommand extends ConfigBaseCommand { title: 'Tenderdash status', enabled: () => config.get('platform.enable'), task: async (ctx) => { - const externalIp = config.get('externalIp'); const tenderdashRPCClient = createTenderdashRpcClient({ host: config.get('platform.drive.tenderdash.rpc.host'), port: config.get('platform.drive.tenderdash.rpc.port'), @@ -174,12 +168,6 @@ export default class DoctorCommand extends ConfigBaseCommand { fetchValidators(), ]); - // remove external ip address from status & peers - obfuscateObjectRecursive(status, (field, value) => (typeof value === 'string' - ? value.replaceAll(externalIp, hideString(externalIp)) : value)); - obfuscateObjectRecursive(peers, (field, value) => (typeof value === 'string' - ? value.replaceAll(externalIp, hideString(externalIp)) : value)); - ctx.report.setServiceInfo('drive_tenderdash', 'status', status); ctx.report.setServiceInfo('drive_tenderdash', 'validators', validators); ctx.report.setServiceInfo('drive_tenderdash', 'genesis', genesis); @@ -229,7 +217,6 @@ export default class DoctorCommand extends ConfigBaseCommand { { title: 'Logs', task: async (ctx, task) => { - const externalIp = config.get('externalIp'); const services = await getServiceList(config); // eslint-disable-next-line no-param-reassign @@ -244,15 +231,11 @@ export default class DoctorCommand extends ConfigBaseCommand { // Hide username & external ip from logs logs.out = logs.out.replaceAll(process.env.USER, hideString(process.env.USER)); - logs.out = logs.out.replaceAll(externalIp, hideString(externalIp)); logs.err = logs.err.replaceAll(process.env.USER, hideString(process.env.USER)); - logs.err = logs.err.replaceAll(externalIp, hideString(externalIp)); // Hide username & external ip from inspect - obfuscateObjectRecursive(inspect, (field, value) => (typeof value === 'string' + obfuscateObjectRecursive(inspect, (_field, value) => (typeof value === 'string' ? value.replaceAll(process.env.USER, hideString(process.env.USER)) : value)); - obfuscateObjectRecursive(inspect, (field, value) => (typeof value === 'string' - ? value.replaceAll(externalIp, hideString(externalIp)) : value)); ctx.report.setServiceInfo(service.name, 'stdOut', logs.out); ctx.report.setServiceInfo(service.name, 'stdErr', logs.err); @@ -269,7 +252,7 @@ export default class DoctorCommand extends ConfigBaseCommand { await ctx.report.archive(archivePath); // eslint-disable-next-line no-param-reassign - task.output = chalk`Saved to {bold.cyanBright ${archivePath}/dashmate-report-${ctx.report.date.toISOString()}.tar}`; + task.output = chalk`Saved to {bold.cyanBright ${archivePath}/dashmate-report-${ctx.report.date.toISOString()}.tar.gz}`; }, options: { persistentOutput: true, diff --git a/packages/dashmate/src/config/obfuscateConfig.js b/packages/dashmate/src/config/obfuscateConfig.js index b2ed2e9a4fd..1a9e8db0446 100644 --- a/packages/dashmate/src/config/obfuscateConfig.js +++ b/packages/dashmate/src/config/obfuscateConfig.js @@ -6,25 +6,20 @@ export default function obfuscateConfig( config, ) { const username = process.env.USER; - const externalIp = config.get('externalIp'); const cloned = lodash.cloneDeep(config); // sanitize [password, apiKey, privateKey, externalIp] fields in the dashmate config obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' && field === 'password' ? hideString(value) : value)); + obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' && field === 'key' ? hideString(value) : value)); obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' && field === 'apiKey' ? hideString(value) : value)); obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' && field === 'privateKey' ? hideString(value) : value)); - obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' && field === 'externalIp' ? hideString(value) : value)); // sanitize also usernames & external ip from the rest of the fields values - obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' ? value.replaceAll( + obfuscateObjectRecursive(cloned, (_field, value) => (typeof value === 'string' ? value.replaceAll( username, hideString(username), ) : value)); - obfuscateObjectRecursive(cloned, (field, value) => (typeof value === 'string' ? value.replaceAll( - externalIp, - hideString(externalIp), - ) : value)); return cloned; } diff --git a/packages/dashmate/src/doctor/report.js b/packages/dashmate/src/doctor/report.js index 45f9e61a64d..ea5618d42ef 100644 --- a/packages/dashmate/src/doctor/report.js +++ b/packages/dashmate/src/doctor/report.js @@ -82,8 +82,8 @@ export default class Report { await create( { cwd: reportDir, - gzip: false, - file: path.join(folderPath, `${reportName}.tar`), + gzip: true, + file: path.join(folderPath, `${reportName}.tar.gz`), }, ['.'], );