kibana/x-pack/plugins/security_solution/scripts/endpoint/common/utils.ts
Konrad Szwarc 96bf7b1f06
[MKI][EDR Workflows] Enable MKI on EDR Workflows Cypress tests (#181080)
This PR sets up everything required for running Cypress tests for EDR
Workflows on the MKI QA environment.

MKI pipeline triggered with these changes -
https://buildkite.com/elastic/kibana-serverless-security-solution-quality-gate-defend-workflows/builds/20

---------

Co-authored-by: dkirchan <diamantis.kirchantzoglou@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Paul Tavares <paul.tavares@elastic.co>
Co-authored-by: dkirchan <55240027+dkirchan@users.noreply.github.com>
2024-04-26 14:10:36 +02:00

73 lines
2.2 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ToolingLog } from '@kbn/tooling-log';
import chalk from 'chalk';
import { inspect } from 'util';
/**
* Capture and return the calling stack for the context that called this utility.
*/
export const captureCallingStack = () => {
const s = { stack: '' };
Error.captureStackTrace(s);
return `Called from:\n${s.stack.split('\n').slice(3).join('\n')}`;
};
/**
* Returns a logger that intercepts calls to the ToolingLog instance methods passed in input
* and prefix it with the provided value. Useful in order to track log entries, especially when
* logging output from multiple sources is concurrently being output to the same source
* (ex. CI jobs and output to stdout).
*
* @param prefix
* @param log
*
* @example
* const logger = new ToolingLog();
* const prefixedLogger = prefixedOutputLogger('my_log', logger);
*
* prefixedLogger.info('log something'); // => info [my_log] log something
*/
export const prefixedOutputLogger = (prefix: string, log: ToolingLog): ToolingLog => {
const styledPrefix = `[${chalk.grey(prefix)}]`;
const logIt = (type: keyof ToolingLog, ...args: any) => {
return log[type](styledPrefix, ...args);
};
const logger: Partial<ToolingLog> = {
info: logIt.bind(null, 'info'),
debug: logIt.bind(null, 'debug'),
verbose: logIt.bind(null, 'verbose'),
success: logIt.bind(null, 'success'),
warning: logIt.bind(null, 'warning'),
write: logIt.bind(null, 'write'),
};
const proxy = new Proxy(log, {
get(target: ToolingLog, prop: keyof ToolingLog, receiver: any): any {
if (prop in logger) {
return logger[prop];
}
return log[prop];
},
});
return proxy;
};
/**
* Safely traverse some content (object, array, etc) and stringify it
* @param content
* @param depth
*/
export const dump = (content: any, depth: number = 5): string => {
return inspect(content, { depth });
};