[APM] Fix JSON in Watcher assistant (#19987) (#19999)

This commit is contained in:
Søren Louv-Jansen 2018-06-18 19:49:17 +02:00 committed by GitHub
parent e4abda8593
commit 34375fd433
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 27 deletions

View file

@ -22,7 +22,28 @@ createHangUpError (_http_client.js)
"
`;
exports[`createErrorGroupWatch should format entire template correctly 1`] = `
exports[`createErrorGroupWatch should format slack message correctly 1`] = `
"Your service \\"opbeans-node\\" has error groups which exceeds 10 occurrences within \\"24h\\"
>*this is a string*
>N/A
>7761 occurrences
>*foo*
>\`<anonymous> (server/coffee.js)\`
>7752 occurrences
>*socket hang up*
>\`createHangUpError (_http_client.js)\`
>3887 occurrences
>*this will not get captured by express*
>\`<anonymous> (server/coffee.js)\`
>3886 occurrences
"
`;
exports[`createErrorGroupWatch should format template correctly 1`] = `
Object {
"actions": Object {
"email": Object {
@ -41,7 +62,7 @@ Object {
},
"slack_webhook": Object {
"webhook": Object {
"body": "{\\"text\\":\\"Your service \\\\\\"opbeans-node\\\\\\" has error groups which exceeds 10 occurrences within \\\\\\"24h\\\\\\"\\\\n\\\\n>*this is a string*\\\\n>N/A\\\\n>7761 occurrences\\\\n\\\\n>*foo*\\\\n>\`<anonymous> (server/coffee.js)\`\\\\n>7752 occurrences\\\\n\\\\n>*socket hang up*\\\\n>\`createHangUpError (_http_client.js)\`\\\\n>3887 occurrences\\\\n\\\\n>*this will not get captured by express*\\\\n>\`<anonymous> (server/coffee.js)\`\\\\n>3886 occurrences\\\\n\\"}",
"body": "__json__::{\\"text\\":\\"Your service \\\\\\"opbeans-node\\\\\\" has error groups which exceeds 10 occurrences within \\\\\\"24h\\\\\\"\\\\n\\\\n>*this is a string*\\\\n>N/A\\\\n>7761 occurrences\\\\n\\\\n>*foo*\\\\n>\`<anonymous> (server/coffee.js)\`\\\\n>7752 occurrences\\\\n\\\\n>*socket hang up*\\\\n>\`createHangUpError (_http_client.js)\`\\\\n>3887 occurrences\\\\n\\\\n>*this will not get captured by express*\\\\n>\`<anonymous> (server/coffee.js)\`\\\\n>3886 occurrences\\\\n\\"}",
"headers": Object {
"Content-Type": "application/json",
},
@ -146,24 +167,3 @@ Object {
},
}
`;
exports[`createErrorGroupWatch should format slack message correctly 1`] = `
"Your service \\"opbeans-node\\" has error groups which exceeds 10 occurrences within \\"24h\\"
>*this is a string*
>N/A
>7761 occurrences
>*foo*
>\`<anonymous> (server/coffee.js)\`
>7752 occurrences
>*socket hang up*
>\`createHangUpError (_http_client.js)\`
>3887 occurrences
>*this will not get captured by express*
>\`<anonymous> (server/coffee.js)\`
>3886 occurrences
"
`;

View file

@ -57,8 +57,9 @@ describe('createErrorGroupWatch', () => {
expect(tmpl.actions.slack_webhook.webhook.path).toBe(
'/services/slackid1/slackid2/slackid3'
);
expect(
JSON.parse(tmpl.actions.slack_webhook.webhook.body).text
JSON.parse(tmpl.actions.slack_webhook.webhook.body.slice(10)).text
).toMatchSnapshot();
});
@ -74,7 +75,7 @@ describe('createErrorGroupWatch', () => {
).toMatchSnapshot();
});
it('should format entire template correctly', () => {
it('should format template correctly', () => {
expect(tmpl).toMatchSnapshot();
});

View file

@ -150,9 +150,9 @@ export async function createErrorGroupWatch({
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
body: `__json__::${JSON.stringify({
text: slackTemplate
})
})}`
}
};
}