-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathindex.js
More file actions
108 lines (97 loc) · 3.48 KB
/
Copy pathindex.js
File metadata and controls
108 lines (97 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict'
const AgentWriter = require('../../../exporters/agent/writer')
const AgentlessWriter = require('../agentless/writer')
const CoverageWriter = require('../agentless/coverage-writer')
const CiVisibilityExporter = require('../ci-visibility-exporter')
const { fetchAgentInfo } = require('../../../agent/info')
const { DEBUGGER_INPUT_V1 } = require('../../../debugger/constants')
// TODO: Use the shared utilities in src/evp_proxy when this product migrates its EVP version policy.
const AGENT_EVP_PROXY_PATH_PREFIX = '/evp_proxy/v'
const AGENT_EVP_PROXY_PATH_REGEX = /\/evp_proxy\/v(\d+)\/?/
function getLatestEvpProxyVersion (err, agentInfo) {
if (err) {
return 0
}
return agentInfo.endpoints.reduce((acc, endpoint) => {
if (endpoint.includes(AGENT_EVP_PROXY_PATH_PREFIX)) {
const version = Number(endpoint.replace(AGENT_EVP_PROXY_PATH_REGEX, '$1'))
if (Number.isNaN(version)) {
return acc
}
return Math.max(version, acc)
}
return acc
}, 0)
}
function getCanForwardDebuggerLogs (err, agentInfo) {
return !err && agentInfo.endpoints.includes(DEBUGGER_INPUT_V1)
}
class AgentProxyCiVisibilityExporter extends CiVisibilityExporter {
constructor (config) {
super(config)
const {
tags,
prioritySampler,
lookup,
protocolVersion,
headers,
testOptimization,
} = config
fetchAgentInfo(this._url, (err, agentInfo) => {
this._isInitialized = true
let latestEvpProxyVersion = getLatestEvpProxyVersion(err, agentInfo)
const isEvpCompatible = latestEvpProxyVersion >= 2
this._isGzipCompatible = latestEvpProxyVersion >= 4
// v3 does not work well citestcycle, so we downgrade to v2
if (latestEvpProxyVersion === 3) {
latestEvpProxyVersion = 2
}
const evpProxyPrefix = `${AGENT_EVP_PROXY_PATH_PREFIX}${latestEvpProxyVersion}`
if (isEvpCompatible) {
this._isUsingEvpProxy = true
this.evpProxyPrefix = evpProxyPrefix
this._writer = new AgentlessWriter({
url: this._url,
tags,
evpProxyPrefix,
})
this._coverageWriter = new CoverageWriter({
url: this._url,
evpProxyPrefix,
})
this._codeCoverageReportUrl = this._url
// Screenshot media uploads go through the Agent's evp_proxy: the uploader prefixes the
// path with evpProxyPrefix and sets X-Datadog-EVP-Subdomain: api (see uploadTestScreenshot).
this._testScreenshotUploadUrl = this._url
if (testOptimization.DD_TEST_FAILED_TEST_REPLAY_ENABLED) {
const canFowardLogs = getCanForwardDebuggerLogs(err, agentInfo)
if (canFowardLogs) {
const DynamicInstrumentationLogsWriter = require('../agentless/di-logs-writer')
this._logsWriter = new DynamicInstrumentationLogsWriter({
url: this._url,
isAgentProxy: true,
})
this._canForwardLogs = true
}
}
} else {
this._writer = new AgentWriter({
url: this._url,
prioritySampler,
lookup,
protocolVersion,
headers,
})
// coverages will never be used, so we discard them
this._coverageBuffer = []
}
this._resolveCanUseCiVisProtocol(isEvpCompatible)
this.exportUncodedTraces()
this.exportUncodedCoverages()
})
}
setUrl (url, coverageUrl) {
this._setUrl(url, coverageUrl)
}
}
module.exports = AgentProxyCiVisibilityExporter