Skip to content

Commit

Permalink
Merge pull request #681 from snyk/fix/add-preflight-check-human-outpu…
Browse files Browse the repository at this point in the history
…t-in-logs

fix: add more readable preflight check summary
  • Loading branch information
aarlaud authored Dec 13, 2023
2 parents a08439d + ca1248e commit 970248f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/client/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getConfigChecks } from './config';
import { getHttpChecks } from './http';
import type { Config } from '../types/config';
import type { Check, CheckResult } from './types';
import { splitStringIntoLines } from './utils';

export function preflightChecksEnabled(config: any): boolean {
// preflight checks are enabled per default
Expand Down Expand Up @@ -56,18 +57,40 @@ export async function executePreflightChecks(
}

const logPreflightCheckResults = (results: CheckResult[]) => {
console.log('\n\n');
console.log('##############################################################');
console.log('### PREFLIGHT CHECKS RESULTS');
console.log('### PREFLIGHT CHECKS RESULTS - NON BLOCKING');
console.log('###');
console.log('### Preflight checks help to catch errors early, upon broker');
console.log('### client startup. Note, that broker client will start');
console.log('### whether the checks were successful or not.');
console.log('###');
console.log('### See more: https://github.com/snyk/broker#preflight-checks');
// console.log('### See more: https://github.com/snyk/broker#preflight-checks');
console.log('##############################################################');

console.log('\n');
const nonPassingChecksDetails: string[] = [
`#############################################################################################
### PREFLIGHT CHECKS DETAILS
###
### Review troubleshooting steps at https://github.com/snyk/broker#preflight-checks
###`,
];
const checks = results.map((check) => {
if (check.status != 'passing') {
nonPassingChecksDetails.push(`
### [${check.name}] ${check.status}.
### Preflight Check output:
### ${splitStringIntoLines(check.output, 88, '### ')}
###`);
}
return { id: check.id, status: check.status };
});
nonPassingChecksDetails.push(
'#############################################################################################',
);
console.log('### Preflight checks summary');
console.table(checks);
console.log('\n');
console.log(nonPassingChecksDetails.join('\n###'));
console.log('\n\n');
};
9 changes: 9 additions & 0 deletions lib/client/checks/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const splitStringIntoLines = (
inputString,
lineLength,
linePrefix = '',
) => {
const regex = new RegExp(`.{1,${lineLength}}`, 'g');
const lines = inputString.match(regex);
return lines.join(`\n${linePrefix}`);
};

0 comments on commit 970248f

Please sign in to comment.