Skip to content

Commit

Permalink
report tested integrations and their tested versions (#3669)
Browse files Browse the repository at this point in the history
Add tracking of supported integrations and supported integration versions and output data as artifacts during testing
  • Loading branch information
wconti27 authored and khanayan123 committed Jan 2, 2024
1 parent 5b41c84 commit 88216cc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .github/actions/testagent/logs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 25 additions & 4 deletions packages/dd-trace/test/plugins/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let agent = null
let listener = null
let tracer = null
let plugins = []
const testedPlugins = []

function isMatchingTrace (spans, spanResourceMatch) {
if (!spanResourceMatch) {
Expand All @@ -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) {
Expand Down Expand Up @@ -333,5 +352,7 @@ module.exports = {
.forEach(name => {
delete require.cache[name]
})
}
},

testedPlugins
}
9 changes: 9 additions & 0 deletions packages/dd-trace/test/setup/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ global.withExports = withExports
global.withNamingSchema = withNamingSchema
global.withPeerService = withPeerService

const testedPlugins = agent.testedPlugins

const packageVersionFailures = Object.create({})

function loadInst (plugin) {
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 88216cc

Please sign in to comment.