Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
19075c4
Overlay: report overlay analysis mode
cklin Jul 18, 2025
e37b293
Overlay: report overlay-base database stats
cklin Jul 18, 2025
c3bbcab
Add downloadOverlayBaseDatabaseFromCache tests
cklin Jul 17, 2025
39b0524
build: refresh js files
cklin Jul 18, 2025
df82387
Update changelog and version after v3.29.3
github-actions[bot] Jul 21, 2025
b195e1b
Update checked-in dependencies
github-actions[bot] Jul 21, 2025
a7cb1b8
Add changelog entry for v3.28.20 backport
koesie10 Jul 21, 2025
8e442bc
Merge pull request #2978 from github/mergeback/v3.29.3-to-main-d6bbdef4
koesie10 Jul 21, 2025
b633287
Merge pull request #2979 from github/koesie10/v3.28.20-changelog
koesie10 Jul 21, 2025
eefe1b5
Merge pull request #2975 from github/cklin/overlay-telemetry
cklin Jul 21, 2025
20477a3
Bump ruby/setup-ruby from 1.245.0 to 1.247.0 in the actions group
dependabot[bot] Jul 21, 2025
b7a5452
Bump the npm group with 5 updates
dependabot[bot] Jul 21, 2025
4749491
Update checked-in dependencies
github-actions[bot] Jul 21, 2025
48ce740
Update combining SARIF runs changelog post URL
koesie10 Jul 22, 2025
2b952be
Update workflow template
mbg Jul 22, 2025
9e7d13d
Merge pull request #2983 from github/koesie10/update-changelog-link
mbg Jul 22, 2025
76bf77d
Merge pull request #2980 from github/dependabot/github_actions/action…
mbg Jul 22, 2025
8f2e636
Merge pull request #2981 from github/dependabot/npm_and_yarn/npm-fe13…
mbg Jul 23, 2025
43afe6e
Treat processing error for multiple runs with the same category as co…
mbg Jul 23, 2025
287d421
Disable combining runs within a single file
koesie10 Jul 23, 2025
5a2327a
Merge pull request #2987 from github/mbg/combine-sarif-error
mbg Jul 23, 2025
5a29823
Merge remote-tracking branch 'origin/main' into koesie10/disable-comb…
koesie10 Jul 23, 2025
37264dc
Merge pull request #2988 from github/koesie10/disable-combine-single-…
koesie10 Jul 23, 2025
b3114b8
Update changelog for v3.29.4
github-actions[bot] Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Overlay: report overlay-base database stats
  • Loading branch information
