Skip to content
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.

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

[test optimization] Configuration parameter to disable git unshallow #5291

Merged
merged 7 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ class CiVisibilityExporter extends AgentInfoExporter {
log.debug('Successfully uploaded git metadata')
}
this._resolveGit(err)
}
},
this._config.isTestUnshallowEnabled
)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function generateAndUploadPackFiles ({
/**
* This function uploads git metadata to CI Visibility's backend.
*/
function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryUrl, callback) {
function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryUrl, callback, isUnshallowEnabled) {
if (!isGitAvailable()) {
return callback(new Error('Git is not available'))
}
Expand Down Expand Up @@ -284,7 +284,9 @@ function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryU
}
// Otherwise we unshallow and get commits to upload again
log.debug('It is shallow clone, unshallowing...')
unshallowRepository()
if (isUnshallowEnabled) {
unshallowRepository()
}

// The latest commits change after unshallowing
latestCommits = getLatestCommits()
Expand Down
5 changes: 4 additions & 1 deletion packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class Config {
this._setValue(defaults, 'isTestDynamicInstrumentationEnabled', false)
this._setValue(defaults, 'isServiceUserProvided', false)
this._setValue(defaults, 'testManagementAttemptToFixRetries', 20)
this._setValue(defaults, 'isTestUnshallowEnabled', true)
this._setValue(defaults, 'isTestManagementEnabled', false)
this._setValue(defaults, 'logInjection', false)
this._setValue(defaults, 'lookup', undefined)
Expand Down Expand Up @@ -1146,7 +1147,8 @@ class Config {
DD_AGENTLESS_LOG_SUBMISSION_ENABLED,
DD_TEST_DYNAMIC_INSTRUMENTATION_ENABLED,
DD_TEST_MANAGEMENT_ENABLED,
DD_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES
DD_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES,
DD_TEST_UNSHALLOW_ENABLED
Copy link
Collaborator

@juan-fernandez juan-fernandez Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED so as to align with Java.

Also: let me think if we need to go through the config changes. Maybe we can check process.env.DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED directly in the git code, as I see no advantage in adding it to the config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed!

} = process.env

if (DD_CIVISIBILITY_AGENTLESS_URL) {
Expand All @@ -1171,6 +1173,7 @@ class Config {
'testManagementAttemptToFixRetries',
coalesce(maybeInt(DD_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES), 20)
)
this._setBoolean(calc, 'isTestUnshallowEnabled', !isFalse(DD_TEST_UNSHALLOW_ENABLED))
}
this._setString(calc, 'dogstatsd.hostname', this._getHostname())
this._setBoolean(calc, 'isGitUploadEnabled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('git_metadata', () => {
let isShallowRepositoryStub
let unshallowRepositoryStub

let isUnshallowEnabled

before(() => {
process.env.DD_API_KEY = 'api-key'
fs.writeFileSync(temporaryPackFile, '')
Expand All @@ -47,6 +49,8 @@ describe('git_metadata', () => {
isShallowRepositoryStub = sinon.stub().returns(false)
unshallowRepositoryStub = sinon.stub()

isUnshallowEnabled = true

generatePackFilesForCommitsStub = sinon.stub().returns([temporaryPackFile])

gitMetadata = proxyquire('../../../../src/ci-visibility/exporters/git/git_metadata', {
Expand Down Expand Up @@ -76,7 +80,8 @@ describe('git_metadata', () => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should unshallow if the repo is shallow and not every commit is in the backend', (done) => {
Expand All @@ -94,7 +99,28 @@ describe('git_metadata', () => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should not unshallow if the parameter to enable unshallow is false', (done) => {
isUnshallowEnabled = false
const scope = nock('https://api.test.com')
.post('/api/v2/git/repository/search_commits')
.reply(200, JSON.stringify({ data: [] }))
.post('/api/v2/git/repository/search_commits') // calls a second time after unshallowing
.reply(200, JSON.stringify({ data: [] }))
.post('/api/v2/git/repository/packfile')
.reply(204)

isShallowRepositoryStub.returns(true)
gitMetadata.sendGitMetadata(new URL('https://api.test.com'), { isEvpProxy: false }, '', (err) => {
expect(unshallowRepositoryStub).not.to.have.been.called
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
},
isUnshallowEnabled)
})

it('should request to /api/v2/git/repository/search_commits and /api/v2/git/repository/packfile', (done) => {
Expand All @@ -108,7 +134,8 @@ describe('git_metadata', () => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should not request to /api/v2/git/repository/packfile if the backend has the commit info', (done) => {
Expand All @@ -126,7 +153,8 @@ describe('git_metadata', () => {
expect(scope.isDone()).to.be.false
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
done()
})
},
isUnshallowEnabled)
})

it('should fail and not continue if first query results in anything other than 200', (done) => {
Expand All @@ -143,7 +171,8 @@ describe('git_metadata', () => {
expect(scope.isDone()).to.be.false
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
done()
})
},
isUnshallowEnabled)
})

it('should fail and not continue if the response are not correct commits', (done) => {
Expand All @@ -159,7 +188,8 @@ describe('git_metadata', () => {
expect(scope.isDone()).to.be.false
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
done()
})
},
isUnshallowEnabled)
})

it('should fail and not continue if the response are badly formatted commits', (done) => {
Expand All @@ -175,7 +205,8 @@ describe('git_metadata', () => {
expect(scope.isDone()).to.be.false
expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile')
done()
})
},
isUnshallowEnabled)
})

it('should fail if the packfile request returns anything other than 204', (done) => {
Expand All @@ -189,7 +220,8 @@ describe('git_metadata', () => {
expect(err.message).to.contain('Could not upload packfiles: status code 502')
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should fail if the getCommitsRevList fails because the repository is too big', (done) => {
Expand All @@ -203,7 +235,8 @@ describe('git_metadata', () => {
expect(err.message).to.contain('git rev-list failed')
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should fire a request per packfile', (done) => {
Expand All @@ -230,7 +263,8 @@ describe('git_metadata', () => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

describe('validateGitRepositoryUrl', () => {
Expand Down Expand Up @@ -305,7 +339,8 @@ describe('git_metadata', () => {
expect(err.message).to.contain('Could not read "not-there"')
expect(scope.isDone()).to.be.false
done()
})
},
isUnshallowEnabled)
})

it('should not crash if generatePackFiles returns an empty array', (done) => {
Expand All @@ -321,7 +356,8 @@ describe('git_metadata', () => {
expect(err.message).to.contain('Failed to generate packfiles')
expect(scope.isDone()).to.be.false
done()
})
},
isUnshallowEnabled)
})

it('should not crash if git is missing', (done) => {
Expand All @@ -340,7 +376,8 @@ describe('git_metadata', () => {
expect(scope.isDone()).to.be.false
process.env.PATH = oldPath
done()
})
},
isUnshallowEnabled)
})

it('should retry if backend temporarily fails', (done) => {
Expand All @@ -358,7 +395,8 @@ describe('git_metadata', () => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
},
isUnshallowEnabled)
})

it('should append evp proxy prefix if configured', (done) => {
Expand All @@ -378,7 +416,8 @@ describe('git_metadata', () => {
(err) => {
expect(err).to.be.null
expect(scope.isDone()).to.be.true
})
},
isUnshallowEnabled)
})

it('should use the input repository url and not call getRepositoryUrl', (done) => {
Expand Down Expand Up @@ -408,6 +447,7 @@ describe('git_metadata', () => {
expect(repositoryUrl).to.equal('https://[email protected]')
done()
})
})
},
isUnshallowEnabled)
})
})
Loading