GeezerVison is showing github.com — Merge pull request #3358 from github/henrymercer/database-upload-tele… · github/codeql-action@5eb7519
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/analyze-action.js +33-10Lines changed: 33 additions & 10 deletions Collapse file Copy file name to clipboardExpand all lines: src/analyze-action.ts +16-8Lines changed: 16 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,10 @@ import { runAutobuild } from "./autobuild"; | 20 | 20 | import { getTotalCacheSize, shouldStoreCache } from "./caching-utils"; | 21 | 21 | import { getCodeQL } from "./codeql"; | 22 | 22 | import { Config, getConfig } from "./config-utils"; | 23 | | -import { cleanupAndUploadDatabases } from "./database-upload"; | | 23 | +import { | | 24 | + cleanupAndUploadDatabases, | | 25 | + DatabaseUploadResult, | | 26 | +} from "./database-upload"; | 24 | 27 | import { | 25 | 28 | DependencyCacheUploadStatusReport, | 26 | 29 | uploadDependencyCaches, | @@ -54,15 +57,13 @@ interface AnalysisStatusReport | 54 | 57 | extends uploadLib.UploadStatusReport, | 55 | 58 | QueriesStatusReport {} | 56 | 59 |
| 57 | | -interface DependencyCachingUploadStatusReport { | 58 | | - dependency_caching_upload_results?: DependencyCacheUploadStatusReport; | 59 | | -} | 60 | | - | 61 | 60 | interface FinishStatusReport | 62 | 61 | extends StatusReportBase, | 63 | 62 | DatabaseCreationTimings, | 64 | | - AnalysisStatusReport, | 65 | | - DependencyCachingUploadStatusReport {} | | 63 | + AnalysisStatusReport { | | 64 | + dependency_caching_upload_results?: DependencyCacheUploadStatusReport; | | 65 | + database_upload_results: DatabaseUploadResult[]; | | 66 | +} | 66 | 67 |
| 67 | 68 | interface FinishWithTrapUploadStatusReport extends FinishStatusReport { | 68 | 69 | /** Size of TRAP caches that we uploaded, in bytes. */ | @@ -81,6 +82,7 @@ async function sendStatusReport( | 81 | 82 | didUploadTrapCaches: boolean, | 82 | 83 | trapCacheCleanup: TrapCacheCleanupStatusReport | undefined, | 83 | 84 | dependencyCacheResults: DependencyCacheUploadStatusReport | undefined, | | 85 | + databaseUploadResults: DatabaseUploadResult[], | 84 | 86 | logger: Logger, | 85 | 87 | ) { | 86 | 88 | const status = getActionsStatus(error, stats?.analyze_failure_language); | @@ -101,6 +103,7 @@ async function sendStatusReport( | 101 | 103 | ...(dbCreationTimings || {}), | 102 | 104 | ...(trapCacheCleanup || {}), | 103 | 105 | dependency_caching_upload_results: dependencyCacheResults, | | 106 | + database_upload_results: databaseUploadResults, | 104 | 107 | }; | 105 | 108 | if (config && didUploadTrapCaches) { | 106 | 109 | const trapCacheUploadStatusReport: FinishWithTrapUploadStatusReport = { | @@ -218,6 +221,7 @@ async function run() { | 218 | 221 | let dbCreationTimings: DatabaseCreationTimings | undefined = undefined; | 219 | 222 | let didUploadTrapCaches = false; | 220 | 223 | let dependencyCacheResults: DependencyCacheUploadStatusReport | undefined; | | 224 | + let databaseUploadResults: DatabaseUploadResult[] = []; | 221 | 225 | util.initializeEnvironment(actionsUtil.getActionVersion()); | 222 | 226 |
| 223 | 227 | // Make inputs accessible in the `post` step, details at | @@ -389,7 +393,7 @@ async function run() { | 389 | 393 | // Possibly upload the database bundles for remote queries. | 390 | 394 | // Note: Take care with the ordering of this call since databases may be cleaned up | 391 | 395 | // at the `overlay` or `clear` level. | 392 | | - await cleanupAndUploadDatabases( | | 396 | + databaseUploadResults = await cleanupAndUploadDatabases( | 393 | 397 | repositoryNwo, | 394 | 398 | codeql, | 395 | 399 | config, | @@ -461,6 +465,7 @@ async function run() { | 461 | 465 | didUploadTrapCaches, | 462 | 466 | trapCacheCleanupTelemetry, | 463 | 467 | dependencyCacheResults, | | 468 | + databaseUploadResults, | 464 | 469 | logger, | 465 | 470 | ); | 466 | 471 | return; | @@ -483,6 +488,7 @@ async function run() { | 483 | 488 | didUploadTrapCaches, | 484 | 489 | trapCacheCleanupTelemetry, | 485 | 490 | dependencyCacheResults, | | 491 | + databaseUploadResults, | 486 | 492 | logger, | 487 | 493 | ); | 488 | 494 | } else if (runStats !== undefined) { | @@ -496,6 +502,7 @@ async function run() { | 496 | 502 | didUploadTrapCaches, | 497 | 503 | trapCacheCleanupTelemetry, | 498 | 504 | dependencyCacheResults, | | 505 | + databaseUploadResults, | 499 | 506 | logger, | 500 | 507 | ); | 501 | 508 | } else { | @@ -509,6 +516,7 @@ async function run() { | 509 | 516 | didUploadTrapCaches, | 510 | 517 | trapCacheCleanupTelemetry, | 511 | 518 | dependencyCacheResults, | | 519 | + databaseUploadResults, | 512 | 520 | logger, | 513 | 521 | ); | 514 | 522 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/database-upload.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -231,7 +231,7 @@ test("Don't crash if uploading a database fails", async (t) => { | 231 | 231 | (v) => | 232 | 232 | v.type === "warning" && | 233 | 233 | v.message === | 234 | | - "Failed to upload database for javascript: Error: some error message", | | 234 | + "Failed to upload database for javascript: some error message", | 235 | 235 | ) !== undefined, | 236 | 236 | ); | 237 | 237 | }); | |
Collapse file Copy file name to clipboardExpand all lines: src/database-upload.ts +43-11Lines changed: 43 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,29 +13,43 @@ import { RepositoryNwo } from "./repository"; | 13 | 13 | import * as util from "./util"; | 14 | 14 | import { bundleDb, CleanupLevel, parseGitHubUrl } from "./util"; | 15 | 15 |
| | 16 | +/** Information about a database upload. */ | | 17 | +export interface DatabaseUploadResult { | | 18 | + /** Language of the database. */ | | 19 | + language: string; | | 20 | + /** Size of the zipped database in bytes. */ | | 21 | + zipped_upload_size_bytes?: number; | | 22 | + /** Whether the uploaded database is an overlay base. */ | | 23 | + is_overlay_base?: boolean; | | 24 | + /** Time taken to upload database in milliseconds. */ | | 25 | + upload_duration_ms?: number; | | 26 | + /** If there was an error during database upload, this is its message. */ | | 27 | + error?: string; | | 28 | +} | | 29 | + | 16 | 30 | export async function cleanupAndUploadDatabases( | 17 | 31 | repositoryNwo: RepositoryNwo, | 18 | 32 | codeql: CodeQL, | 19 | 33 | config: Config, | 20 | 34 | apiDetails: GitHubApiDetails, | 21 | 35 | features: FeatureEnablement, | 22 | 36 | logger: Logger, | 23 | | -): Promise<void> { | | 37 | +): Promise<DatabaseUploadResult[]> { | 24 | 38 | if (actionsUtil.getRequiredInput("upload-database") !== "true") { | 25 | 39 | logger.debug("Database upload disabled in workflow. Skipping upload."); | 26 | | - return; | | 40 | + return []; | 27 | 41 | } | 28 | 42 |
| 29 | 43 | if (!config.analysisKinds.includes(AnalysisKind.CodeScanning)) { | 30 | 44 | logger.debug( | 31 | 45 | `Not uploading database because 'analysis-kinds: ${AnalysisKind.CodeScanning}' is not enabled.`, | 32 | 46 | ); | 33 | | - return; | | 47 | + return []; | 34 | 48 | } | 35 | 49 |
| 36 | 50 | if (util.isInTestMode()) { | 37 | 51 | logger.debug("In test mode. Skipping database upload."); | 38 | | - return; | | 52 | + return []; | 39 | 53 | } | 40 | 54 |
| 41 | 55 | // Do nothing when not running against github.com | @@ -44,20 +58,22 @@ export async function cleanupAndUploadDatabases( | 44 | 58 | config.gitHubVersion.type !== util.GitHubVariant.GHEC_DR | 45 | 59 | ) { | 46 | 60 | logger.debug("Not running against github.com or GHEC-DR. Skipping upload."); | 47 | | - return; | | 61 | + return []; | 48 | 62 | } | 49 | 63 |
| 50 | 64 | if (!(await gitUtils.isAnalyzingDefaultBranch())) { | 51 | 65 | // We only want to upload a database if we are analyzing the default branch. | 52 | 66 | logger.debug("Not analyzing default branch. Skipping upload."); | 53 | | - return; | | 67 | + return []; | 54 | 68 | } | 55 | 69 |
| 56 | | - const cleanupLevel = | | 70 | + // If config.overlayDatabaseMode is OverlayBase, then we have overlay base databases for all languages. | | 71 | + const shouldUploadOverlayBase = | 57 | 72 | config.overlayDatabaseMode === OverlayDatabaseMode.OverlayBase && | 58 | | - (await features.getValue(Feature.UploadOverlayDbToApi)) | 59 | | - ? CleanupLevel.Overlay | 60 | | - : CleanupLevel.Clear; | | 73 | + (await features.getValue(Feature.UploadOverlayDbToApi)); | | 74 | + const cleanupLevel = shouldUploadOverlayBase | | 75 | + ? CleanupLevel.Overlay | | 76 | + : CleanupLevel.Clear; | 61 | 77 |
| 62 | 78 | // Clean up the database, since intermediate results may still be written to the | 63 | 79 | // database if there is high RAM pressure. | @@ -77,6 +93,7 @@ export async function cleanupAndUploadDatabases( | 77 | 93 | uploadsBaseUrl = uploadsBaseUrl.slice(0, -1); | 78 | 94 | } | 79 | 95 |
| | 96 | + const reports: DatabaseUploadResult[] = []; | 80 | 97 | for (const language of config.languages) { | 81 | 98 | try { | 82 | 99 | // Upload the database bundle. | @@ -90,6 +107,7 @@ export async function cleanupAndUploadDatabases( | 90 | 107 | actionsUtil.getRequiredInput("checkout_path"), | 91 | 108 | ); | 92 | 109 | try { | | 110 | + const startTime = performance.now(); | 93 | 111 | await client.request( | 94 | 112 | `POST /repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name&commit_oid=:commit_oid`, | 95 | 113 | { | @@ -107,13 +125,27 @@ export async function cleanupAndUploadDatabases( | 107 | 125 | }, | 108 | 126 | }, | 109 | 127 | ); | | 128 | + const endTime = performance.now(); | | 129 | + reports.push({ | | 130 | + language, | | 131 | + zipped_upload_size_bytes: bundledDbSize, | | 132 | + is_overlay_base: shouldUploadOverlayBase, | | 133 | + upload_duration_ms: endTime - startTime, | | 134 | + }); | 110 | 135 | logger.debug(`Successfully uploaded database for ${language}`); | 111 | 136 | } finally { | 112 | 137 | bundledDbReadStream.close(); | 113 | 138 | } | 114 | 139 | } catch (e) { | 115 | 140 | // Log a warning but don't fail the workflow | 116 | | - logger.warning(`Failed to upload database for ${language}: ${e}`); | | 141 | + logger.warning( | | 142 | + `Failed to upload database for ${language}: ${util.getErrorMessage(e)}`, | | 143 | + ); | | 144 | + reports.push({ | | 145 | + language, | | 146 | + error: util.getErrorMessage(e), | | 147 | + }); | 117 | 148 | } | 118 | 149 | } | | 150 | + return reports; | 119 | 151 | } |
|