Skip to content

Commit 31bfb99

Browse files
committed
Do not use stringified objects for dependency caching telemetry
1 parent ed57767 commit 31bfb99

File tree

8 files changed

+36
-49
lines changed

8 files changed

+36
-49
lines changed

lib/analyze-action.js

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface AnalysisStatusReport
5959
QueriesStatusReport {}
6060

6161
interface DependencyCachingUploadStatusReport {
62-
dependency_caching_upload_results?: string;
62+
dependency_caching_upload_results?: DependencyCacheUploadStatusReport;
6363
}
6464

6565
interface FinishStatusReport
@@ -104,9 +104,7 @@ async function sendStatusReport(
104104
...(stats || {}),
105105
...(dbCreationTimings || {}),
106106
...(trapCacheCleanup || {}),
107-
dependency_caching_upload_results: JSON.stringify(
108-
dependencyCacheResults ?? {},
109-
),
107+
dependency_caching_upload_results: dependencyCacheResults,
110108
};
111109
if (config && didUploadTrapCaches) {
112110
const trapCacheUploadStatusReport: FinishWithTrapUploadStatusReport = {

src/dependency-caching.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,13 @@ export enum CacheHitKind {
9999

100100
/** Represents results of trying to restore a dependency cache for a language. */
101101
export interface DependencyCacheRestoreStatus {
102+
language: Language;
102103
hit_kind: CacheHitKind;
103104
download_duration_ms?: number;
104105
}
105106

106107
/** A partial mapping from languages to the results of restoring dependency caches for them. */
107-
export type DependencyCacheRestoreStatusReport = Partial<
108-
Record<Language, DependencyCacheRestoreStatus>
109-
>;
108+
export type DependencyCacheRestoreStatusReport = DependencyCacheRestoreStatus[];
110109

111110
/**
112111
* Attempts to restore dependency caches for the languages being analyzed.
@@ -121,7 +120,7 @@ export async function downloadDependencyCaches(
121120
logger: Logger,
122121
minimizeJavaJars: boolean,
123122
): Promise<DependencyCacheRestoreStatusReport> {
124-
const status: DependencyCacheRestoreStatusReport = {};
123+
const status: DependencyCacheRestoreStatusReport = [];
125124

126125
for (const language of languages) {
127126
const cacheConfig = getDefaultCacheConfig()[language];
@@ -138,7 +137,7 @@ export async function downloadDependencyCaches(
138137
const globber = await makeGlobber(cacheConfig.hash);
139138

140139
if ((await globber.glob()).length === 0) {
141-
status[language] = { hit_kind: CacheHitKind.NoHash };
140+
status.push({ language, hit_kind: CacheHitKind.NoHash });
142141
logger.info(
143142
`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`,
144143
);
@@ -168,12 +167,9 @@ export async function downloadDependencyCaches(
168167
logger.info(`Cache hit on key ${hitKey} for ${language}.`);
169168
const hit_kind =
170169
hitKey === primaryKey ? CacheHitKind.Exact : CacheHitKind.Partial;
171-
status[language] = {
172-
hit_kind,
173-
download_duration_ms,
174-
};
170+
status.push({ language, hit_kind, download_duration_ms });
175171
} else {
176-
status[language] = { hit_kind: CacheHitKind.Miss };
172+
status.push({ language, hit_kind: CacheHitKind.Miss });
177173
logger.info(`No suitable cache found for ${language}.`);
178174
}
179175
}
@@ -195,15 +191,14 @@ export enum CacheStoreResult {
195191

196192
/** Represents results of trying to upload a dependency cache for a language. */
197193
export interface DependencyCacheUploadStatus {
194+
language: Language;
198195
result: CacheStoreResult;
199196
upload_size_bytes?: number;
200197
upload_duration_ms?: number;
201198
}
202199

203200
/** A partial mapping from languages to the results of uploading dependency caches for them. */
204-
export type DependencyCacheUploadStatusReport = Partial<
205-
Record<Language, DependencyCacheUploadStatus>
206-
>;
201+
export type DependencyCacheUploadStatusReport = DependencyCacheUploadStatus[];
207202

208203
/**
209204
* Attempts to store caches for the languages that were analyzed.
@@ -219,7 +214,7 @@ export async function uploadDependencyCaches(
219214
logger: Logger,
220215
minimizeJavaJars: boolean,
221216
): Promise<DependencyCacheUploadStatusReport> {
222-
const status: DependencyCacheUploadStatusReport = {};
217+
const status: DependencyCacheUploadStatusReport = [];
223218
for (const language of config.languages) {
224219
const cacheConfig = getDefaultCacheConfig()[language];
225220

@@ -235,7 +230,7 @@ export async function uploadDependencyCaches(
235230
const globber = await makeGlobber(cacheConfig.hash);
236231

237232
if ((await globber.glob()).length === 0) {
238-
status[language] = { result: CacheStoreResult.NoHash };
233+
status.push({ language, result: CacheStoreResult.NoHash });
239234
logger.info(
240235
`Skipping upload of dependency cache for ${language} as we cannot calculate a hash for the cache key.`,
241236
);
@@ -256,7 +251,7 @@ export async function uploadDependencyCaches(
256251

257252
// Skip uploading an empty cache.
258253
if (size === 0) {
259-
status[language] = { result: CacheStoreResult.Empty };
254+
status.push({ language, result: CacheStoreResult.Empty });
260255
logger.info(
261256
`Skipping upload of dependency cache for ${language} since it is empty.`,
262257
);
@@ -274,11 +269,12 @@ export async function uploadDependencyCaches(
274269
await actionsCache.saveCache(cacheConfig.paths, key);
275270
const upload_duration_ms = Math.round(performance.now() - start);
276271

277-
status[language] = {
272+
status.push({
273+
language,
278274
result: CacheStoreResult.Stored,
279275
upload_size_bytes: Math.round(size),
280276
upload_duration_ms,
281-
};
277+
});
282278
} catch (error) {
283279
// `ReserveCacheError` indicates that the cache key is already in use, which means that a
284280
// cache with that key already exists or is in the process of being uploaded by another
@@ -289,7 +285,7 @@ export async function uploadDependencyCaches(
289285
);
290286
logger.debug(error.message);
291287

292-
status[language] = { result: CacheStoreResult.Duplicate };
288+
status.push({ language, result: CacheStoreResult.Duplicate });
293289
} else {
294290
// Propagate other errors upwards.
295291
throw error;

src/init-action-post-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CodeScanning } from "./analyses";
88
import { getApiClient } from "./api-client";
99
import { CodeQL, getCodeQL } from "./codeql";
1010
import { Config } from "./config-utils";
11+
import * as dependencyCaching from "./dependency-caching";
1112
import { EnvVar } from "./environment";
1213
import { Feature, FeatureEnablement } from "./feature-flags";
1314
import { Logger } from "./logging";
@@ -46,7 +47,7 @@ export interface JobStatusReport {
4647
}
4748

4849
export interface DependencyCachingUsageReport {
49-
dependency_caching_usage?: string;
50+
dependency_caching_usage?: dependencyCaching.DependencyCachingUsageReport;
5051
}
5152

5253
function createFailedUploadFailedSarifResult(

src/init-action-post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function runWrapper() {
128128
...statusReportBase,
129129
...uploadFailedSarifResult,
130130
job_status: initActionPostHelper.getFinalJobStatus(),
131-
dependency_caching_usage: JSON.stringify(dependencyCachingUsage ?? {}),
131+
dependency_caching_usage: dependencyCachingUsage,
132132
};
133133
logger.info("Sending status report for init-post step.");
134134
await sendStatusReport(statusReport);

src/status-report.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export interface InitWithConfigStatusReport extends InitStatusReport {
499499
/** Time taken to download the overlay-base database, in milliseconds. */
500500
overlay_base_database_download_duration_ms?: number;
501501
/** Stringified JSON object representing information about the results of restoring dependency caches. */
502-
dependency_caching_restore_results: string;
502+
dependency_caching_restore_results?: DependencyCacheRestoreStatusReport;
503503
/** Stringified JSON array of registry configuration objects, from the 'registries' config field
504504
or workflow input. **/
505505
registries: string;
@@ -574,9 +574,7 @@ export async function createInitWithConfigStatusReport(
574574
overlayBaseDatabaseStats?.databaseSizeBytes,
575575
overlay_base_database_download_duration_ms:
576576
overlayBaseDatabaseStats?.databaseDownloadDurationMs,
577-
dependency_caching_restore_results: JSON.stringify(
578-
dependencyCachingResults ?? {},
579-
),
577+
dependency_caching_restore_results: dependencyCachingResults,
580578
query_filters: JSON.stringify(
581579
config.originalUserInput["query-filters"] ?? [],
582580
),

0 commit comments

Comments
 (0)