Skip to content

Commit

Permalink
[APM] Fix bug that causes watcher emails to fail (#19071)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed May 15, 2018
1 parent 0940f57 commit 3bf6c43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -128,6 +128,7 @@ Object {
"metadata": Object {
"emails": Array [
"my@email.dk",
"mySecond@email.dk",
],
"serviceName": "opbeans-node",
"slackUrlPath": "/services/slackid1/slackid2/slackid3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
);
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bf6c43

Please sign in to comment.