Skip to content

Commit 609c67d

Browse files
simCopilot
andcommitted
Derive overlay minimum disk space from feature flags
Overlay analysis required 20 GB of available disk space, lowered to 14 GB when overlay_analysis_resource_checks_v2 was enabled. That gave us a single step to roll out, and any further reduction needed another flag and another release. Determine the threshold from the new overlay_analysis_min_disk_N_gb flags instead, taking the lowest one that is enabled so that a lower limit can be rolled out to a subset of repositories without first disabling the flag above it. When none are enabled, the 14 GB limit now applies unconditionally, replacing the 20 GB default. Thresholds remain in decimal MB, matching the bytes-per-MB convention the disk check already used, so the effective byte values are unchanged from the previous 14 GB path. Also log the available and required space at debug level when the check passes, so that run logs show which threshold took effect. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7526bed commit 609c67d

3 files changed

Lines changed: 128 additions & 47 deletions

File tree

lib/entry-points.js

Lines changed: 29 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,17 +1295,36 @@ checkOverlayEnablementMacro.serial(
12951295
);
12961296

12971297
checkOverlayEnablementMacro.serial(
1298-
"No overlay-base database on default branch if runner disk space is below v2 limit and v2 resource checks enabled",
1298+
"Overlay-base database on default branch if runner disk space is above the default limit",
12991299
{
13001300
languages: [BuiltInLanguage.javascript],
13011301
features: [
13021302
Feature.OverlayAnalysis,
13031303
Feature.OverlayAnalysisCodeScanningJavascript,
1304-
Feature.OverlayAnalysisResourceChecksV2,
13051304
],
13061305
isDefaultBranch: true,
13071306
diskUsage: {
1308-
numAvailableBytes: 5_000_000_000,
1307+
numAvailableBytes: 15_000_000_000,
1308+
numTotalBytes: 100_000_000_000,
1309+
},
1310+
},
1311+
{
1312+
overlayDatabaseMode: OverlayDatabaseMode.OverlayBase,
1313+
useOverlayDatabaseCaching: true,
1314+
},
1315+
);
1316+
1317+
checkOverlayEnablementMacro.serial(
1318+
"No overlay-base database on default branch if runner disk space is below the default limit",
1319+
{
1320+
languages: [BuiltInLanguage.javascript],
1321+
features: [
1322+
Feature.OverlayAnalysis,
1323+
Feature.OverlayAnalysisCodeScanningJavascript,
1324+
],
1325+
isDefaultBranch: true,
1326+
diskUsage: {
1327+
numAvailableBytes: 10_000_000_000,
13091328
numTotalBytes: 100_000_000_000,
13101329
},
13111330
},
@@ -1315,17 +1334,17 @@ checkOverlayEnablementMacro.serial(
13151334
);
13161335

13171336
checkOverlayEnablementMacro.serial(
1318-
"Overlay-base database on default branch if runner disk space is between v2 and v1 limits and v2 resource checks enabled",
1337+
"Overlay-base database on default branch if runner disk space is above the limit lowered by a feature flag",
13191338
{
13201339
languages: [BuiltInLanguage.javascript],
13211340
features: [
13221341
Feature.OverlayAnalysis,
13231342
Feature.OverlayAnalysisCodeScanningJavascript,
1324-
Feature.OverlayAnalysisResourceChecksV2,
1343+
Feature.OverlayAnalysisMinDisk10Gb,
13251344
],
13261345
isDefaultBranch: true,
13271346
diskUsage: {
1328-
numAvailableBytes: 15_000_000_000,
1347+
numAvailableBytes: 11_000_000_000,
13291348
numTotalBytes: 100_000_000_000,
13301349
},
13311350
},
@@ -1336,16 +1355,40 @@ checkOverlayEnablementMacro.serial(
13361355
);
13371356

13381357
checkOverlayEnablementMacro.serial(
1339-
"No overlay-base database on default branch if runner disk space is between v2 and v1 limits and v2 resource checks not enabled",
1358+
"Overlay-base database on default branch if runner disk space is exactly at the lowest limit enabled by a feature flag",
13401359
{
13411360
languages: [BuiltInLanguage.javascript],
13421361
features: [
13431362
Feature.OverlayAnalysis,
13441363
Feature.OverlayAnalysisCodeScanningJavascript,
1364+
Feature.OverlayAnalysisMinDisk9Gb,
1365+
Feature.OverlayAnalysisMinDisk12Gb,
13451366
],
13461367
isDefaultBranch: true,
13471368
diskUsage: {
1348-
numAvailableBytes: 15_000_000_000,
1369+
numAvailableBytes: 9_000_000_000,
1370+
numTotalBytes: 100_000_000_000,
1371+
},
1372+
},
1373+
{
1374+
overlayDatabaseMode: OverlayDatabaseMode.OverlayBase,
1375+
useOverlayDatabaseCaching: true,
1376+
},
1377+
);
1378+
1379+
checkOverlayEnablementMacro.serial(
1380+
"No overlay-base database on default branch if runner disk space is below the lowest limit enabled by a feature flag",
1381+
{
1382+
languages: [BuiltInLanguage.javascript],
1383+
features: [
1384+
Feature.OverlayAnalysis,
1385+
Feature.OverlayAnalysisCodeScanningJavascript,
1386+
Feature.OverlayAnalysisMinDisk9Gb,
1387+
Feature.OverlayAnalysisMinDisk12Gb,
1388+
],
1389+
isDefaultBranch: true,
1390+
diskUsage: {
1391+
numAvailableBytes: 8_500_000_000,
13491392
numTotalBytes: 100_000_000_000,
13501393
},
13511394
},

src/config-utils.ts

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
import { prepareDiffInformedAnalysis } from "./diff-informed-analysis-utils";
4949
import { EnvVar } from "./environment";
5050
import * as errorMessages from "./error-messages";
51-
import { Feature, FeatureEnablement } from "./feature-flags";
51+
import { Feature, FeatureEnablement, FeatureWithoutCLI } from "./feature-flags";
5252
import {
5353
RepositoryProperties,
5454
RepositoryPropertyName,
@@ -101,19 +101,28 @@ export { type Config } from "./config/action-config";
101101
* whether to perform overlay analysis, then the action will not perform overlay
102102
* analysis unless overlay analysis has been explicitly enabled via environment
103103
* variable.
104+
*
105+
* This threshold can be lowered by the feature flags in
106+
* `OVERLAY_MINIMUM_DISK_SPACE_FEATURES`.
104107
*/
105-
const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_MB = 20000;
106-
const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_BYTES =
107-
OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_MB * 1_000_000;
108+
const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_MB = 14000;
108109

109110
/**
110-
* The v2 minimum available disk space (in MB) required to perform overlay
111-
* analysis. This is a lower threshold than the v1 limit, allowing overlay
112-
* analysis to run on runners with less available disk space.
111+
* Feature flags that lower the minimum available disk space required to perform
112+
* overlay analysis, paired with the threshold (in MB) that each one enables.
113+
*
114+
* If several of these are enabled, the lowest threshold takes effect.
113115
*/
114-
const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_MB = 14000;
115-
const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES =
116-
OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_MB * 1_000_000;
116+
const OVERLAY_MINIMUM_DISK_SPACE_FEATURES: ReadonlyArray<
117+
[FeatureWithoutCLI, number]
118+
> = [
119+
[Feature.OverlayAnalysisMinDisk8Gb, 8000],
120+
[Feature.OverlayAnalysisMinDisk9Gb, 9000],
121+
[Feature.OverlayAnalysisMinDisk10Gb, 10000],
122+
[Feature.OverlayAnalysisMinDisk11Gb, 11000],
123+
[Feature.OverlayAnalysisMinDisk12Gb, 12000],
124+
[Feature.OverlayAnalysisMinDisk13Gb, 13000],
125+
];
117126

118127
/**
119128
* The minimum memory (in MB) that must be available for CodeQL to perform overlay analysis. If
@@ -588,24 +597,42 @@ async function checkOverlayAnalysisFeatureEnabled(
588597
return new Success(undefined);
589598
}
590599

600+
/**
601+
* Returns the minimum available disk space (in MB) required to perform overlay
602+
* analysis, which is the lowest threshold enabled by a feature flag, or the
603+
* default threshold if no such feature flag is enabled.
604+
*/
605+
async function getMinimumDiskSpaceMb(
606+
features: FeatureEnablement,
607+
): Promise<number> {
608+
let minimumMb = OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_MB;
609+
for (const [feature, thresholdMb] of OVERLAY_MINIMUM_DISK_SPACE_FEATURES) {
610+
if (await features.getValue(feature)) {
611+
minimumMb = Math.min(minimumMb, thresholdMb);
612+
}
613+
}
614+
return minimumMb;
615+
}
616+
591617
/** Checks if the runner has enough disk space for overlay analysis. */
592618
function runnerHasSufficientDiskSpace(
593619
diskUsage: DiskUsage,
594620
logger: Logger,
595-
useV2ResourceChecks: boolean,
621+
minimumDiskSpaceMb: number,
596622
): boolean {
597-
const minimumDiskSpaceBytes = useV2ResourceChecks
598-
? OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES
599-
: OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_BYTES;
600-
if (diskUsage.numAvailableBytes < minimumDiskSpaceBytes) {
601-
const diskSpaceMb = Math.round(diskUsage.numAvailableBytes / 1_000_000);
602-
const minimumDiskSpaceMb = Math.round(minimumDiskSpaceBytes / 1_000_000);
623+
const diskSpaceMb = Math.round(diskUsage.numAvailableBytes / 1_000_000);
624+
if (diskUsage.numAvailableBytes < minimumDiskSpaceMb * 1_000_000) {
603625
logger.info(
604626
`Setting overlay database mode to ${OverlayDatabaseMode.None} ` +
605627
`due to insufficient disk space (${diskSpaceMb} MB, needed ${minimumDiskSpaceMb} MB).`,
606628
);
607629
return false;
608630
}
631+
632+
logger.debug(
633+
`Disk space available for CodeQL analysis is ${diskSpaceMb} MB, which is above the minimum ` +
634+
`of ${minimumDiskSpaceMb} MB.`,
635+
);
609636
return true;
610637
}
611638

@@ -648,12 +675,13 @@ async function runnerHasSufficientMemory(
648675
*/
649676
async function checkRunnerResources(
650677
codeql: CodeQL,
678+
features: FeatureEnablement,
651679
diskUsage: DiskUsage,
652680
ramInput: string | undefined,
653681
logger: Logger,
654-
useV2ResourceChecks: boolean,
655682
): Promise<Result<void, OverlayDisabledReason>> {
656-
if (!runnerHasSufficientDiskSpace(diskUsage, logger, useV2ResourceChecks)) {
683+
const minimumDiskSpaceMb = await getMinimumDiskSpaceMb(features);
684+
if (!runnerHasSufficientDiskSpace(diskUsage, logger, minimumDiskSpaceMb)) {
657685
return new Failure(OverlayDisabledReason.InsufficientDiskSpace);
658686
}
659687
if (!(await runnerHasSufficientMemory(codeql, ramInput, logger))) {
@@ -752,9 +780,6 @@ export async function checkOverlayEnablement(
752780
Feature.OverlayAnalysisSkipResourceChecks,
753781
codeql,
754782
));
755-
const useV2ResourceChecks = await features.getValue(
756-
Feature.OverlayAnalysisResourceChecksV2,
757-
);
758783
const checkOverlayStatus = await features.getValue(
759784
Feature.OverlayAnalysisStatusCheck,
760785
);
@@ -770,10 +795,10 @@ export async function checkOverlayEnablement(
770795
performResourceChecks && diskUsage !== undefined
771796
? await checkRunnerResources(
772797
codeql,
798+
features,
773799
diskUsage,
774800
ramInput,
775801
logger,
776-
useV2ResourceChecks,
777802
)
778803
: new Success<void>(undefined);
779804
if (resourceResult.isFailure()) {

0 commit comments

Comments
 (0)