Skip to content

Commit d276374

Browse files
authored
feat: add --verbose flag to expose stateless installation steps of Dataform Core and identify bottlenecks (#2100)
* feat: add --verbose argument to expose steps in stateless installation * chore: make verbose and quiet flags mutually exclusive * feat: use performance timing in node to avoid system clock issues * chore: do not export print * refactor: remove redundant double check * chore: print should pipe to stderr
1 parent b06e7f1 commit d276374

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

cli/api/commands/compile.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { dataform } from "df/protos/ts";
1212

1313
export class CompilationTimeoutError extends Error {}
1414

15+
function print(text: string) {
16+
process.stderr.write(text);
17+
}
18+
1519
export async function compile(
1620
compileConfig: dataform.ICompileConfig = {}
1721
): Promise<dataform.CompiledGraph> {
@@ -41,8 +45,19 @@ export async function compile(
4145
}
4246
});
4347

48+
if (compileConfig.verbose) {
49+
print(`Using isolated environment for @dataform/core@${workflowSettingsDataformCoreVersion}\n`);
50+
print(`Copying project to temporary directory: ${temporaryProjectPath}\n`);
51+
}
52+
const copyStartTime = performance.now();
4453
fs.copySync(resolvedProjectPath, temporaryProjectPath);
54+
if (compileConfig.verbose) {
55+
print(`Project copy completed in ${performance.now() - copyStartTime}ms\n`);
56+
}
4557

58+
if (compileConfig.verbose) {
59+
print(`Generating temporary package.json\n`);
60+
}
4661
fs.writeFileSync(
4762
path.join(temporaryProjectPath, "package.json"),
4863
`{
@@ -52,9 +67,19 @@ export async function compile(
5267
}`
5368
);
5469

55-
await promisify(exec)("npm i --ignore-scripts", {
70+
const npmCommand = `npm i --ignore-scripts${compileConfig.verbose ? " --loglevel=http" : ""}`;
71+
if (compileConfig.verbose) {
72+
print(`Running '${npmCommand}' in temporary directory...\n`);
73+
}
74+
const npmStartTime = performance.now();
75+
const { stdout, stderr } = await promisify(exec)(npmCommand, {
5676
cwd: temporaryProjectPath
5777
});
78+
79+
if (compileConfig.verbose) {
80+
print(`NPM HTTP Logs:\n${stderr}\n`);
81+
print(`NPM install completed in ${performance.now() - npmStartTime}ms\n`);
82+
}
5883

5984
compileConfig.projectDir = temporaryProjectPath;
6085
}
@@ -77,7 +102,7 @@ export class CompileChildProcess {
77102
// if it exists, otherwise run the bazel compile loader target.
78103
const findForkScript = () => {
79104
try {
80-
const workerBundlePath = require.resolve("./worker_bundle");
105+
const workerBundlePath = require.resolve("./worker_bundle.js");
81106
return workerBundlePath;
82107
} catch (e) {
83108
return require.resolve("../../vm/compile_loader");

cli/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const testConnectionOptionName = "test-connection";
213213

214214
const watchOptionName = "watch";
215215

216+
const verboseOptionName = "verbose";
216217
const dryRunOptionName = "dry-run";
217218
const runTestsOptionName = "run-tests";
218219
const checkOptionName = "check";
@@ -375,6 +376,19 @@ export function runCli() {
375376
jsonOutputOption,
376377
timeoutOption,
377378
quietCompileOption,
379+
{
380+
name: verboseOptionName,
381+
option: {
382+
describe: "Enable verbose compilation output. Example usage: 'dataform compile --verbose'",
383+
type: "boolean",
384+
default: false
385+
},
386+
check: (argv: yargs.Arguments) => {
387+
if (argv.quiet && argv.verbose) {
388+
throw new Error("Arguments --verbose and --quiet are mutually exclusive.");
389+
}
390+
}
391+
},
378392
...ProjectConfigOptions.allYargsOptions
379393
],
380394
processFn: async argv => {
@@ -387,7 +401,8 @@ export function runCli() {
387401
const compiledGraph = await compile({
388402
projectDir,
389403
projectConfigOverride: ProjectConfigOptions.constructProjectConfigOverride(argv),
390-
timeoutMillis: argv[timeoutOption.name] || undefined
404+
timeoutMillis: argv[timeoutOption.name] || undefined,
405+
verbose: argv[verboseOptionName] || false
391406
});
392407
printCompiledGraph(compiledGraph, argv[jsonOutputOption.name], argv[quietCompileOption.name]);
393408
if (compiledGraphHasErrors(compiledGraph)) {

protos/core.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ message CompileConfig {
5151

5252
Extension extension = 10;
5353

54+
// Whether to emit compilation debug logs.
55+
bool verbose = 11;
56+
5457
reserved 2, 4, 5, 7, 9;
5558
}
5659

0 commit comments

Comments
 (0)