-
Notifications
You must be signed in to change notification settings - Fork 451
Cache first failure building an overlay base DB to avoid repeated failures #3487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d1bdc0e
d28d996
69c2819
e275d63
ebad062
96961e0
827bba6
6c405c2
0c47ae1
7b7a951
ef58c00
cc0dce0
d24014a
3dd1275
554b931
5c583bb
05d4e25
657f337
fa56ea8
898ae16
4191f52
4e71011
1847416
dc00a6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import test from "ava"; | ||
|
|
||
| import { mockCodeQLVersion, setupTests } from "../testing-utils"; | ||
| import { DiskUsage } from "../util"; | ||
|
|
||
| import { getCacheKey } from "./status"; | ||
|
|
||
| setupTests(test); | ||
|
|
||
| function makeDiskUsage(totalGiB: number): DiskUsage { | ||
| return { | ||
| numTotalBytes: totalGiB * 1024 * 1024 * 1024, | ||
| numAvailableBytes: 0, | ||
| }; | ||
| } | ||
|
|
||
| test("getCacheKey incorporates language, CodeQL version, and disk space", async (t) => { | ||
| const codeql = mockCodeQLVersion("2.20.0"); | ||
| t.is( | ||
| await getCacheKey(codeql, "javascript", makeDiskUsage(50)), | ||
| "codeql-overlay-status-javascript-2.20.0-runner-50GB", | ||
| ); | ||
| t.is( | ||
| await getCacheKey(codeql, "python", makeDiskUsage(50)), | ||
| "codeql-overlay-status-python-2.20.0-runner-50GB", | ||
| ); | ||
| t.is( | ||
| await getCacheKey( | ||
| mockCodeQLVersion("2.21.0"), | ||
| "javascript", | ||
| makeDiskUsage(50), | ||
| ), | ||
| "codeql-overlay-status-javascript-2.21.0-runner-50GB", | ||
| ); | ||
| t.is( | ||
| await getCacheKey(codeql, "javascript", makeDiskUsage(100)), | ||
| "codeql-overlay-status-javascript-2.20.0-runner-100GB", | ||
| ); | ||
| }); | ||
|
|
||
| test("getCacheKey rounds disk space down to nearest 10 GiB", async (t) => { | ||
| const codeql = mockCodeQLVersion("2.20.0"); | ||
| t.is( | ||
| await getCacheKey(codeql, "javascript", makeDiskUsage(14)), | ||
| "codeql-overlay-status-javascript-2.20.0-runner-10GB", | ||
| ); | ||
| t.is( | ||
| await getCacheKey(codeql, "javascript", makeDiskUsage(19)), | ||
| "codeql-overlay-status-javascript-2.20.0-runner-10GB", | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * We perform enablement checks for overlay analysis to avoid using it on runners that are too small | ||
| * to support it. However these checks cannot avoid every potential issue without being overly | ||
| * conservative. Therefore, if our enablement checks enable overlay analysis for a runner that is | ||
| * too small, we want to remember that, so that we will not try to use overlay analysis until | ||
| * something changes (e.g. a larger runner is provisioned, or a new CodeQL version is released). | ||
| * | ||
| * We use the Actions cache as a lightweight way of providing this functionality. | ||
| */ | ||
|
mbg marked this conversation as resolved.
|
||
|
|
||
| import { type CodeQL } from "../codeql"; | ||
| import { DiskUsage } from "../util"; | ||
|
|
||
| export async function getCacheKey( | ||
| codeql: CodeQL, | ||
| language: string, | ||
| diskUsage: DiskUsage, | ||
| ): Promise<string> { | ||
| // Total disk space, rounded to the nearest 10 GB. This is included in the cache key so that if a | ||
| // customer upgrades their runner, we will try again to use overlay analysis, even if the CodeQL | ||
| // version has not changed. We round to the nearest 10 GB to work around small differences in disk | ||
| // space. | ||
| // | ||
| // Limitation: this can still flip from "too small" to "large enough" and back again if the disk | ||
| // space fluctuates above and below a multiple of 10 GB. | ||
| const diskSpaceToNearest10Gb = `${10 * Math.floor(diskUsage.numTotalBytes / (10 * 1024 * 1024 * 1024))}GB`; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Design question: this fundamentally assumes that the CodeQL analysis typically runs on comparable runners. I.e. the assumption is that unless the amount of total disk space is increased deliberately, the runner specs are the same. Practically speaking, I'd expect that to be the case as well. However, I am not sure whether it is necessarily the case or this is an assumption we have made previously. My concern is that, if a customer has a runner group for CodeQL containing runners with different specs, we might flip-flop on this -- I think you express that in the "Limitation" part of the comment. That wouldn't be a great experience for a customer if it happened. Is there a way we can mitigate this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, this might be something that's worth checking in telemetry before rolling this out. |
||
|
|
||
| // Include the CodeQL version in the cache key so we will try again to use overlay analysis when | ||
| // new queries and libraries that may be more efficient are released. | ||
| return `codeql-overlay-status-${language}-${(await codeql.getVersion()).version}-runner-${diskSpaceToNearest10Gb}`; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.