Skip to content

Commit

Permalink
handle packages that _need_ to use version ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
bengl committed Dec 14, 2024
1 parent e81e0de commit 8e97cfa
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 23 deletions.
13 changes: 8 additions & 5 deletions packages/datadog-plugin-aws-sdk/test/aws-sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ describe('Plugin', () => {
setup()

withVersions('aws-sdk', ['aws-sdk'], (version) => {
const versionRange = withVersions.range
if (semver.intersects(version, '>2.3.0')) {
const S3 = require(`../../../versions/aws-sdk@${version}`).get('aws-sdk/clients/s3')
const S3 = require(`../../../versions/aws-sdk@${versionRange}`).get('aws-sdk/clients/s3')
const s3 = new S3({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1', s3ForcePathStyle: true })
require('../../dd-trace')
before(() => {
Expand Down Expand Up @@ -68,6 +69,8 @@ describe('Plugin', () => {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let AWS
let s3
let sqs
Expand All @@ -82,7 +85,7 @@ describe('Plugin', () => {
})

before(() => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
AWS = require(`../../../versions/${s3ClientName}@${versionRange}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1', s3ForcePathStyle: true })
tracer = require('../../dd-trace')
})
Expand Down Expand Up @@ -225,7 +228,7 @@ describe('Plugin', () => {
})

before(() => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
AWS = require(`../../../versions/${s3ClientName}@${versionRange}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:5000', region: 'us-east-1', s3ForcePathStyle: true })
tracer = require('../../dd-trace')
})
Expand Down Expand Up @@ -262,8 +265,8 @@ describe('Plugin', () => {
})

before(() => {
const { S3 } = require(`../../../versions/${s3ClientName}@${version}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${version}`).get()
const { S3 } = require(`../../../versions/${s3ClientName}@${versionRange}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

s3 = new S3({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1', s3ForcePathStyle: true })
sqs = new SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
Expand Down
6 changes: 4 additions & 2 deletions packages/datadog-plugin-aws-sdk/test/kinesis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('Kinesis', function () {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let AWS
let kinesis
let tracer
Expand All @@ -21,15 +23,15 @@ describe('Kinesis', function () {
const kinesisClientName = moduleName === '@aws-sdk/smithy-client' ? '@aws-sdk/client-kinesis' : 'aws-sdk'

function createResources (streamName, cb) {
AWS = require(`../../../versions/${kinesisClientName}@${version}`).get()
AWS = require(`../../../versions/${kinesisClientName}@${versionRange}`).get()

const params = {
endpoint: 'http://127.0.0.1:4566',
region: 'us-east-1'
}

if (moduleName === '@aws-sdk/smithy-client') {
const { NodeHttpHandler } = require(`../../../versions/@aws-sdk/node-http-handler@${version}`).get()
const { NodeHttpHandler } = require(`../../../versions/@aws-sdk/node-http-handler@${versionRange}`).get()

params.requestHandler = new NodeHttpHandler()
}
Expand Down
4 changes: 3 additions & 1 deletion packages/datadog-plugin-aws-sdk/test/lambda.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('Plugin', () => {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let AWS
let lambda
let tracer
Expand All @@ -38,7 +40,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${lambdaClientName}@${version}`).get()
AWS = require(`../../../versions/${lambdaClientName}@${versionRange}`).get()

lambda = new AWS.Lambda({ endpoint: 'http://127.0.0.1:4567', region: 'us-east-1' })
lambda.createFunction({
Expand Down
4 changes: 3 additions & 1 deletion packages/datadog-plugin-aws-sdk/test/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('Plugin', () => {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let AWS
let s3
let tracer
Expand All @@ -36,7 +38,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${s3ClientName}@${version}`).get()
AWS = require(`../../../versions/${s3ClientName}@${versionRange}`).get()
s3 = new AWS.S3({ endpoint: 'http://127.0.0.1:4566', s3ForcePathStyle: true, region: 'us-east-1' })

// Fix for LocationConstraint issue - only for SDK v2
Expand Down
6 changes: 4 additions & 2 deletions packages/datadog-plugin-aws-sdk/test/sns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('Sns', function () {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let sns
let sqs
let subParams
Expand Down Expand Up @@ -45,8 +47,8 @@ describe('Sns', function () {
}

function createResources (queueName, topicName, cb) {
const { SNS } = require(`../../../versions/${snsClientName}@${version}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${version}`).get()
const { SNS } = require(`../../../versions/${snsClientName}@${versionRange}`).get()
const { SQS } = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

sns = new SNS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs = new SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
Expand Down
10 changes: 6 additions & 4 deletions packages/datadog-plugin-aws-sdk/test/sqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('Plugin', () => {
setup()

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let AWS
let sqs
const QueueUrl = 'http://127.0.0.1:4566/00000000000000000000/SQS_QUEUE_NAME'
Expand All @@ -49,7 +51,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
AWS = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptions, (err, res) => {
Expand Down Expand Up @@ -314,7 +316,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
AWS = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptions, (err, res) => {
Expand Down Expand Up @@ -405,7 +407,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
AWS = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptionsDsm, (err, res) => {
Expand All @@ -416,7 +418,7 @@ describe('Plugin', () => {
})

before(done => {
AWS = require(`../../../versions/${sqsClientName}@${version}`).get()
AWS = require(`../../../versions/${sqsClientName}@${versionRange}`).get()

sqs = new AWS.SQS({ endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' })
sqs.createQueue(queueOptionsDsmConsumerOnly, (err, res) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/datadog-plugin-aws-sdk/test/stepfunctions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('Sfn', () => {
let tracer

withVersions('aws-sdk', ['aws-sdk', '@aws-sdk/smithy-client'], (version, moduleName) => {
const versionRange = withVersions.range

let stateMachineArn
let client

Expand All @@ -33,7 +35,7 @@ describe('Sfn', () => {
function getClient () {
const params = { endpoint: 'http://127.0.0.1:4566', region: 'us-east-1' }
if (moduleName === '@aws-sdk/smithy-client') {
const lib = require(`../../../versions/@aws-sdk/client-sfn@${version}`).get()
const lib = require(`../../../versions/@aws-sdk/client-sfn@${versionRange}`).get()
const client = new lib.SFNClient(params)
return {
client,
Expand All @@ -55,7 +57,7 @@ describe('Sfn', () => {
}
}
} else {
const { StepFunctions } = require(`../../../versions/aws-sdk@${version}`).get()
const { StepFunctions } = require(`../../../versions/aws-sdk@${versionRange}`).get()
const client = new StepFunctions(params)
return {
client,
Expand Down
11 changes: 9 additions & 2 deletions packages/datadog-plugin-langchain/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { useEnv } = require('../../../integration-tests/helpers')
const agent = require('../../dd-trace/test/plugins/agent')
const { getAllVersionsMatching } = require('../../dd-trace/test/setup/helpers/version-utils')

const nock = require('nock')

Expand Down Expand Up @@ -33,6 +34,7 @@ describe('Plugin', () => {

describe('langchain', () => {
withVersions('langchain', ['@langchain/core'], version => {
const versionRange = withVersions.range
beforeEach(() => {
return agent.load('langchain')
})
Expand All @@ -43,8 +45,13 @@ describe('Plugin', () => {
})

beforeEach(() => {
langchainOpenai = require(`../../../versions/@langchain/openai@${version}`).get()
langchainAnthropic = require(`../../../versions/@langchain/anthropic@${version}`).get()
// TODO these depend on the fact that the openai and anthropic versions
// are in the same range as the core langchain library. That's a
// potential problem.
const openAiVersion = getAllVersionsMatching('@langchain/openai', [versionRange]).pop()
langchainOpenai = require(`../../../versions/@langchain/openai@${openAiVersion}`).get()
const anthropicVersion = getAllVersionsMatching('@langchain/anthropic', [versionRange]).pop()
langchainAnthropic = require(`../../../versions/@langchain/anthropic@${anthropicVersion}`).get()

// need to specify specific import in `get(...)`
langchainMessages = require(`../../../versions/@langchain/core@${version}`).get('@langchain/core/messages')
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/test/setup/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function withVersions (plugin, modules, range, cb) {
require('module').Module._initPaths()
})

withVersions.range = v.range // TODO tests needing this need to be changed to not need it
cb(v.version, moduleName, v.version) // TODO get rid of 3rd param here

after(() => {
Expand Down
18 changes: 14 additions & 4 deletions scripts/install_plugin_modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ async function assertVersions () {
}

async function assertInstrumentation (instrumentation, external) {
const versions = getIdeallyTestedVersions(instrumentation.name, instrumentation.versions)

for (const entry of versions) {
await assertModules(instrumentation.name, entry.version, external)
const [first, ...rest] = getIdeallyTestedVersions(instrumentation.name, instrumentation.versions)
const last = rest.pop()
await assertModules(instrumentation.name, first.version, external)
await assertModules(instrumentation.name, last.version, external)

// This symlink should be unnecessary, but some tests use it to grab
// "compatible" versions of instrumented support libraries. This is an
// incorrect way to do it, but it work for modules where this is necessary.
// This is, of course, very fragile.
// Affected modules: langchain, aws-sdk
// TODO Have a better way to handle this for those modules.
const dest = folder(instrumentation.name, instrumentation.versions)
if (!fs.existsSync(dest)) {
fs.symlinkSync(folder(instrumentation.name, last.version), dest)
}
}

Expand Down

0 comments on commit 8e97cfa

Please sign in to comment.