mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #11080 from overleaf/lg-openapi-chat-metrics
Fix metrics for chat service GitOrigin-RevId: fcc6b3e1e5bf411d8c9fe48a6913ad1c0a9199f2
This commit is contained in:
parent
0b14c55d24
commit
4bdffbefdf
3 changed files with 25 additions and 0 deletions
|
@ -15,6 +15,9 @@ logger.initialize('chat')
|
|||
export async function createServer() {
|
||||
const app = express()
|
||||
|
||||
app.use(metrics.http.monitor(logger))
|
||||
metrics.injectMetricsRoute(app)
|
||||
|
||||
// See https://github.com/exegesis-js/exegesis/blob/master/docs/Options.md
|
||||
const options = {
|
||||
controllers: { messagesController },
|
||||
|
|
|
@ -4,6 +4,16 @@ import { expect } from 'chai'
|
|||
import * as ChatClient from './helpers/ChatClient.js'
|
||||
import * as ChatApp from './helpers/ChatApp.js'
|
||||
|
||||
async function getCount() {
|
||||
return await ChatClient.getMetric(line => {
|
||||
return (
|
||||
line.includes('timer_http_request_count') &&
|
||||
line.includes('path="project_{projectId}_messages"') &&
|
||||
line.includes('method="POST"')
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
describe('Getting messages', async function () {
|
||||
const userId1 = ObjectId().toString()
|
||||
const userId2 = ObjectId().toString()
|
||||
|
@ -16,6 +26,7 @@ describe('Getting messages', async function () {
|
|||
describe('globally', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
before(async function () {
|
||||
const previousCount = await getCount()
|
||||
const { response } = await ChatClient.sendGlobalMessage(
|
||||
projectId,
|
||||
userId1,
|
||||
|
@ -31,6 +42,7 @@ describe('Getting messages', async function () {
|
|||
const { response: response3, body } = await ChatClient.checkStatus()
|
||||
expect(response3.statusCode).to.equal(200)
|
||||
expect(body).to.equal('chat is alive')
|
||||
expect(await getCount()).to.equal(previousCount + 2)
|
||||
})
|
||||
|
||||
it('should contain the messages and populated users when getting the messages', async function () {
|
||||
|
|
|
@ -99,6 +99,16 @@ export async function checkStatus() {
|
|||
})
|
||||
}
|
||||
|
||||
export async function getMetric(matcher) {
|
||||
const { body } = await asyncRequest({
|
||||
method: 'get',
|
||||
url: `/metrics`,
|
||||
})
|
||||
const found = body.split('\n').find(matcher)
|
||||
if (!found) return 0
|
||||
return parseInt(found.split(' ')[1], 0)
|
||||
}
|
||||
|
||||
export async function reopenThread(projectId, threadId) {
|
||||
return asyncRequest({
|
||||
method: 'post',
|
||||
|
|
Loading…
Reference in a new issue