GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add telemetry for dependency caching by mbg · Pull Request #3136 · github/codeql-action

Add telemetry for dependency caching #3136

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.

Sign up for GitHub

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

Merged
mbg merged 9 commits into main from mbg/dep-caching/telemetry
Sep 29, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Add telemetry for dependency caching #3136

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit Hold shift + click to select a range
11480e3
Add telemetry for restoring dependency caches
mbg Sep 23, 2025
249a3cb
Add telemetry for storing dependency caches
mbg Sep 23, 2025
3d7d7c9
Fix comment
mbg Sep 23, 2025
7dfbfdc
Report overall cache usage for CodeQL dependency caches
mbg Sep 23, 2025
2ff902e
Rename `CacheHitResult` and `hit`
mbg Sep 25, 2025
ed57767
Don't measure size of downloaded cache
mbg Sep 25, 2025
31bfb99
Do not use stringified objects for dependency caching telemetry
mbg Sep 25, 2025
e6768a1
Merge branch 'main' into mbg/dep-caching/telemetry
mbg Sep 29, 2025
d44c8b3
Fix comments
mbg Sep 29, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
Add telemetry for restoring dependency caches
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@mbg
mbg committed Sep 23, 2025
commit 11480e326c449cb21c7445fc7ed2b51bba59709b

There are no files selected for viewing

29 changes: 22 additions & 7 deletions 29 lib/init-action.js
Show comments
View file
Open in desktop

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

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

43 changes: 38 additions & 5 deletions 43 src/dependency-caching.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,44 @@ async function makeGlobber(patterns: string[]): Promise<glob.Globber> {
return glob.create(patterns.join("\n"));
}

/** Enumerates possible outcomes for cache hits. */
export enum CacheHitResult {
Comment thread
mbg marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

/** We were unable to calculate a hash for the key. */
NoHash = "no-hash",
/** No cache was found. */
Miss = "miss",
/** The primary cache key matched. */
Exact = "exact",
/** A restore key matched. */
Partial = "partial",
}

/** Represents results of trying to restore a dependency cache for a language. */
export interface DependencyCacheRestoreStatus {
hit: CacheHitResult;
Comment thread
mbg marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

download_size_bytes?: number;
download_duration_ms?: number;
}

/** A partial mapping from languages to the results of restoring dependency caches for them. */
export type DependencyCacheRestoreStatusReport = Partial<
Record<Language, DependencyCacheRestoreStatus>
>;

