Skip to content

Commit 5ac5c91

Browse files
committed
End tracing early in autobuild Action for improved performance and reliability
This lets us achieve some performance and reliability improvements for workflows that run autobuild directly without specifying a build mode.
1 parent 7a6352f commit 5ac5c91

9 files changed

+46
-18
lines changed

lib/analyze.js

+4-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild-action.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tracer-config.js

+11-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tracer-config.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,10 @@ export async function runFinalize(
402402
logger,
403403
);
404404

405-
// WARNING: This does not _really_ end tracing, as the tracer will restore its
406-
// critical environment variables and it'll still be active for all processes
407-
// launched from this build step.
408-
// However, it will stop tracing for all steps past the codeql-action/analyze
409-
// step.
410-
// Delete variables as specified by the end-tracing script
411-
await endTracingForCluster(codeql, config, features);
405+
// If we didn't already end tracing in the autobuild Action, end it now.
406+
if (process.env[EnvVar.AUTOBUILD_DID_COMPLETE_SUCCESSFULLY] !== "true") {
407+
await endTracingForCluster(codeql, config, logger, features);
408+
}
412409
return timings;
413410
}
414411

src/autobuild-action.ts

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
sendStatusReport,
2222
ActionName,
2323
} from "./status-report";
24+
import { endTracingForCluster } from "./tracer-config";
2425
import {
2526
checkActionVersion,
2627
checkDiskUsage,
@@ -125,6 +126,10 @@ async function run() {
125126
await runAutobuild(config, language, features, logger);
126127
}
127128
}
129+
130+
// End tracing early to avoid tracing analyze. This improves the performance and reliability of
131+
// the analyze step.
132+
await endTracingForCluster(codeql, config, logger, features);
128133
} catch (unwrappedError) {
129134
const error = wrapError(unwrappedError);
130135
core.setFailed(

src/tracer-config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type CodeQL } from "./codeql";
55
import { type Config } from "./config-utils";
66
import { Feature, FeatureEnablement } from "./feature-flags";
77
import { isTracedLanguage } from "./languages";
8+
import { Logger } from "./logging";
89
import { ToolsFeature } from "./tools-features";
910
import { BuildMode } from "./util";
1011

@@ -28,13 +29,27 @@ export async function shouldEnableIndirectTracing(
2829
);
2930
}
3031

32+
/**
33+
* Delete variables as specified by the end-tracing script
34+
*
35+
* WARNING: This does not _really_ end tracing, as the tracer will restore its
36+
* critical environment variables and it'll still be active for all processes
37+
* launched from this build step.
38+
*
39+
* However, it will stop tracing for all steps past the current build step.
40+
*/
3141
export async function endTracingForCluster(
3242
codeql: CodeQL,
3343
config: Config,
44+
logger: Logger,
3445
features: FeatureEnablement,
3546
): Promise<void> {
3647
if (!(await shouldEnableIndirectTracing(codeql, config, features))) return;
3748

49+
logger.info(
50+
"Unsetting build tracing environment variables. Subsequent steps of this job will not be traced.",
51+
);
52+
3853
const envVariablesFile = path.resolve(
3954
config.dbLocation,
4055
"temp/tracingEnvironment/end-tracing.json",

0 commit comments

Comments
 (0)