Log cgroup RAM limits

This commit is contained in:
Henry Mercer 2023-09-18 12:43:52 +01:00
parent 253d9cf358
commit 379f89dc53
12 changed files with 32 additions and 19 deletions

2
lib/analyze-action.js generated
View file

@ -163,7 +163,7 @@ async function run() {
const repositoryNwo = (0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY"));
const gitHubVersion = await (0, api_client_1.getGitHubVersion)();
const features = new feature_flags_1.Features(gitHubVersion, repositoryNwo, actionsUtil.getTemporaryDirectory(), logger);
const memory = util.getMemoryFlag(actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"]);
const memory = util.getMemoryFlag(actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"], logger);
await runAutobuildIfLegacyGoWorkflow(config, logger);
dbCreationTimings = await (0, analyze_1.runFinalize)(outputDir, threads, memory, config, logger, features);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {

File diff suppressed because one or more lines are too long

2
lib/init-action.js generated
View file

@ -173,7 +173,7 @@ async function run() {
// options at https://codeql.github.com/docs/codeql-cli/manual/database-trace-command/
// for details.
core.exportVariable("CODEQL_RAM", process.env["CODEQL_RAM"] ||
(0, util_1.getMemoryFlagValue)((0, actions_util_1.getOptionalInput)("ram")).toString());
(0, util_1.getMemoryFlagValue)((0, actions_util_1.getOptionalInput)("ram"), logger).toString());
core.exportVariable("CODEQL_THREADS", (0, util_1.getThreadsFlagValue)((0, actions_util_1.getOptionalInput)("threads"), logger).toString());
// Disable Kotlin extractor if feature flag set
if (await features.getValue(feature_flags_1.Feature.DisableKotlinAnalysisEnabled)) {

File diff suppressed because one or more lines are too long

11
lib/util.js generated
View file

@ -152,7 +152,7 @@ exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
* Get the total amount of memory available to the Action, taking into account constraints imposed
* by cgroups on Linux.
*/
function getTotalMemoryAvailable() {
function getTotalMemoryAvailable(logger) {
if (os.platform() === "linux") {
// Respect constraints imposed by Linux cgroups v1 and v2
for (const limitFile of [
@ -162,6 +162,7 @@ function getTotalMemoryAvailable() {
if (fs.existsSync(limitFile)) {
const limit = Number(fs.readFileSync(limitFile, "utf8"));
if (Number.isInteger(limit)) {
logger.info(`While resolving RAM, found cgroup limit of ${limit / (1024 * 1024)} MiB in ${limitFile}.`);
return limit;
}
}
@ -176,8 +177,8 @@ function getTotalMemoryAvailable() {
*
* @returns {number} the amount of RAM to use, in megabytes
*/
function getMemoryFlagValue(userInput) {
return getMemoryFlagValueForPlatform(userInput, getTotalMemoryAvailable(), process.platform);
function getMemoryFlagValue(userInput, logger) {
return getMemoryFlagValueForPlatform(userInput, getTotalMemoryAvailable(logger), process.platform);
}
exports.getMemoryFlagValue = getMemoryFlagValue;
/**
@ -187,8 +188,8 @@ exports.getMemoryFlagValue = getMemoryFlagValue;
*
* @returns string
*/
function getMemoryFlag(userInput) {
const megabytes = getMemoryFlagValue(userInput);
function getMemoryFlag(userInput, logger) {
const megabytes = getMemoryFlagValue(userInput, logger);
return `--ram=${megabytes}`;
}
exports.getMemoryFlag = getMemoryFlag;

File diff suppressed because one or more lines are too long

2
lib/util.test.js generated
View file

@ -97,7 +97,7 @@ for (const { input, totalMemoryMb, platform, expectedMemoryValue, reservedPercen
}
(0, ava_1.default)("getMemoryFlag() throws if the ram input is < 0 or NaN", async (t) => {
for (const input of ["-1", "hello!"]) {
t.throws(() => util.getMemoryFlag(input));
t.throws(() => util.getMemoryFlag(input, (0, logging_1.getRunnerLogger)(true)));
}
});
(0, ava_1.default)("getAddSnippetsFlag() should return the correct flag", (t) => {

File diff suppressed because one or more lines are too long

View file

@ -233,6 +233,7 @@ async function run() {
const memory = util.getMemoryFlag(
actionsUtil.getOptionalInput("ram") || process.env["CODEQL_RAM"],
logger,
);
await runAutobuildIfLegacyGoWorkflow(config, logger);

View file

@ -332,7 +332,7 @@ async function run() {
core.exportVariable(
"CODEQL_RAM",
process.env["CODEQL_RAM"] ||
getMemoryFlagValue(getOptionalInput("ram")).toString(),
getMemoryFlagValue(getOptionalInput("ram"), logger).toString(),
);
core.exportVariable(
"CODEQL_THREADS",

View file

@ -93,7 +93,7 @@ for (const {
test("getMemoryFlag() throws if the ram input is < 0 or NaN", async (t) => {
for (const input of ["-1", "hello!"]) {
t.throws(() => util.getMemoryFlag(input));
t.throws(() => util.getMemoryFlag(input, getRunnerLogger(true)));
}
});

View file

@ -215,7 +215,7 @@ export function getMemoryFlagValueForPlatform(
* Get the total amount of memory available to the Action, taking into account constraints imposed
* by cgroups on Linux.
*/
function getTotalMemoryAvailable(): number {
function getTotalMemoryAvailable(logger: Logger): number {
if (os.platform() === "linux") {
// Respect constraints imposed by Linux cgroups v1 and v2
for (const limitFile of [
@ -225,6 +225,11 @@ function getTotalMemoryAvailable(): number {
if (fs.existsSync(limitFile)) {
const limit = Number(fs.readFileSync(limitFile, "utf8"));
if (Number.isInteger(limit)) {
logger.info(
`While resolving RAM, found cgroup limit of ${
limit / (1024 * 1024)
} MiB in ${limitFile}.`,
);
return limit;
}
}
@ -240,10 +245,13 @@ function getTotalMemoryAvailable(): number {
*
* @returns {number} the amount of RAM to use, in megabytes
*/
export function getMemoryFlagValue(userInput: string | undefined): number {
export function getMemoryFlagValue(
userInput: string | undefined,
logger: Logger,
): number {
return getMemoryFlagValueForPlatform(
userInput,
getTotalMemoryAvailable(),
getTotalMemoryAvailable(logger),
process.platform,
);
}
@ -255,8 +263,11 @@ export function getMemoryFlagValue(userInput: string | undefined): number {
*
* @returns string
*/
export function getMemoryFlag(userInput: string | undefined): string {
const megabytes = getMemoryFlagValue(userInput);
export function getMemoryFlag(
userInput: string | undefined,
logger: Logger,
): string {
const megabytes = getMemoryFlagValue(userInput, logger);
return `--ram=${megabytes}`;
}