[APM] Fix bug that causes watcher emails to fail (#19071) (#19091)

This commit is contained in:
Søren Louv-Jansen 2018-05-16 00:56:46 +02:00 committed by GitHub
parent 6e8447082e
commit 5db2efdb43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View file

@ -31,7 +31,7 @@ Object {
"html": "Your service \\"opbeans-node\\" has error groups which exceeds 10 occurrences within \\"24h\\"<br/><br/><br/><strong>this is a string</strong><br/>N/A<br/>7761 occurrences<br/><br/><strong>foo</strong><br/><anonymous> (server/coffee.js)<br/>7752 occurrences<br/><br/><strong>socket hang up</strong><br/>createHangUpError (_http_client.js)<br/>3887 occurrences<br/><br/><strong>this will not get captured by express</strong><br/><anonymous> (server/coffee.js)<br/>3886 occurrences<br/>",
},
"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",

View file

@ -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)) {

View file

@ -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