Limit cardinality of ML-powered JS queries status report

Some platforms that ingest this status report charge based on the
cardinality of the fields, so here we restrict the version strings we
support to a fixed set.
This commit is contained in:
Henry Mercer 2022-02-07 14:36:40 +00:00
parent f888be73ce
commit c95a3d854c
6 changed files with 78 additions and 33 deletions

35
lib/util.js generated
View file

@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.getMlPoweredJsQueriesStatus = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.checkNotWindows11 = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.isHTTPError = exports.HTTPError = exports.getRequiredEnvParam = exports.isActions = exports.getMode = exports.enrichEnvironment = exports.initializeEnvironment = exports.Mode = exports.assertNever = exports.getGitHubAuth = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0; exports.getMlPoweredJsQueriesStatus = exports.ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.checkNotWindows11 = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.isHTTPError = exports.HTTPError = exports.getRequiredEnvParam = exports.isActions = exports.getMode = exports.enrichEnvironment = exports.initializeEnvironment = exports.Mode = exports.assertNever = exports.getGitHubAuth = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
@ -525,16 +525,23 @@ function checkNotWindows11() {
} }
exports.checkNotWindows11 = checkNotWindows11; exports.checkNotWindows11 = checkNotWindows11;
exports.ML_POWERED_JS_QUERIES_PACK_NAME = "codeql/javascript-experimental-atm-queries"; exports.ML_POWERED_JS_QUERIES_PACK_NAME = "codeql/javascript-experimental-atm-queries";
/**
* Set containing version strings of the ML-powered JS query pack that are reportable.
*
* We restrict the set of version strings we report to limit the cardinality of the ML-powered JS
* queries status report field, since some platforms that ingest this status report charge based on
* the cardinality of the fields.
*/
exports.ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS = new Set(["~0.0.2"]);
/** /**
* Get information about ML-powered JS queries to populate status reports with. * Get information about ML-powered JS queries to populate status reports with.
* *
* This will be: * This will be:
* *
* - The version string if the analysis will use a specific version of the pack * - The version string if the analysis will use a specific version of the pack and that version
* - "latest" if the analysis will use the latest version of the pack * string is within {@link ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS}.
* - "false" if the analysis won't run any ML-powered JS queries * - "false" if the analysis won't run any ML-powered JS queries.
* - "multiple" if the analysis will run multiple ML-powered JS query packs (this is an unsupported * - "other" in all other cases.
* scenario)
* *
* This function lives here rather than in `init-action.ts` so it's easier to test, since tests for * This function lives here rather than in `init-action.ts` so it's easier to test, since tests for
* `init-action.ts` would each need to live in their own file. See `analyze-action-env.ts` for an * `init-action.ts` would each need to live in their own file. See `analyze-action-env.ts` for an
@ -542,14 +549,16 @@ exports.ML_POWERED_JS_QUERIES_PACK_NAME = "codeql/javascript-experimental-atm-qu
*/ */
function getMlPoweredJsQueriesStatus(config) { function getMlPoweredJsQueriesStatus(config) {
const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter((pack) => pack.packName === exports.ML_POWERED_JS_QUERIES_PACK_NAME); const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter((pack) => pack.packName === exports.ML_POWERED_JS_QUERIES_PACK_NAME);
switch (mlPoweredJsQueryPacks.length) { if (mlPoweredJsQueryPacks.length === 0) {
case 1: return "false";
return mlPoweredJsQueryPacks[0].version || "latest";
case 0:
return "false";
default:
return "multiple";
} }
const firstVersionString = mlPoweredJsQueryPacks[0].version;
if (mlPoweredJsQueryPacks.length === 1 &&
firstVersionString &&
exports.ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS.has(firstVersionString)) {
return firstVersionString;
}
return "other";
} }
exports.getMlPoweredJsQueriesStatus = getMlPoweredJsQueriesStatus; exports.getMlPoweredJsQueriesStatus = getMlPoweredJsQueriesStatus;
//# sourceMappingURL=util.js.map //# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

18
lib/util.test.js generated
View file

