Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ tasks:
type: setup
params:
updates:
- { key: NPM_VERSION, value: "9" }
- { key: NODE_VERSION, value: "22" }
- func: "install dependencies"
- command: ec2.assume_role
params:
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ tasks:
type: setup
params:
updates:
- {key: NPM_VERSION, value: '9'}
- {key: NODE_VERSION, value: '22'}
- func: install dependencies
- command: ec2.assume_role
params:
Expand Down
4 changes: 3 additions & 1 deletion .evergreen/prepare-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export PATH="$MONGODB_BINARIES:$PATH"

if [ ! -d "$DRIVERS_TOOLS" ]; then
# Only clone driver tools if it does not exist
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
git clone "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
git -C "${DRIVERS_TOOLS}" fetch -a
git -C "${DRIVERS_TOOLS}" switch NODE-6839-lambda-timeout
fi

echo "installed DRIVERS_TOOLS from commit $(git -C "${DRIVERS_TOOLS}" rev-parse HEAD)"
Expand Down
60 changes: 32 additions & 28 deletions test/lambda/mongodb/app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import * as assert from 'node:assert/strict';
/* eslint-disable no-console */
import util from 'node:util';

import { MongoClient } from 'mongodb';

// Creates the client that is cached for all requests, subscribes to
// relevant events, and forces the connection pool to get populated.
const mongoClient = new MongoClient(process.env.MONGODB_URI, {
monitorCommands: true
monitorCommands: true,
mongodbLogComponentSeverities: {
command: 'trace',
topology: 'trace',
connection: 'trace',
default: 'trace'
},
mongodbLogMaxDocumentLength: 10_000,
mongodbLogPath: {
write(log) {
console.log(
util.inspect(log, { colors: false, breakLength: Infinity, compact: true, depth: Infinity })
);
}
}
});

let openConnections = 0;
Expand All @@ -14,49 +29,38 @@ let totalHeartbeatDuration = 0;
let totalCommands = 0;
let totalCommandDuration = 0;

mongoClient.on('commandStarted', (event) => {
console.log('commandStarted', event);
});

mongoClient.on('commandSucceeded', (event) => {
mongoClient.on('commandSucceeded', event => {
totalCommands++;
totalCommandDuration += event.duration;
console.log('commandSucceeded', event);
});

mongoClient.on('commandFailed', (event) => {
mongoClient.on('commandFailed', event => {
totalCommands++;
totalCommandDuration += event.duration;
console.log('commandFailed', event);
});

mongoClient.on('serverHeartbeatStarted', (event) => {
console.log('serverHeartbeatStarted', event);
assert.strictEqual(event.awaited, false);
mongoClient.on('serverHeartbeatStarted', event => {
if (event.awaited !== false) console.log('server hb started', { awaited: event.awaited });
});

mongoClient.on('serverHeartbeatSucceeded', (event) => {
mongoClient.on('serverHeartbeatSucceeded', event => {
heartbeatCount++;
totalHeartbeatDuration += event.duration;
console.log('serverHeartbeatSucceeded', event);
assert.strictEqual(event.awaited, false);
if (event.awaited !== false) console.log('server hb succeeded', { awaited: event.awaited });
});

mongoClient.on('serverHeartbeatFailed', (event) => {
mongoClient.on('serverHeartbeatFailed', event => {
heartbeatCount++;
totalHeartbeatDuration += event.duration;
console.log('serverHeartbeatFailed', event);
assert.strictEqual(event.awaited, false);
if (event.awaited !== false) console.log('server hb failed', { awaited: event.awaited });
});

mongoClient.on('connectionCreated', (event) => {
mongoClient.on('connectionCreated', () => {
openConnections++;
console.log('connectionCreated', event);
});

mongoClient.on('connectionClosed', (event) => {
mongoClient.on('connectionClosed', () => {
openConnections--;
console.log('connectionClosed', event);
});

// Populate the connection pool.
Expand All @@ -65,8 +69,8 @@ await mongoClient.connect();
// Create the response to send back.
function createResponse() {
return {
averageCommandDuration: totalCommandDuration / totalCommands,
averageHeartbeatDuration: totalHeartbeatDuration / heartbeatCount,
averageCommandDuration: totalCommands === 0 ? 0 : totalCommandDuration / totalCommands,
averageHeartbeatDuration: heartbeatCount === 0 ? 0 : totalHeartbeatDuration / heartbeatCount,
openConnections: openConnections,
heartbeatCount: heartbeatCount
};
Expand All @@ -85,10 +89,10 @@ function reset() {
* The handler function itself performs an insert/delete and returns the
* id of the document in play.
*
* @param {Object} event - API Gateway Lambda Proxy Input Format
* @returns {Object} object - API Gateway Lambda Proxy Output Format
* @param event - API Gateway Lambda Proxy Input Format
* @returns API Gateway Lambda Proxy Output Format
*/
export const lambdaHandler = async (event) => {
export const lambdaHandler = async () => {
const db = mongoClient.db('lambdaTest');
const collection = db.collection('test');
const { insertedId } = await collection.insertOne({ n: 1 });
Expand Down