Skip to content

Commit adf58cf

Browse files
authored
Merge pull request #3515 from github/henrymercer/drop-ram-limit
Skip overlay memory check for CodeQL 2.24.3 and later
2 parents b0ed4de + 29765a3 commit adf58cf

File tree

3 files changed

+126
-12
lines changed

3 files changed

+126
-12
lines changed

lib/init-action.js

Lines changed: 27 additions & 1 deletion
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,25 @@ test(
13651365
},
13661366
);
13671367

1368+
test(
1369+
getOverlayDatabaseModeMacro,
1370+
"Overlay-base database on default branch if memory flag is too low but CodeQL >= 2.24.3",
1371+
{
1372+
languages: [KnownLanguage.javascript],
1373+
features: [
1374+
Feature.OverlayAnalysis,
1375+
Feature.OverlayAnalysisCodeScanningJavascript,
1376+
],
1377+
isDefaultBranch: true,
1378+
memoryFlagValue: 3072,
1379+
codeqlVersion: "2.24.3",
1380+
},
1381+
{
1382+
overlayDatabaseMode: OverlayDatabaseMode.OverlayBase,
1383+
useOverlayDatabaseCaching: true,
1384+
},
1385+
);
1386+
13681387
test(
13691388
getOverlayDatabaseModeMacro,
13701389
"Overlay-base database on default branch if memory flag is too low and skip resource checks flag is enabled",
@@ -1683,6 +1702,25 @@ test(
16831702
},
16841703
);
16851704

1705+
test(
1706+
getOverlayDatabaseModeMacro,
1707+
"Overlay analysis on PR if memory flag is too low but CodeQL >= 2.24.3",
1708+
{
1709+
languages: [KnownLanguage.javascript],
1710+
features: [
1711+
Feature.OverlayAnalysis,
1712+
Feature.OverlayAnalysisCodeScanningJavascript,
1713+
],
1714+
isPullRequest: true,
1715+
memoryFlagValue: 3072,
1716+
codeqlVersion: "2.24.3",
1717+
},
1718+
{
1719+
overlayDatabaseMode: OverlayDatabaseMode.Overlay,
1720+
useOverlayDatabaseCaching: true,
1721+
},
1722+
);
1723+
16861724
test(
16871725
getOverlayDatabaseModeMacro,
16881726
"Overlay analysis on PR if memory flag is too low and skip resource checks flag is enabled",

src/config-utils.ts

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,23 @@ const OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES =
9292
OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_MB * 1_000_000;
9393

9494
/**
95-
* The minimum memory (in MB) that must be available for CodeQL to perform overlay
96-
* analysis. If CodeQL will be given less memory than this threshold, then the
97-
* action will not perform overlay analysis unless overlay analysis has been
98-
* explicitly enabled via environment variable.
95+
* The minimum memory (in MB) that must be available for CodeQL to perform overlay analysis. If
96+
* CodeQL will be given less memory than this threshold, then the action will not perform overlay
97+
* analysis unless overlay analysis has been explicitly enabled via environment variable.
98+
*
99+
* This check is not performed for CodeQL >= `CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE` since
100+
* improved memory usage in that version makes the check unnecessary.
99101
*/
100102
const OVERLAY_MINIMUM_MEMORY_MB = 5 * 1024;
101103

104+
/**
105+
* Versions 2.24.3+ of CodeQL reduce overlay analysis's peak RAM usage.
106+
*
107+
* In particular, RAM usage with overlay analysis enabled should generally be no higher than it is
108+
* without overlay analysis for these versions.
109+
*/
110+
const CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE = "2.24.3";
111+
102112
export type RegistryConfigWithCredentials = RegistryConfigNoCredentials & {
103113
// Token to use when downloading packs from this registry.
104114
token: string;
@@ -683,16 +693,12 @@ async function isOverlayAnalysisFeatureEnabled(
683693
return true;
684694
}
685695

686-
/**
687-
* Checks if the runner supports overlay analysis based on available disk space
688-
* and the maximum memory CodeQL will be allowed to use.
689-
*/
690-
async function runnerSupportsOverlayAnalysis(
696+
/** Checks if the runner has enough disk space for overlay analysis. */
697+
function runnerHasSufficientDiskSpace(
691698
diskUsage: DiskUsage | undefined,
692-
ramInput: string | undefined,
693699
logger: Logger,
694700
useV2ResourceChecks: boolean,
695-
): Promise<boolean> {
701+
): boolean {
696702
const minimumDiskSpaceBytes = useV2ResourceChecks
697703
? OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_V2_BYTES
698704
: OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_BYTES;
@@ -711,6 +717,26 @@ async function runnerSupportsOverlayAnalysis(
711717
);
712718
return false;
713719
}
720+
return true;
721+
}
722+
723+
/** Checks if the runner has enough memory for overlay analysis. */
724+
async function runnerHasSufficientMemory(
725+
codeql: CodeQL,
726+
ramInput: string | undefined,
727+
logger: Logger,
728+
): Promise<boolean> {
729+
if (
730+
await codeQlVersionAtLeast(
731+
codeql,
732+
CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE,
733+
)
734+
) {
735+
logger.debug(
736+
`Skipping memory check for overlay analysis because CodeQL version is at least ${CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE}.`,
737+
);
738+
return true;
739+
}
714740

715741
const memoryFlagValue = getCodeQLMemoryLimit(ramInput, logger);
716742
if (memoryFlagValue < OVERLAY_MINIMUM_MEMORY_MB) {
@@ -721,6 +747,29 @@ async function runnerSupportsOverlayAnalysis(
721747
return false;
722748
}
723749

750+
logger.debug(
751+
`Memory available for CodeQL analysis is ${memoryFlagValue} MB, which is above the minimum of ${OVERLAY_MINIMUM_MEMORY_MB} MB.`,
752+
);
753+
return true;
754+
}
755+
756+
/**
757+
* Checks if the runner supports overlay analysis based on available disk space
758+
* and the maximum memory CodeQL will be allowed to use.
759+
*/
760+
async function runnerSupportsOverlayAnalysis(
761+
codeql: CodeQL,
762+
diskUsage: DiskUsage | undefined,
763+
ramInput: string | undefined,
764+
logger: Logger,
765+
useV2ResourceChecks: boolean,
766+
): Promise<boolean> {
767+
if (!runnerHasSufficientDiskSpace(diskUsage, logger, useV2ResourceChecks)) {
768+
return false;
769+
}
770+
if (!(await runnerHasSufficientMemory(codeql, ramInput, logger))) {
771+
return false;
772+
}
724773
return true;
725774
}
726775

@@ -812,6 +861,7 @@ export async function getOverlayDatabaseMode(
812861
if (
813862
performResourceChecks &&
814863
!(await runnerSupportsOverlayAnalysis(
864+
codeql,
815865
diskUsage,
816866
ramInput,
817867
logger,

0 commit comments

Comments
 (0)