mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
[web] collect mongo stats on native client (#32909)
* [metrics] mongo: fail when command monitoring is not available * [metrics] mongo: add optional client label to pool metrics * [web] collect mongo stats on native client * [metrics] mongo: record namespace of find commands * [metrics] mongo: add counter for all the commands with collection label * [web] add missing mock GitOrigin-RevId: 9f378d8aa8d7167f56cf512681d63ef115c6dd98
This commit is contained in:
@@ -11,17 +11,7 @@ const connectionPromise = mongoose.connect(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
|
||||
connectionPromise
|
||||
.then(mongooseInstance => {
|
||||
Metrics.mongodb.monitor(mongooseInstance.connection.client)
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error(
|
||||
{ error },
|
||||
'Failed to connect to MongoDB - cannot set up monitoring'
|
||||
)
|
||||
})
|
||||
Metrics.mongodb.monitor(mongoose.connection.client, 'mongoose')
|
||||
|
||||
addConnectionDrainer('mongoose', async () => {
|
||||
await connectionPromise
|
||||
|
||||
@@ -4,6 +4,7 @@ import Settings from '@overleaf/settings'
|
||||
import MongoUtils from '@overleaf/mongo-utils'
|
||||
import Mongoose from './Mongoose.mjs'
|
||||
import { addConnectionDrainer } from './GracefulShutdown.mjs'
|
||||
import Metrics from '@overleaf/metrics'
|
||||
|
||||
// Ensure Mongoose is using the same mongodb instance as the mongodb module,
|
||||
// otherwise we will get multiple versions of the ObjectId class. Mongoose
|
||||
@@ -27,6 +28,7 @@ const mongoClient = new mongodb.MongoClient(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
Metrics.mongodb.monitor(mongoClient, 'native')
|
||||
|
||||
addConnectionDrainer('mongodb', async () => {
|
||||
await mongoClient.close()
|
||||
|
||||
@@ -59,6 +59,7 @@ vi.mock('@overleaf/metrics', () => {
|
||||
}
|
||||
},
|
||||
prom: { Counter: sinon.stub(), Histogram: sinon.stub() },
|
||||
mongodb: { monitor: sinon.stub() },
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user