cklin committed Jul 18, 2025
commit e37b293334be08308a49bc95fc999bbbb27bb1f8
22 changes: 19 additions & 3 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { Language } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import {
downloadOverlayBaseDatabaseFromCache,
OverlayBaseDatabaseDownloadStats,
OverlayDatabaseMode,
} from "./overlay-database-utils";
import { getRepositoryNwo } from "./repository";
Expand Down Expand Up @@ -107,6 +108,10 @@ interface InitWithConfigStatusReport extends InitStatusReport {
trap_cache_download_size_bytes: number;
/** Time taken to download TRAP caches, in milliseconds. */
trap_cache_download_duration_ms: number;
/** Size of the overlay-base database that we downloaded, in bytes. */
overlay_base_database_download_size_bytes?: number;
/** Time taken to download the overlay-base database, in milliseconds. */
overlay_base_database_download_duration_ms?: number;
/** Stringified JSON array of registry configuration objects, from the 'registries' config field
or workflow input. **/
registries: string;
Expand Down Expand Up @@ -134,6 +139,7 @@ async function sendCompletedStatusReport(
toolsFeatureFlagsValid: boolean | undefined,
toolsSource: ToolsSource,
toolsVersion: string,
overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined,
logger: Logger,
error?: Error,
) {
Expand Down Expand Up @@ -237,6 +243,10 @@ async function sendCompletedStatusReport(
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime),
overlay_base_database_download_size_bytes:
overlayBaseDatabaseStats?.databaseSizeBytes,
overlay_base_database_download_duration_ms:
overlayBaseDatabaseStats?.databaseDownloadDurationMs,
query_filters: JSON.stringify(
config.originalUserInput["query-filters"] ?? [],
),
Expand Down Expand Up @@ -400,6 +410,7 @@ async function run() {
return;
}

let overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined;
try {
if (
config.augmentationProperties.overlayDatabaseMode ===
Expand All @@ -417,9 +428,12 @@ async function run() {
// necessary preparations. So, in that mode, we would assume that
// everything is in order and let the analysis fail if that turns out not
// to be the case.
const overlayDatabaseDownloaded =
await downloadOverlayBaseDatabaseFromCache(codeql, config, logger);
if (!overlayDatabaseDownloaded) {
overlayBaseDatabaseStats = await downloadOverlayBaseDatabaseFromCache(
codeql,
config,
logger,
);
if (!overlayBaseDatabaseStats) {
config.augmentationProperties.overlayDatabaseMode =
OverlayDatabaseMode.None;
logger.info(
Expand Down Expand Up @@ -729,6 +743,7 @@ async function run() {
toolsFeatureFlagsValid,
toolsSource,
toolsVersion,
overlayBaseDatabaseStats,
logger,
error,
);
Expand All @@ -744,6 +759,7 @@ async function run() {
toolsFeatureFlagsValid,
toolsSource,
toolsVersion,
overlayBaseDatabaseStats,
logger,
);
}
Expand Down
48 changes: 37 additions & 11 deletions src/overlay-database-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type CodeQL } from "./codeql";
import { type Config } from "./config-utils";
import { getCommitOid, getFileOidsUnderPath } from "./git-utils";
import { Logger } from "./logging";
import { isInTestMode, withTimeout } from "./util";
import { isInTestMode, tryGetFolderBytes, withTimeout } from "./util";

export enum OverlayDatabaseMode {
Overlay = "overlay",
Expand Down Expand Up @@ -235,41 +235,47 @@ export async function uploadOverlayBaseDatabaseToCache(
return true;
}

export interface OverlayBaseDatabaseDownloadStats {
databaseSizeBytes: number;
databaseDownloadDurationMs: number;
}

/**
* Downloads the overlay-base database from the GitHub Actions cache. If conditions
* for downloading are not met, the function does nothing and returns false.
*
* @param codeql The CodeQL instance
* @param config The configuration object
* @param logger The logger instance
* @returns A promise that resolves to true if the download was performed and
* successfully completed, or false otherwise
* @returns A promise that resolves to download statistics if an overlay-base
* database was successfully downloaded, or undefined if the download was
* either not performed or failed.
*/
export async function downloadOverlayBaseDatabaseFromCache(
codeql: CodeQL,
config: Config,
logger: Logger,
): Promise<boolean> {
): Promise<OverlayBaseDatabaseDownloadStats | undefined> {
const overlayDatabaseMode = config.augmentationProperties.overlayDatabaseMode;
if (overlayDatabaseMode !== OverlayDatabaseMode.Overlay) {
logger.debug(
`Overlay database mode is ${overlayDatabaseMode}. ` +
"Skip downloading overlay-base database from cache.",
);
return false;
return undefined;
}
if (!config.augmentationProperties.useOverlayDatabaseCaching) {
logger.debug(
"Overlay database caching is disabled. " +
"Skip downloading overlay-base database from cache.",
);
return false;
return undefined;
}
if (isInTestMode()) {
logger.debug(
"In test mode. Skip downloading overlay-base database from cache.",
);
return false;
return undefined;
}

const dbLocation = config.dbLocation;
Expand All @@ -280,18 +286,23 @@ export async function downloadOverlayBaseDatabaseFromCache(
`Looking in Actions cache for overlay-base database with restore key ${restoreKey}`,
);

let databaseDownloadDurationMs = 0;
try {
const databaseDownloadStart = performance.now();
const foundKey = await withTimeout(
MAX_CACHE_OPERATION_MS,
actionsCache.restoreCache([dbLocation], restoreKey),
() => {
logger.info("Timed out downloading overlay-base database from cache");
},
);
databaseDownloadDurationMs = Math.round(
performance.now() - databaseDownloadStart,
);

if (foundKey === undefined) {
logger.info("No overlay-base database found in Actions cache");
return false;
return undefined;
}

logger.info(
Expand All @@ -302,7 +313,7 @@ export async function downloadOverlayBaseDatabaseFromCache(
"Failed to download overlay-base database from cache: " +
`${error instanceof Error ? error.message : String(error)}`,
);
return false;
return undefined;
}

const databaseIsValid = checkOverlayBaseDatabase(
Expand All @@ -312,11 +323,26 @@ export async function downloadOverlayBaseDatabaseFromCache(
);
if (!databaseIsValid) {
logger.warning("Downloaded overlay-base database failed validation");
return false;
return undefined;
}

const databaseSizeBytes = await tryGetFolderBytes(dbLocation, logger);
if (databaseSizeBytes === undefined) {
logger.info(
"Filesystem error while accessing downloaded overlay-base database",
);
// The problem that warrants reporting download failure is not that we are
// unable to determine the size of the database. Rather, it is that we
// encountered a filesystem error while accessing the database, which
// indicates that an overlay analysis will likely fail.
return undefined;
}

logger.info(`Successfully downloaded overlay-base database to ${dbLocation}`);
return true;
return {
databaseSizeBytes: Math.round(databaseSizeBytes),
databaseDownloadDurationMs,
};
}

async function generateCacheKey(
Expand Down