-
Notifications
You must be signed in to change notification settings - Fork 227
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
chore: add TAV tests for mongoose #3408
Conversation
/test tav mongoose |
It seems TAV tests did not run after my command. Running it locally it errors with node v18 and mongoose v6.11.1. Logs attached
|
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 looks good, but you say that TAV tests are still failing? I assume you want to dig into those before merging, right?
|
||
test('Mongoose simple test', async function (t) { | ||
resetAgent(5, function (data) { | ||
console.log(data) |
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.
Debugging code to remove eventually?
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.
Yes!
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.
/test tav mongoose
The difference with mine at #3408 (review) is the
(Also we'd had a case where tav-command did not run this past week because of permissions issues. However, it seems to be working this time, so I'm not sure what is/was going on with permissions. /cc @cachedout My tav-command attempt worked on this PR this time.) |
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.
/test tav mongoose
Likewise for node v16 and mongoose v6.11.1. |
Looking at the latest TAV errors (from https://github.com/elastic/apm-agent-nodejs/actions/runs/5203925913?pr=3408), two suggestions:
|
…ub.com:elastic/apm-agent-nodejs into dluna/3161-mongoose-spans-in-wrong-transaction
This change is introduced in
By looking at the shape of the command it seems an internal operation to close the session with the DB. Its always present but I prefer to do like the test in
|
@@ -23,6 +23,7 @@ | |||
"memcached", | |||
"mongodb", | |||
"mongodb-core", | |||
"mongoose", |
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 puts us at 34 * 7 = 238 combinations, so still under the 256 GH actions jobs limit. All good.
await mongoose.disconnect() | ||
trans.end() | ||
|
||
await promisify(agent.flush.bind(agent))().then(function (err) { |
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.
Actually, I believe you can just await agent.flush()
.
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.
you're right. removing promisify
t.ok(subtypeOk, 'spans subtype') | ||
|
||
// TODO: there seems to be situations where create is sent after insert, seems to be internal to the pacakge | ||
// narrowed the problem to v6. v5 and v7 have the spans in order always |
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.
I'm fine with having the test just assert that all the spans are there and not requiring the order to be as expected... with a comment here saying why.
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.
I thought so since the order is internal to mongoose
package but it's alway nice to have a second opinion :)
// we normalize it | ||
t.equal(spans[2].name.replace('.remove', '.delete'), 'elasticapm.tests.delete', 'span.name') | ||
} else { | ||
t.equal(spans[0].name, 'elasticapm.tests.create', 'span.name') |
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.
Do we know the versions for which we expect the create
span?
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.
I did some checks and seems that v6.0.6
introduced that command
// TODO: there seems to be situations where create is sent after insert, seems to be internal to the pacakge | ||
// narrowed the problem to v6. v5 and v7 have the spans in order always | ||
console.log(data.spans) | ||
if (spans.length < 5) { |
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.
Perhaps it would be clearer to explicitly mention and filter out the admin.*
spans.
It looks like all the tests with |
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.
/test tav mongoose
dev-utils/gen-notice.sh
Outdated
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.
Now that mongoose is in devDeps, I think the change in this file can be dropped as well.
Thanks for the example. Although were not instrumenting mongoose directly do you think it's possible show a warning in this situation? |
TAV tests reveal there is an error instrumenting mongoose on a certain combination of versions
Here's the test output > [email protected] test:tav /Users/david/Documents/repos/el/apm-agent-nodejs
> (cd test/opentelemetry-metrics/fixtures && tav --quiet) && (cd test/opentelemetry-bridge && tav --quiet) && (cd test/instrumentation/modules/next/a-nextjs-app && tav --quiet) && tav --quiet
-- ok
-- ok
-- ok
-- required packages ["[email protected]"]
-- installing ["[email protected]"]
-- running test "node test/instrumentation/modules/mongoose.test.js" with mongoose
-- required packages ["[email protected]"]
-- installing ["[email protected]"]
-- running test "node test/instrumentation/modules/mongoose.test.js" with mongoose
(node:82390) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
-- detected failing command, flushing stdout...
{"log.level":"info","@timestamp":"2023-06-09T18:30:17.582Z","log":{"logger":"elastic-apm-node"},"agentVersion":"3.46.0","env":{"pid":82390,"proctitle":"node","os":"darwin 22.5.0","arch":"x64","host":"Davids-MBP.home","timezone":"UTC+0200","runtime":"Node.js v10.24.1"},"config":{"serviceName":{"source":"start","value":"test-mongoose","commonName":"service_name"},"serviceVersion":{"source":"default","value":"3.46.0","commonName":"service_version"},"serverUrl":{"source":"default","value":"http://127.0.0.1:8200/","commonName":"server_url"},"logLevel":{"source":"default","value":"info","commonName":"log_level"},"captureExceptions":{"source":"start","value":false},"metricsInterval":{"source":"start","value":0},"centralConfig":{"source":"start","value":false},"cloudProvider":{"source":"start","value":"none"},"spanCompressionEnabled":{"source":"start","value":false}},"activationMethod":"require","ecs":{"version":"1.6.0"},"message":"Elastic APM Node.js Agent v3.46.0"}
TAP version 13
# Mongoose simple test
ok 1 no error from agent.flush()
ok 2 transaction.name
ok 3 spans parent_id
ok 4 spans subtype
ok 5 insert span present
ok 6 find span present
not ok 7 delete span present
---
operator: ok
expected: true
actual: false
at: <anonymous> (/Users/david/Documents/repos/el/apm-agent-nodejs/test/instrumentation/modules/mongoose.test.js:97:7)
stack: |-
Error: delete span present
at Test.assert [as _assert] (/Users/david/Documents/repos/el/apm-agent-nodejs/node_modules/tape/lib/test.js:312:48)
at Test.bound [as _assert] (/Users/david/Documents/repos/el/apm-agent-nodejs/node_modules/tape/lib/test.js:95:17)
at Test.assert (/Users/david/Documents/repos/el/apm-agent-nodejs/node_modules/tape/lib/test.js:431:7)
at Test.bound [as ok] (/Users/david/Documents/repos/el/apm-agent-nodejs/node_modules/tape/lib/test.js:95:17)
at /Users/david/Documents/repos/el/apm-agent-nodejs/test/instrumentation/modules/mongoose.test.js:97:7
at process._tickCallback (internal/process/next_tick.js:68:7)
...
1..7
# tests 7
# pass 6
# fail 1 A bit of debugging reveals the |
This does not explain #3161 then right? That user said they are using
I agree that we do not need to spend time debugging such an old version. |
I think that would require either instrumenting mongoose (too much added code just for this warning) or putting the warning in the mongodb instrumentation (if that is appropriate). |
await mongoose.disconnect() | ||
trans.end() | ||
|
||
await agent.flush.bind(agent)().then(function (err) { |
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 could be:
await agent.flush()
// ... then dedent the following code that was in the `.then(...)` callback.
Fine with me. It would be nice to have a separate commit that:
|
Commit in #3653 |
Description
Adding a new test for
mongoose
package and updatetav.yml
file accordingly. With this new test were going to check the switch frommongodb-core
tomongodb
as dependency doesn't affect the instrumentation and also we will have checks on the versions we claim to support in the docs.Refs: #3161
Checklist