/**
* Attempts to restore dependency caches for the languages being analyzed.
*
* @param languages The languages being analyzed.
* @param logger A logger to record some informational messages to.
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
* @returns A list of languages for which dependency caches were restored.
* @returns A partial mapping of languages to results of restoring dependency caches for them.
*/
export async function downloadDependencyCaches(
languages: Language[],
logger: Logger,
minimizeJavaJars: boolean,
): Promise<Language[]> {
const restoredCaches: Language[] = [];
): Promise<DependencyCacheRestoreStatusReport> {
const status: DependencyCacheRestoreStatusReport = {};

for (const language of languages) {
const cacheConfig = getDefaultCacheConfig()[language];
Expand All @@ -114,6 +138,7 @@ export async function downloadDependencyCaches(
const globber = await makeGlobber(cacheConfig.hash);

if ((await globber.glob()).length === 0) {
status[language] = { hit: CacheHitResult.NoHash };
logger.info(
`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`,
);
Expand All @@ -131,21 +156,29 @@ export async function downloadDependencyCaches(
)}`,
);

const start = performance.now();
const hitKey = await actionsCache.restoreCache(
cacheConfig.paths,
primaryKey,
restoreKeys,
);
const download_duration_ms = Math.round(performance.now() - start);
const download_size_bytes = Math.round(
await getTotalCacheSize(cacheConfig.paths, logger),
);
Comment thread
mbg marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


Comment thread
mbg marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

if (hitKey !== undefined) {
logger.info(`Cache hit on key ${hitKey} for ${language}.`);
restoredCaches.push(language);
const hit =
hitKey === primaryKey ? CacheHitResult.Exact : CacheHitResult.Partial;
status[language] = { hit, download_duration_ms, download_size_bytes };
} else {
status[language] = { hit: CacheHitResult.Miss };
logger.info(`No suitable cache found for ${language}.`);
}
}

return restoredCaches;
return status;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions 12 src/init-action.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
} from "./caching-utils";
import { CodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { downloadDependencyCaches } from "./dependency-caching";
import {
DependencyCacheRestoreStatusReport,
downloadDependencyCaches,
} from "./dependency-caching";
import {
addDiagnostic,
flushDiagnostics,
Expand Down Expand Up @@ -102,6 +105,7 @@ async function sendCompletedStatusReport(
toolsSource: ToolsSource,
toolsVersion: string,
overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined,
dependencyCachingResults: DependencyCacheRestoreStatusReport | undefined,
logger: Logger,
error?: Error,
) {
Expand Down Expand Up @@ -151,6 +155,7 @@ async function sendCompletedStatusReport(
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
overlayBaseDatabaseStats,
dependencyCachingResults,
);
await sendStatusReport({
...initWithConfigStatusReport,
Expand Down Expand Up @@ -351,6 +356,7 @@ async function run() {
}

let overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined;
let dependencyCachingResults: DependencyCacheRestoreStatusReport | undefined;
try {
if (
config.overlayDatabaseMode === OverlayDatabaseMode.Overlay &&
Expand Down Expand Up @@ -562,7 +568,7 @@ async function run() {
codeql,
);
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
await downloadDependencyCaches(
dependencyCachingResults = await downloadDependencyCaches(
config.languages,
logger,
minimizeJavaJars,
Expand Down Expand Up @@ -714,6 +720,7 @@ async function run() {
toolsSource,
toolsVersion,
overlayBaseDatabaseStats,
dependencyCachingResults,
logger,
error,
);
Expand All @@ -736,6 +743,7 @@ async function run() {
toolsSource,
toolsVersion,
overlayBaseDatabaseStats,
dependencyCachingResults,
logger,
);
}
Expand Down
1 change: 1 addition & 0 deletions 1 src/status-report.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ const testCreateInitWithConfigStatusReport = test.macro({
undefined,
1024,
undefined,
undefined,
);

if (t.truthy(initWithConfigStatusReport)) {
Expand Down
7 changes: 7 additions & 0 deletions 7 src/status-report.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "./actions-util";
import { getAnalysisKey, getApiClient } from "./api-client";
import { parseRegistriesWithoutCredentials, type Config } from "./config-utils";
import { DependencyCacheRestoreStatusReport } from "./dependency-caching";
import { DocUrl } from "./doc-url";
import { EnvVar } from "./environment";
import { getRef } from "./git-utils";
Expand Down Expand Up @@ -497,6 +498,8 @@ export interface InitWithConfigStatusReport extends InitStatusReport {
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 object representing information about the results of restoring dependency caches. */
dependency_caching_restore_results: string;
/** Stringified JSON array of registry configuration objects, from the 'registries' config field
or workflow input. **/
registries: string;
Expand All @@ -522,6 +525,7 @@ export async function createInitWithConfigStatusReport(
configFile: string | undefined,
totalCacheSize: number,
overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined,
dependencyCachingResults: DependencyCacheRestoreStatusReport | undefined,
): Promise<InitWithConfigStatusReport> {
const languages = config.languages.join(",");
const paths = (config.originalUserInput.paths || []).join(",");
Expand Down Expand Up @@ -570,6 +574,9 @@ export async function createInitWithConfigStatusReport(
overlayBaseDatabaseStats?.databaseSizeBytes,
overlay_base_database_download_duration_ms:
overlayBaseDatabaseStats?.databaseDownloadDurationMs,
dependency_caching_restore_results: JSON.stringify(
dependencyCachingResults ?? {},
),
query_filters: JSON.stringify(
config.originalUserInput["query-filters"] ?? [],
),
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.