From c0b2da92f2987e383c2038d14867a1b82205159b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Fri, 23 Jun 2023 20:09:22 +0200 Subject: [PATCH] [ci-visibility] More verbose logging for git upload (#3251) --- .../src/ci-visibility/exporters/git/git_metadata.js | 12 ++++++++++++ packages/dd-trace/src/plugins/util/exec.js | 2 ++ packages/dd-trace/src/plugins/util/git.js | 12 ++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js b/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js index 0b658b5fa8d..856f5f23792 100644 --- a/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +++ b/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js @@ -48,6 +48,9 @@ function getCommonRequestOptions (url) { */ function getCommitsToExclude ({ url, isEvpProxy, repositoryUrl }, callback) { const latestCommits = getLatestCommits() + + log.debug(`There were ${latestCommits.length} commits since last month.`) + const [headCommit] = latestCommits const commonOptions = getCommonRequestOptions(url) @@ -158,11 +161,14 @@ function sendGitMetadata (url, isEvpProxy, configRepositoryUrl, callback) { repositoryUrl = getRepositoryUrl() } + log.debug(`Uploading git history for repository ${repositoryUrl}`) + if (!repositoryUrl) { return callback(new Error('Repository URL is empty')) } if (isShallowRepository()) { + log.debug('It is shallow clone, unshallowing...') unshallowRepository() } @@ -170,14 +176,20 @@ function sendGitMetadata (url, isEvpProxy, configRepositoryUrl, callback) { if (err) { return callback(err) } + log.debug(`There are ${commitsToExclude.length} commits to exclude.`) + const commitsToUpload = getCommitsToUpload(commitsToExclude) if (!commitsToUpload.length) { log.debug('No commits to upload') return callback(null) } + log.debug(`There are ${commitsToUpload.length} commits to upload`) + const packFilesToUpload = generatePackFilesForCommits(commitsToUpload) + log.debug(`Uploading ${packFilesToUpload.length} packfiles.`) + if (!packFilesToUpload.length) { return callback(new Error('Failed to generate packfiles')) } diff --git a/packages/dd-trace/src/plugins/util/exec.js b/packages/dd-trace/src/plugins/util/exec.js index d55127d8b17..a2d091232c6 100644 --- a/packages/dd-trace/src/plugins/util/exec.js +++ b/packages/dd-trace/src/plugins/util/exec.js @@ -1,9 +1,11 @@ const cp = require('child_process') +const log = require('../../log') const sanitizedExec = (cmd, flags, options = { stdio: 'pipe' }) => { try { return cp.execFileSync(cmd, flags, options).toString().replace(/(\r\n|\n|\r)/gm, '') } catch (e) { + log.error(e) return '' } } diff --git a/packages/dd-trace/src/plugins/util/git.js b/packages/dd-trace/src/plugins/util/git.js index 59143ea1031..84ceec17208 100644 --- a/packages/dd-trace/src/plugins/util/git.js +++ b/packages/dd-trace/src/plugins/util/git.js @@ -36,12 +36,8 @@ function isShallowRepository () { } function unshallowRepository () { - try { - sanitizedExec('git', ['config', 'remote.origin.partialclonefilter', '"blob:none"']) - sanitizedExec('git', ['fetch', '--shallow-since="1 month ago"', '--update-shallow', '--refetch']) - } catch (err) { - log.error(err) - } + sanitizedExec('git', ['config', 'remote.origin.partialclonefilter', '"blob:none"']) + sanitizedExec('git', ['fetch', '--shallow-since="1 month ago"', '--update-shallow', '--refetch']) } function getRepositoryUrl () { @@ -55,7 +51,7 @@ function getLatestCommits () { .split('\n') .filter(commit => commit) } catch (err) { - log.error(err) + log.error(`Get latest commits failed: ${err.message}`) return [] } } @@ -80,7 +76,7 @@ function getCommitsToUpload (commitsToExclude) { .split('\n') .filter(commit => commit) } catch (err) { - log.error(err) + log.error(`Get commits to upload failed: ${err.message}`) return [] } }