diff --git a/services/chat/app/js/server.js b/services/chat/app/js/server.js index b75a84b912..ede4b19a40 100644 --- a/services/chat/app/js/server.js +++ b/services/chat/app/js/server.js @@ -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 }, diff --git a/services/chat/test/acceptance/js/GettingMessagesTests.js b/services/chat/test/acceptance/js/GettingMessagesTests.js index 0e5cb6fd6c..e95e28f9ee 100644 --- a/services/chat/test/acceptance/js/GettingMessagesTests.js +++ b/services/chat/test/acceptance/js/GettingMessagesTests.js @@ -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 () { diff --git a/services/chat/test/acceptance/js/helpers/ChatClient.js b/services/chat/test/acceptance/js/helpers/ChatClient.js index 433b6fcd71..022afecc9b 100644 --- a/services/chat/test/acceptance/js/helpers/ChatClient.js +++ b/services/chat/test/acceptance/js/helpers/ChatClient.js @@ -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',