-
Notifications
You must be signed in to change notification settings - Fork 360
chore(datastreams): separate DSM specific test behavior and add to CODEOWNERS #7076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robcarlan-datadog
wants to merge
12
commits into
master
Choose a base branch
from
rob.carlan/DSMON-1162-dsm-test-ownership
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,845
−1,448
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8bad5bb
simple migration of DSM test behavior to datastreams folder
robcarlan-datadog 18620c0
remove avro & protobufjs from codeowners (temp)
robcarlan-datadog 7807377
move tests to dsm.spec.js
robcarlan-datadog b2404b8
fix linting
robcarlan-datadog 709d156
fix some tests
robcarlan-datadog 0210882
fix dsm tests
robcarlan-datadog c648fe8
update team name
robcarlan-datadog b0b792c
update test:plugins to include additional *.spec.js files
robcarlan-datadog b1f4d26
revert queue name change for DSM
robcarlan-datadog fefa398
fix ahh bug
robcarlan-datadog 339f97a
fix another llm ahh bug
robcarlan-datadog 3253660
Merge branch 'master' into rob.carlan/DSMON-1162-dsm-test-ownership
robcarlan-datadog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,281 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
| const { Buffer } = require('node:buffer') | ||
|
|
||
| const { afterEach, beforeEach, describe, it } = require('mocha') | ||
|
|
||
| const { computePathwayHash } = require('../../dd-trace/src/datastreams/pathway') | ||
| const { ENTRY_PARENT_HASH } = require('../../dd-trace/src/datastreams/processor') | ||
| const id = require('../../dd-trace/src/id') | ||
| const agent = require('../../dd-trace/test/plugins/agent') | ||
| const { withVersions } = require('../../dd-trace/test/setup/mocha') | ||
| const { assertObjectContains } = require('../../../integration-tests/helpers') | ||
|
|
||
| describe('Plugin', () => { | ||
| let connection | ||
| let channel | ||
| let queue | ||
|
|
||
| describe('amqplib', () => { | ||
| withVersions('amqplib', 'amqplib', version => { | ||
| beforeEach(() => { | ||
| process.env.DD_DATA_STREAMS_ENABLED = 'true' | ||
| queue = `test-${id()}` | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| connection.close() | ||
| }) | ||
|
|
||
| describe('data stream monitoring', function () { | ||
| this.timeout(10000) | ||
|
|
||
| let expectedProducerHashWithTopic | ||
| let expectedProducerHashWithExchange | ||
| let expectedConsumerHash | ||
|
|
||
| beforeEach(done => { | ||
| agent.load('amqplib').then(() => { | ||
| require(`../../../versions/amqplib@${version}`).get('amqplib/callback_api') | ||
| .connect((err, conn) => { | ||
| connection = conn | ||
|
|
||
| if (err != null) { | ||
| return done(err) | ||
| } | ||
|
|
||
| conn.createChannel((err, ch) => { | ||
| channel = ch | ||
| return done(err) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| return agent.close({ ritmReset: false }) | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| const producerHashWithTopic = computePathwayHash('test', 'tester', [ | ||
| 'direction:out', | ||
| 'has_routing_key:true', | ||
| `topic:${queue}`, | ||
| 'type:rabbitmq' | ||
| ], ENTRY_PARENT_HASH) | ||
|
|
||
| expectedProducerHashWithTopic = producerHashWithTopic.readBigUInt64LE(0).toString() | ||
|
|
||
| expectedProducerHashWithExchange = computePathwayHash('test', 'tester', [ | ||
| 'direction:out', | ||
| 'exchange:namedExchange', | ||
| 'has_routing_key:true', | ||
| 'type:rabbitmq' | ||
| ], ENTRY_PARENT_HASH).readBigUInt64LE(0).toString() | ||
|
|
||
| expectedConsumerHash = computePathwayHash('test', 'tester', [ | ||
| 'direction:in', | ||
| `topic:${queue}`, | ||
| 'type:rabbitmq' | ||
| ], producerHashWithTopic).readBigUInt64LE(0).toString() | ||
| }) | ||
|
|
||
| it('Should emit DSM stats to the agent when sending a message on an unnamed exchange', done => { | ||
| agent.expectPipelineStats(dsmStats => { | ||
| let statsPointsReceived = [] | ||
| // we should have 1 dsm stats points | ||
| dsmStats.forEach((timeStatsBucket) => { | ||
| if (timeStatsBucket && timeStatsBucket.Stats) { | ||
| timeStatsBucket.Stats.forEach((statsBuckets) => { | ||
| statsPointsReceived = statsPointsReceived.concat(statsBuckets.Stats) | ||
| }) | ||
| } | ||
| }) | ||
| assert.ok(statsPointsReceived.length >= 1) | ||
| assert.deepStrictEqual(statsPointsReceived[0].EdgeTags, [ | ||
| 'direction:out', | ||
| 'has_routing_key:true', | ||
| `topic:${queue}`, | ||
| 'type:rabbitmq' | ||
| ]) | ||
| assert.strictEqual(agent.dsmStatsExist(agent, expectedProducerHashWithTopic), true) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
|
|
||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('DSM pathway test')) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should emit DSM stats to the agent when sending a message on an named exchange', done => { | ||
| agent.expectPipelineStats(dsmStats => { | ||
| let statsPointsReceived = [] | ||
| // we should have 1 dsm stats points | ||
| dsmStats.forEach((timeStatsBucket) => { | ||
| if (timeStatsBucket && timeStatsBucket.Stats) { | ||
| timeStatsBucket.Stats.forEach((statsBuckets) => { | ||
| statsPointsReceived = statsPointsReceived.concat(statsBuckets.Stats) | ||
| }) | ||
| } | ||
| }) | ||
| assert.ok(statsPointsReceived.length >= 1) | ||
| assert.deepStrictEqual(statsPointsReceived[0].EdgeTags, [ | ||
| 'direction:out', | ||
| 'exchange:namedExchange', | ||
| 'has_routing_key:true', | ||
| 'type:rabbitmq' | ||
| ]) | ||
| assert.strictEqual(agent.dsmStatsExist(agent, expectedProducerHashWithExchange), true) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
|
|
||
| channel.assertExchange('namedExchange', 'direct', {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.publish('namedExchange', 'anyOldRoutingKey', Buffer.from('DSM pathway test')) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should emit DSM stats to the agent when receiving a message', done => { | ||
| agent.expectPipelineStats(dsmStats => { | ||
| let statsPointsReceived = [] | ||
| // we should have 2 dsm stats points | ||
| dsmStats.forEach((timeStatsBucket) => { | ||
| if (timeStatsBucket && timeStatsBucket.Stats) { | ||
| timeStatsBucket.Stats.forEach((statsBuckets) => { | ||
| statsPointsReceived = statsPointsReceived.concat(statsBuckets.Stats) | ||
| }) | ||
| } | ||
| }) | ||
| assert.strictEqual(statsPointsReceived.length, 2) | ||
| assert.deepStrictEqual(statsPointsReceived[1].EdgeTags, | ||
| ['direction:in', `topic:${queue}`, 'type:rabbitmq']) | ||
| assert.strictEqual(agent.dsmStatsExist(agent, expectedConsumerHash), true) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
|
|
||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('DSM pathway test')) | ||
| channel.consume(ok.queue, () => {}, {}, (err, ok) => { | ||
| if (err) done(err) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should emit DSM stats to the agent when sending another message', done => { | ||
| agent.expectPipelineStats(dsmStats => { | ||
| let statsPointsReceived = [] | ||
| // we should have 1 dsm stats points | ||
| dsmStats.forEach((timeStatsBucket) => { | ||
| if (timeStatsBucket && timeStatsBucket.Stats) { | ||
| timeStatsBucket.Stats.forEach((statsBuckets) => { | ||
| statsPointsReceived = statsPointsReceived.concat(statsBuckets.Stats) | ||
| }) | ||
| } | ||
| }) | ||
| assert.strictEqual(statsPointsReceived.length, 1) | ||
| assert.deepStrictEqual(statsPointsReceived[0].EdgeTags, [ | ||
| 'direction:out', | ||
| 'has_routing_key:true', | ||
| `topic:${queue}`, | ||
| 'type:rabbitmq' | ||
| ]) | ||
| assert.strictEqual(agent.dsmStatsExist(agent, expectedProducerHashWithTopic), true) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
|
|
||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('DSM pathway test')) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should emit DSM stats to the agent when receiving a message with get', done => { | ||
| agent.expectPipelineStats(dsmStats => { | ||
| let statsPointsReceived = [] | ||
| // we should have 2 dsm stats points | ||
| dsmStats.forEach((timeStatsBucket) => { | ||
| if (timeStatsBucket && timeStatsBucket.Stats) { | ||
| timeStatsBucket.Stats.forEach((statsBuckets) => { | ||
| statsPointsReceived = statsPointsReceived.concat(statsBuckets.Stats) | ||
| }) | ||
| } | ||
| }) | ||
| assert.strictEqual(statsPointsReceived.length, 2) | ||
| assert.deepStrictEqual(statsPointsReceived[1].EdgeTags, | ||
| ['direction:in', `topic:${queue}`, 'type:rabbitmq']) | ||
| assert.strictEqual(agent.dsmStatsExist(agent, expectedConsumerHash), true) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
|
|
||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('DSM pathway test')) | ||
| channel.get(ok.queue, {}, (err, ok) => { | ||
| if (err) done(err) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('regression test: should handle basic.get when queue is empty', done => { | ||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.get(ok.queue, {}, (err, msg) => { | ||
| if (err) return done(err) | ||
| assert.strictEqual(msg, false) | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should set pathway hash tag on a span when producing', (done) => { | ||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('dsm test')) | ||
|
|
||
| let produceSpanMeta = {} | ||
| agent.assertSomeTraces(traces => { | ||
| const span = traces[0][0] | ||
|
|
||
| if (span.resource.startsWith('basic.publish')) { | ||
| produceSpanMeta = span.meta | ||
| } | ||
|
|
||
| assertObjectContains(produceSpanMeta, { | ||
| 'pathway.hash': expectedProducerHashWithTopic | ||
| }) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
| }) | ||
| }) | ||
|
|
||
| it('Should set pathway hash tag on a span when consuming', (done) => { | ||
| channel.assertQueue(queue, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| channel.sendToQueue(ok.queue, Buffer.from('dsm test')) | ||
| channel.consume(ok.queue, () => {}, {}, (err, ok) => { | ||
| if (err) return done(err) | ||
|
|
||
| let consumeSpanMeta = {} | ||
| agent.assertSomeTraces(traces => { | ||
| const span = traces[0][0] | ||
|
|
||
| if (span.resource.startsWith('basic.deliver')) { | ||
| consumeSpanMeta = span.meta | ||
| } | ||
|
|
||
| assertObjectContains(consumeSpanMeta, { | ||
| 'pathway.hash': expectedConsumerHash | ||
| }) | ||
| }, { timeoutMs: 10000 }).then(done, done) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so i.e.
SPEC=sqswill still testsqs.dsm.spec.js, which is consistent with how this would work if SPEC wasn't set.