diff --git a/.github/actions/testagent/logs/action.yml b/.github/actions/testagent/logs/action.yml index 070e35d19f2..bb80d251848 100644 --- a/.github/actions/testagent/logs/action.yml +++ b/.github/actions/testagent/logs/action.yml @@ -15,3 +15,26 @@ runs: docker-compose logs testagent fi shell: bash + - name: Get Tested Integrations from Test Agent + run: | + # make temporary files to save response data to + response=$(mktemp) && headers=$(mktemp) + + # create artifacts directory if it doesn't exist + mkdir -p "./artifacts" + + # get tested integrations + curl -o "$response" -D "$headers" http://127.0.0.1:9126/test/integrations/tested_versions + + # get filename representing the name of the tested integration from headers + filename=$(awk -F': ' '/file-name/{print $2}' "$headers" | tr -d '\r\n') + + # copy data to final file and remove temp files + mv "$response" "artifacts/${filename}_supported_versions.csv" + rm "$headers" + shell: bash + - name: Archive Test Agent Artifacts + uses: actions/upload-artifact@v3 + with: + name: supported-integrations + path: ./artifacts diff --git a/docker-compose.yml b/docker-compose.yml index ef86aab2730..ec9a519fde6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -128,7 +128,7 @@ services: - LDAP_PASSWORDS=password1,password2 testagent: - image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest + image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:v1.13.1 ports: - "127.0.0.1:9126:9126" environment: diff --git a/packages/dd-trace/test/plugins/agent.js b/packages/dd-trace/test/plugins/agent.js index 953312190b4..06c41d77731 100644 --- a/packages/dd-trace/test/plugins/agent.js +++ b/packages/dd-trace/test/plugins/agent.js @@ -16,6 +16,7 @@ let agent = null let listener = null let tracer = null let plugins = [] +const testedPlugins = [] function isMatchingTrace (spans, spanResourceMatch) { if (!spanResourceMatch) { @@ -37,15 +38,33 @@ function ciVisRequestHandler (request, response) { function addEnvironmentVariablesToHeaders (headers) { // get all environment variables that start with "DD_" - const ddEnvVars = Object.entries(process.env) - .filter(([key]) => key.startsWith('DD_')) - .map(([key, value]) => `${key}=${value}`) + const ddEnvVars = new Map( + Object.entries(process.env) + .filter(([key]) => key.startsWith('DD_')) + ) + + // add plugin name and plugin version to headers, this is used for verifying tested + // integration version ranges + const currentPlugin = testedPlugins[testedPlugins.length - 1] + if (currentPlugin && currentPlugin.pluginName && currentPlugin.pluginVersion) { + ddEnvVars.set('DD_INTEGRATION', currentPlugin.pluginName) + ddEnvVars.set('DD_INTEGRATION_VERSION', currentPlugin.pluginVersion) + } // add the DD environment variables to the header if any exist // to send with trace to final agent destination if (ddEnvVars.length > 0) { headers['X-Datadog-Trace-Env-Variables'] = ddEnvVars.join(',') } + + // serialize the DD environment variables into a string of k=v pairs separated by comma + const serializedEnvVars = Array.from(ddEnvVars.entries()) + .map(([key, value]) => `${key}=${value}`) + .join(',') + + // add the serialized DD environment variables to the header + // to send with trace to the final agent destination + headers['X-Datadog-Trace-Env-Variables'] = serializedEnvVars } function handleTraceRequest (req, res, sendToTestAgent) { @@ -333,5 +352,7 @@ module.exports = { .forEach(name => { delete require.cache[name] }) - } + }, + + testedPlugins } diff --git a/packages/dd-trace/test/setup/mocha.js b/packages/dd-trace/test/setup/mocha.js index ba076ebcbaf..840684761a5 100644 --- a/packages/dd-trace/test/setup/mocha.js +++ b/packages/dd-trace/test/setup/mocha.js @@ -18,6 +18,8 @@ global.withExports = withExports global.withNamingSchema = withNamingSchema global.withPeerService = withPeerService +const testedPlugins = agent.testedPlugins + const packageVersionFailures = Object.create({}) function loadInst (plugin) { @@ -216,6 +218,13 @@ function withVersions (plugin, modules, range, cb) { let nodePath before(() => { + // set plugin name and version to later report to test agent regarding tested integrations and + // their tested range of versions + const lastPlugin = testedPlugins[testedPlugins.length - 1] + if (!lastPlugin || lastPlugin.pluginName !== plugin || lastPlugin.pluginVersion !== v.version) { + testedPlugins.push({ pluginName: plugin, pluginVersion: v.version }) + } + nodePath = process.env.NODE_PATH process.env.NODE_PATH = [process.env.NODE_PATH, versionPath] .filter(x => x && x !== 'undefined')