Skip to content

Commit bd8d26b

Browse files
committed
Overlay: Fall back to full analysis if memory flag is low
1 parent bd30e75 commit bd8d26b

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

lib/init-action.js

Lines changed: 22 additions & 15 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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function createTestInitConfigInputs(
5959
dbLocation: undefined,
6060
configInput: undefined,
6161
buildModeInput: undefined,
62+
ramInput: undefined,
6263
trapCachingEnabled: false,
6364
dependencyCachingEnabled: CachingKind.None,
6465
debugMode: false,
@@ -979,6 +980,7 @@ interface OverlayDatabaseModeTestSetup {
979980
gitRoot: string | undefined;
980981
codeScanningConfig: configUtils.UserConfig;
981982
diskUsage: DiskUsage | undefined;
983+
memoryFlagValue: number;
982984
}
983985

984986
const defaultOverlayDatabaseModeTestSetup: OverlayDatabaseModeTestSetup = {
@@ -995,6 +997,7 @@ const defaultOverlayDatabaseModeTestSetup: OverlayDatabaseModeTestSetup = {
995997
numAvailableBytes: 50_000_000_000,
996998
numTotalBytes: 100_000_000_000,
997999
},
1000+
memoryFlagValue: 6920,
9981001
};
9991002

10001003
const getOverlayDatabaseModeMacro = test.macro({
@@ -1037,6 +1040,8 @@ const getOverlayDatabaseModeMacro = test.macro({
10371040
.stub(actionsUtil, "isAnalyzingPullRequest")
10381041
.returns(setup.isPullRequest);
10391042

1043+
sinon.stub(util, "getMemoryFlagValue").returns(setup.memoryFlagValue);
1044+
10401045
// Set up CodeQL mock
10411046
const codeql = mockCodeQLVersion(setup.codeqlVersion);
10421047

@@ -1063,6 +1068,7 @@ const getOverlayDatabaseModeMacro = test.macro({
10631068
setup.languages,
10641069
tempDir, // sourceRoot
10651070
setup.buildMode,
1071+
undefined,
10661072
setup.codeScanningConfig,
10671073
logger,
10681074
);
@@ -1225,6 +1231,24 @@ test(
12251231
},
12261232
);
12271233

1234+
test(
1235+
getOverlayDatabaseModeMacro,
1236+
"No overlay-base database on default branch if memory flag is too low",
1237+
{
1238+
languages: [KnownLanguage.javascript],
1239+
features: [
1240+
Feature.OverlayAnalysis,
1241+
Feature.OverlayAnalysisCodeScanningJavascript,
1242+
],
1243+
isDefaultBranch: true,
1244+
memoryFlagValue: 3072,
1245+
},
1246+
{
1247+
overlayDatabaseMode: OverlayDatabaseMode.None,
1248+
useOverlayDatabaseCaching: false,
1249+
},
1250+
);
1251+
12281252
test(
12291253
getOverlayDatabaseModeMacro,
12301254
"No overlay-base database on default branch when code-scanning feature enabled with disable-default-queries",
@@ -1434,6 +1458,24 @@ test(
14341458
},
14351459
);
14361460

1461+
test(
1462+
getOverlayDatabaseModeMacro,
1463+
"No overlay analysis on PR if memory flag is too low",
1464+
{
1465+
languages: [KnownLanguage.javascript],
1466+
features: [
1467+
Feature.OverlayAnalysis,
1468+
Feature.OverlayAnalysisCodeScanningJavascript,
1469+
],
1470+
isPullRequest: true,
1471+
memoryFlagValue: 3072,
1472+
},
1473+
{
1474+
overlayDatabaseMode: OverlayDatabaseMode.None,
1475+
useOverlayDatabaseCaching: false,
1476+
},
1477+
);
1478+
14371479
test(
14381480
getOverlayDatabaseModeMacro,
14391481
"No overlay analysis on PR when code-scanning feature enabled with disable-default-queries",

src/config-utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
cloneObject,
4545
isDefined,
4646
checkDiskUsage,
47+
getMemoryFlagValue,
4748
} from "./util";
4849

4950
export * from "./config/db-config";
@@ -393,6 +394,7 @@ export interface InitConfigInputs {
393394
dbLocation: string | undefined;
394395
configInput: string | undefined;
395396
buildModeInput: string | undefined;
397+
ramInput: string | undefined;
396398
trapCachingEnabled: boolean;
397399
dependencyCachingEnabled: string | undefined;
398400
debugMode: boolean;
@@ -661,6 +663,7 @@ export async function getOverlayDatabaseMode(
661663
languages: Language[],
662664
sourceRoot: string,
663665
buildMode: BuildMode | undefined,
666+
ramInput: string | undefined,
664667
codeScanningConfig: UserConfig,
665668
logger: Logger,
666669
): Promise<{
@@ -692,6 +695,7 @@ export async function getOverlayDatabaseMode(
692695
)
693696
) {
694697
const diskUsage = await checkDiskUsage(logger);
698+
const memoryFlagValue = getMemoryFlagValue(ramInput, logger);
695699
if (
696700
diskUsage === undefined ||
697701
diskUsage.numAvailableBytes < OVERLAY_MINIMUM_AVAILABLE_DISK_SPACE_BYTES
@@ -706,6 +710,13 @@ export async function getOverlayDatabaseMode(
706710
`Setting overlay database mode to ${overlayDatabaseMode} ` +
707711
`due to insufficient disk space (${diskSpaceMb} MB).`,
708712
);
713+
} else if (memoryFlagValue < 5 * 1024) {
714+
overlayDatabaseMode = OverlayDatabaseMode.None;
715+
useOverlayDatabaseCaching = false;
716+
logger.info(
717+
`Setting overlay database mode to ${overlayDatabaseMode} ` +
718+
`due to insufficient memory for CodeQL analysis (${memoryFlagValue} MB).`,
719+
);
709720
} else if (isAnalyzingPullRequest()) {
710721
overlayDatabaseMode = OverlayDatabaseMode.Overlay;
711722
useOverlayDatabaseCaching = true;
@@ -873,6 +884,7 @@ export async function initConfig(
873884
config.languages,
874885
inputs.sourceRoot,
875886
config.buildMode,
887+
inputs.ramInput,
876888
config.computedConfig,
877889
logger,
878890
);

src/init-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ async function run() {
324324
queriesInput: getOptionalInput("queries"),
325325
packsInput: getOptionalInput("packs"),
326326
buildModeInput: getOptionalInput("build-mode"),
327+
ramInput: getOptionalInput("ram"),
327328
configFile,
328329
dbLocation: getOptionalInput("db-location"),
329330
configInput: getOptionalInput("config"),

0 commit comments

Comments
 (0)