From 3bf6c43602b5cb07f3ef65db06362443c538e2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Tue, 15 May 2018 23:03:40 +0200 Subject: [PATCH] [APM] Fix bug that causes watcher emails to fail (#19071) --- .../__snapshots__/createErrorGroupWatch.test.js.snap | 3 ++- .../Watcher/__test__/createErrorGroupWatch.test.js | 11 ++++++++--- .../Watcher/createErrorGroupWatch.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/__snapshots__/createErrorGroupWatch.test.js.snap b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/__snapshots__/createErrorGroupWatch.test.js.snap index 9a9e7964d5cc8d..50a272afa4cb5f 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/__snapshots__/createErrorGroupWatch.test.js.snap +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/__snapshots__/createErrorGroupWatch.test.js.snap @@ -31,7 +31,7 @@ Object { "html": "Your service \\"opbeans-node\\" has error groups which exceeds 10 occurrences within \\"24h\\"


this is a string
N/A
7761 occurrences

foo
(server/coffee.js)
7752 occurrences

socket hang up
createHangUpError (_http_client.js)
3887 occurrences

this will not get captured by express
(server/coffee.js)
3886 occurrences
", }, "subject": "\\"opbeans-node\\" has error groups which exceeds the threshold", - "to": "my@email.dk", + "to": "my@email.dk,mySecond@email.dk", }, }, "log_error": Object { @@ -128,6 +128,7 @@ Object { "metadata": Object { "emails": Array [ "my@email.dk", + "mySecond@email.dk", ], "serviceName": "opbeans-node", "slackUrlPath": "/services/slackid1/slackid2/slackid3", diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/createErrorGroupWatch.test.js b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/createErrorGroupWatch.test.js index 57a1c59e9233e6..baf0795a0d6c44 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/createErrorGroupWatch.test.js +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/__test__/createErrorGroupWatch.test.js @@ -26,7 +26,7 @@ describe('createErrorGroupWatch', () => { jest.spyOn(rest, 'createWatch').mockReturnValue(); createWatchResponse = await createErrorGroupWatch({ - emails: ['my@email.dk'], + emails: ['my@email.dk', 'mySecond@email.dk'], schedule: { daily: { at: '08:00' @@ -63,7 +63,9 @@ describe('createErrorGroupWatch', () => { }); it('should format email correctly', () => { - expect(tmpl.actions.email.email.to).toBe('my@email.dk'); + expect(tmpl.actions.email.email.to).toEqual( + 'my@email.dk,mySecond@email.dk' + ); expect(tmpl.actions.email.email.subject).toBe( '"opbeans-node" has error groups which exceeds the threshold' ); @@ -85,7 +87,10 @@ describe('createErrorGroupWatch', () => { // Recusively iterate a nested structure and render strings as mustache templates function renderMustache(input, ctx) { if (isString(input)) { - return mustache.render(input, { ctx }); + return mustache.render(input, { + ctx, + join: () => (text, render) => render(`{{${text}}}`, { ctx }) + }); } if (isArray(input)) { diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/createErrorGroupWatch.js b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/createErrorGroupWatch.js index 3922b26f83edf9..e1b9de2f40f37c 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/createErrorGroupWatch.js +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/Watcher/createErrorGroupWatch.js @@ -160,7 +160,7 @@ export async function createErrorGroupWatch({ if (!isEmpty(emails)) { body.actions.email = { email: { - to: '{{ctx.metadata.emails}}', + to: '{{#join}}ctx.metadata.emails{{/join}}', subject: `"{{ctx.metadata.serviceName}}" has error groups which exceeds the threshold`, body: { html: emailTemplate