Skip to content

Commit

Permalink
Limit cardinality of ML-powered JS queries status report
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
henrymercer committed Feb 7, 2022
1 parent f888be7 commit c95a3d8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 33 deletions.
35 changes: 22 additions & 13 deletions lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions lib/util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.test.js.map

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,36 @@ async function mockStdInForAuthExpectError(

const ML_POWERED_JS_STATUS_TESTS: Array<[PackWithVersion[], string]> = [
[[], "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" }],
"~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.2" },
],
"multiple",
"other",
],
[
[
{ packName: "someOtherPack" },
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME },
],
"latest",
"other",
],
];

Expand Down
36 changes: 24 additions & 12 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,16 +631,24 @@ export function checkNotWindows11() {
export const 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.
*/
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.
*
* This will be:
*
* - The version string if the analysis will use a specific version of the pack
* - "latest" if the analysis will use the latest version of the pack
* - "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
* scenario)
* - The version string if the analysis will use a specific version of the pack and that version
* string is within {@link ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS}.
* - "false" if the analysis won't run any ML-powered JS queries.
* - "other" in all other cases.
*
* 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
Expand All @@ -650,12 +658,16 @@ export function getMlPoweredJsQueriesStatus(config: Config): string {
const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter(
(pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK_NAME
);
switch (mlPoweredJsQueryPacks.length) {
case 1:
return mlPoweredJsQueryPacks[0].version || "latest";
case 0:
return "false";
default:
return "multiple";
if (mlPoweredJsQueryPacks.length === 0) {
return "false";
}
const firstVersionString = mlPoweredJsQueryPacks[0].version;
if (
mlPoweredJsQueryPacks.length === 1 &&
firstVersionString &&
ML_POWERED_JS_QUERIES_REPORTABLE_VERSIONS.has(firstVersionString)
) {
return firstVersionString;
}
return "other";
}

0 comments on commit c95a3d8

Please sign in to comment.