Skip to content

Commit

Permalink
End tracing early in autobuild Action for improved performance and re…
Browse files Browse the repository at this point in the history
…liability

This lets us achieve some performance and reliability improvements for
workflows that run autobuild directly without specifying a build mode.
  • Loading branch information
henrymercer committed May 9, 2024
1 parent 7a6352f commit 5ac5c91
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 18 deletions.
11 changes: 4 additions & 7 deletions lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/autobuild-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/autobuild-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion lib/tracer-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tracer-config.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,10 @@ export async function runFinalize(
logger,
);

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

Expand Down
5 changes: 5 additions & 0 deletions src/autobuild-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
sendStatusReport,
ActionName,
} from "./status-report";
import { endTracingForCluster } from "./tracer-config";
import {
checkActionVersion,
checkDiskUsage,
Expand Down Expand Up @@ -125,6 +126,10 @@ async function run() {
await runAutobuild(config, language, features, logger);
}
}

// End tracing early to avoid tracing analyze. This improves the performance and reliability of
// the analyze step.
await endTracingForCluster(codeql, config, logger, features);
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
core.setFailed(
Expand Down
15 changes: 15 additions & 0 deletions src/tracer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type CodeQL } from "./codeql";
import { type Config } from "./config-utils";
import { Feature, FeatureEnablement } from "./feature-flags";
import { isTracedLanguage } from "./languages";
import { Logger } from "./logging";
import { ToolsFeature } from "./tools-features";
import { BuildMode } from "./util";

Expand All @@ -28,13 +29,27 @@ export async function shouldEnableIndirectTracing(
);
}

/**
* Delete variables as specified by the end-tracing script
*
* WARNING: This does not _really_ end tracing, as the tracer will restore its
* critical environment variables and it'll still be active for all processes
* launched from this build step.
*
* However, it will stop tracing for all steps past the current build step.
*/
export async function endTracingForCluster(
codeql: CodeQL,
config: Config,
logger: Logger,
features: FeatureEnablement,
): Promise<void> {
if (!(await shouldEnableIndirectTracing(codeql, config, features))) return;

logger.info(
"Unsetting build tracing environment variables. Subsequent steps of this job will not be traced.",
);

const envVariablesFile = path.resolve(
config.dbLocation,
"temp/tracingEnvironment/end-tracing.json",
Expand Down

0 comments on commit 5ac5c91

Please sign in to comment.