mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 21:59:00 +02:00
Merge pull request #16873 from overleaf/dp-mongo-command-monitoring
Use mongo command monitoring to add timing metrics GitOrigin-RevId: e7e5dd5cca1ba3802c02198ccf81058d4da3f1e7
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { Gauge } = require('prom-client')
|
||||
const { Gauge, Summary } = require('prom-client')
|
||||
|
||||
function monitor(mongoClient) {
|
||||
const labelNames = ['mongo_server']
|
||||
@@ -25,6 +25,35 @@ function monitor(mongoClient) {
|
||||
labelNames,
|
||||
})
|
||||
|
||||
const mongoCommandTimer = new Summary({
|
||||
name: 'mongo_command_time',
|
||||
help: 'time taken to complete a mongo command',
|
||||
percentiles: [],
|
||||
labelNames: ['status', 'method'],
|
||||
})
|
||||
|
||||
if (mongoClient.on) {
|
||||
mongoClient.on('commandSucceeded', event => {
|
||||
mongoCommandTimer.observe(
|
||||
{
|
||||
status: 'success',
|
||||
method: event.commandName === 'find' ? 'read' : 'write',
|
||||
},
|
||||
event.duration
|
||||
)
|
||||
})
|
||||
|
||||
mongoClient.on('commandFailed', event => {
|
||||
mongoCommandTimer.observe(
|
||||
{
|
||||
status: 'failed',
|
||||
method: event.commandName === 'find' ? 'read' : 'write',
|
||||
},
|
||||
event.duration
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function collect() {
|
||||
// Reset all gauges in case they contain values for servers that
|
||||
// disappeared
|
||||
|
||||
@@ -4,7 +4,10 @@ import { MongoClient } from 'mongodb'
|
||||
|
||||
export { ObjectId } from 'mongodb'
|
||||
|
||||
export const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
export const mongoClient = new MongoClient(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
export const db = {
|
||||
|
||||
@@ -20,5 +20,8 @@ module.exports = {
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import { MongoClient } from 'mongodb'
|
||||
|
||||
export { ObjectId } from 'mongodb'
|
||||
|
||||
export const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
export const mongoClient = new MongoClient(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
export const db = {
|
||||
|
||||
@@ -13,5 +13,8 @@ module.exports = {
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb-legacy')
|
||||
|
||||
const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
const db = {
|
||||
|
||||
@@ -9,7 +9,11 @@ const Settings = {
|
||||
},
|
||||
},
|
||||
|
||||
mongo: {},
|
||||
mongo: {
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
|
||||
docstore: {
|
||||
archiveOnSoftDelete: process.env.ARCHIVE_ON_SOFT_DELETE === 'true',
|
||||
|
||||
@@ -2,7 +2,7 @@ const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb-legacy')
|
||||
|
||||
const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
const db = {
|
||||
|
||||
@@ -159,6 +159,9 @@ module.exports = {
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || '127.0.0.1'}/sharelatex`,
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
|
||||
sentry: {
|
||||
|
||||
@@ -2,7 +2,7 @@ const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb-legacy')
|
||||
|
||||
const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
const mongoClient = new MongoClient(Settings.mongo.url, Settings.mongo.options)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
const db = {
|
||||
|
||||
@@ -10,5 +10,8 @@ module.exports = {
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ const { MongoClient, ObjectId } = mongodb
|
||||
|
||||
export { ObjectId }
|
||||
|
||||
export const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
export const mongoClient = new MongoClient(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
@@ -3,6 +3,9 @@ module.exports = {
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
|
||||
options: {
|
||||
monitorCommands: true,
|
||||
},
|
||||
},
|
||||
internal: {
|
||||
history: {
|
||||
|
||||
@@ -129,6 +129,7 @@ module.exports = {
|
||||
process.env.MONGO_SOCKET_TIMEOUT ?? '60000',
|
||||
10
|
||||
),
|
||||
monitorCommands: true,
|
||||
},
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
|
||||
Reference in New Issue
Block a user