@ -206,24 +206,36 @@ async function mockStdInForAuthExpectError(t, mockLogger, ...text) {
} }
const ML_POWERED_JS_STATUS_TESTS = [ const ML_POWERED_JS_STATUS_TESTS = [
[[], "false"], [[], "false"],
[[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }], "latest"], [[{ packName: "someOtherPack" }], "false"],
[
[
{ packName: "someOtherPack" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" },
],
"~0.0.2",
],
[ [
[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" }], [{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" }],
"~0.0.2", "~0.0.2",
], ],
[[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }], "other"],
[
[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.1" }],
"other",
],
[ [
[ [
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.1" }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.1" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.2" }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.2" },
], ],
"multiple", "other",
], ],
[ [
[ [
{ packName: "someOtherPack" }, { packName: "someOtherPack" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME },
], ],
"latest", "other",
], ],
]; ];
for (const [packs, expectedStatus] of ML_POWERED_JS_STATUS_TESTS) { for (const [packs, expectedStatus] of ML_POWERED_JS_STATUS_TESTS) {

File diff suppressed because one or more lines are too long

View file

@ -295,24 +295,36 @@ async function mockStdInForAuthExpectError(
const ML_POWERED_JS_STATUS_TESTS: Array<[PackWithVersion[], string]> = [ const ML_POWERED_JS_STATUS_TESTS: Array<[PackWithVersion[], string]> = [
[[], "false"], [[], "false"],
[[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }], "latest"], [[{ packName: "someOtherPack" }], "false"],
[
[
{ packName: "someOtherPack" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" },
],
"~0.0.2",
],
[ [
[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" }], [{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.2" }],
"~0.0.2", "~0.0.2",
], ],
[[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }], "other"],
[
[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.0.1" }],
"other",
],
[ [
[ [
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.1" }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.1" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.2" }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.2" },
], ],
"multiple", "other",
], ],
[ [
[ [
{ packName: "someOtherPack" }, { packName: "someOtherPack" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }, { packName: util.ML_POWERED_JS_QUERIES_PACK_NAME },
], ],
"latest", "other",
], ],
]; ];

View file

@ -631,16 +631,24 @@ export function checkNotWindows11() {
export const ML_POWERED_JS_QUERIES_PACK_NAME = export const ML_POWERED_JS_QUERIES_PACK_NAME =
"codeql/javascript-experimental-atm-queries"; "codeql/javascript-experimental-atm-queries";
/**
* Set containing version strings of the ML-powered JS query pack that are reportable.
*
* We restrict the set of version strings we report to limit the cardinality of the ML-powered JS
* queries status report field, since some platforms that ingest this status report charge based on
* the cardinality of the fields.
*/
export const ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS = new Set(["~0.0.2"]);
/** /**
* Get information about ML-powered JS queries to populate status reports with. * Get information about ML-powered JS queries to populate status reports with.
* *
* This will be: * This will be:
* *
* - The version string if the analysis will use a specific version of the pack * - The version string if the analysis will use a specific version of the pack and that version
* - "latest" if the analysis will use the latest version of the pack * string is within {@link ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS}.
* - "false" if the analysis won't run any ML-powered JS queries * - "false" if the analysis won't run any ML-powered JS queries.
* - "multiple" if the analysis will run multiple ML-powered JS query packs (this is an unsupported * - "other" in all other cases.
* scenario)
* *
* This function lives here rather than in `init-action.ts` so it's easier to test, since tests for * This function lives here rather than in `init-action.ts` so it's easier to test, since tests for
* `init-action.ts` would each need to live in their own file. See `analyze-action-env.ts` for an * `init-action.ts` would each need to live in their own file. See `analyze-action-env.ts` for an
@ -650,12 +658,16 @@ export function getMlPoweredJsQueriesStatus(config: Config): string {
const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter( const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter(
(pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK_NAME (pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK_NAME
); );
switch (mlPoweredJsQueryPacks.length) { if (mlPoweredJsQueryPacks.length === 0) {
case 1: return "false";
return mlPoweredJsQueryPacks[0].version || "latest";
case 0:
return "false";
default:
return "multiple";
} }
const firstVersionString = mlPoweredJsQueryPacks[0].version;
if (
mlPoweredJsQueryPacks.length === 1 &&
firstVersionString &&
ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS.has(firstVersionString)
) {
return firstVersionString;
}
return "other";
} }