-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci-visibility] Add get known tests request (#4015)
- Loading branch information
1 parent
165b340
commit d28f33e
Showing
7 changed files
with
309 additions
and
5 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const request = require('../../exporters/common/request') | ||
const id = require('../../id') | ||
const log = require('../../log') | ||
|
||
function getKnownTests ({ | ||
url, | ||
isEvpProxy, | ||
evpProxyPrefix, | ||
isGzipCompatible, | ||
env, | ||
service, | ||
repositoryUrl, | ||
sha, | ||
osVersion, | ||
osPlatform, | ||
osArchitecture, | ||
runtimeName, | ||
runtimeVersion, | ||
custom | ||
}, done) { | ||
const options = { | ||
path: '/api/v2/ci/libraries/tests', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
timeout: 20000, | ||
url | ||
} | ||
|
||
if (isGzipCompatible) { | ||
options.headers['accept-encoding'] = 'gzip' | ||
} | ||
|
||
if (isEvpProxy) { | ||
options.path = `${evpProxyPrefix}/api/v2/ci/libraries/tests` | ||
options.headers['X-Datadog-EVP-Subdomain'] = 'api' | ||
} else { | ||
const apiKey = process.env.DATADOG_API_KEY || process.env.DD_API_KEY | ||
if (!apiKey) { | ||
return done(new Error('Skippable suites were not fetched because Datadog API key is not defined.')) | ||
} | ||
|
||
options.headers['dd-api-key'] = apiKey | ||
} | ||
|
||
const data = JSON.stringify({ | ||
data: { | ||
id: id().toString(10), | ||
type: 'ci_app_libraries_tests_request', | ||
attributes: { | ||
configurations: { | ||
'os.platform': osPlatform, | ||
'os.version': osVersion, | ||
'os.architecture': osArchitecture, | ||
'runtime.name': runtimeName, | ||
'runtime.version': runtimeVersion, | ||
custom | ||
}, | ||
service, | ||
env, | ||
repository_url: repositoryUrl, | ||
sha | ||
} | ||
} | ||
}) | ||
|
||
request(data, options, (err, res) => { | ||
if (err) { | ||
done(err) | ||
} else { | ||
try { | ||
const { data: { attributes: { test_full_names: knownTests } } } = JSON.parse(res) | ||
log.debug(() => `Number of received known tests: ${Object.keys(knownTests).length}`) | ||
done(null, knownTests) | ||
} catch (err) { | ||
done(err) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { getKnownTests } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.