Skip to content

Commit

Permalink
feat(dashmate): compress doctor report and other improvements (#2071)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Shumkov <[email protected]>
  • Loading branch information
pshenmic and shumkov authored Aug 24, 2024
1 parent e6c5bdc commit d48b399
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
1 change: 0 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 3 additions & 20 deletions packages/dashmate/src/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -113,7 +112,7 @@ export default class DoctorCommand extends ConfigBaseCommand {

const coreCalls = [
rpcClient.getBestChainLock(),
rpcClient.quorum('list'),
rpcClient.quorum('listextended'),
rpcClient.getBlockchainInfo(),
rpcClient.getPeerInfo(),
];
Expand All @@ -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);
Expand All @@ -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'),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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,
Expand Down
9 changes: 2 additions & 7 deletions packages/dashmate/src/config/obfuscateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions packages/dashmate/src/doctor/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
},
['.'],
);
Expand Down

0 comments on commit d48b399

Please sign in to comment.