From 0f1fdab7a0c669b086a069a6a30f3d023a30e5e2 Mon Sep 17 00:00:00 2001 From: Alexander Chernyaev <46301523+HyTekCoop@users.noreply.github.com> Date: Thu, 9 Mar 2023 18:23:33 +0300 Subject: [PATCH 1/4] Changed the content of the limit events email (#319) * Update html.twig Change the description email * Change email's title --- .../emails/events-limit-almost-reached/html.twig | 8 ++++---- .../emails/events-limit-almost-reached/subject.twig | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/workers/email/src/templates/emails/events-limit-almost-reached/html.twig b/workers/email/src/templates/emails/events-limit-almost-reached/html.twig index 32f05cf2..05dd0c35 100644 --- a/workers/email/src/templates/emails/events-limit-almost-reached/html.twig +++ b/workers/email/src/templates/emails/events-limit-almost-reached/html.twig @@ -14,7 +14,7 @@ - Your plan limit is almost reached + Warning of the Used Volume @@ -22,15 +22,15 @@ - You've used {{ eventsCount }} of {{ eventsLimit }} events available on {{ workspace.name | escape }} workspace plan. + You've used {{ eventsCount }} of {{ eventsLimit }} events available on {{ workspace.name | escape }} workspace. - Upgrade the plan and don't miss the new ones. + Increase used volume and don't miss the new ones. - {% include '../../components/button.twig' with {href: host ~ '/workspace/' ~ workspace._id ~ '/settings/billing', label: 'Go to payment settings'} %} + {% include '../../components/button.twig' with {href: host ~ '/workspace/' ~ workspace._id ~ '/settings/volume', label: 'Go to event usage settings'} %} {% endblock %} diff --git a/workers/email/src/templates/emails/events-limit-almost-reached/subject.twig b/workers/email/src/templates/emails/events-limit-almost-reached/subject.twig index f52cda55..4a43e8b9 100644 --- a/workers/email/src/templates/emails/events-limit-almost-reached/subject.twig +++ b/workers/email/src/templates/emails/events-limit-almost-reached/subject.twig @@ -1 +1 @@ -Your plan limit is almost reached for workspace {{ workspace.name | escape }}! +Warning of the Used Volume for workspace {{ workspace.name | escape }}! From ced34da14ac672cbbe54c540cc4c0bce74fef100 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 1 Oct 2024 00:16:42 +0300 Subject: [PATCH 2/4] Update index.ts (#322) --- workers/grouper/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/workers/grouper/src/index.ts b/workers/grouper/src/index.ts index e39370e1..22a51771 100644 --- a/workers/grouper/src/index.ts +++ b/workers/grouper/src/index.ts @@ -126,6 +126,8 @@ export default class GrouperWorker extends Worker { if (e.code?.toString() === DB_DUPLICATE_KEY_ERROR) { HawkCatcher.send(new Error('[Grouper] MongoError: E11000 duplicate key error collection')); await this.handle(task); + + return; } else { throw e; } From 98997a41d3c96af5dcd0d46ffa424e4452211236 Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Wed, 4 Dec 2024 18:31:00 +0000 Subject: [PATCH 3/4] add error log (#324) --- lib/worker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/worker.ts b/lib/worker.ts index abe3209f..e71395ef 100644 --- a/lib/worker.ts +++ b/lib/worker.ts @@ -346,6 +346,7 @@ export abstract class Worker { return; default: + console.error(e) this.logger.error('Unknown error: ', e); await this.sendToStash(msg); } From cdf5984d6c1ab901df18dd52e7cc37da2d189423 Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Mon, 9 Dec 2024 10:28:26 +0000 Subject: [PATCH 4/4] fix(grouper): handle out-of-type diff calculations (#275) * add failed test case to deepDiff * update deepDiff method Resolves #312 * eslint issue fixed * Update utils.test.js * Update utils.test.js --------- Co-authored-by: Peter Savchenko --- lib/utils.js | 28 +++++++++- lib/utils.test.js | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 418aa43f..c28b9cb2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -29,9 +29,33 @@ module.exports.deepMerge = deepMerge; * @returns {object} */ function deepDiff(source, target) { - if (typeOf(target) === 'array') { + const sourceType = typeOf(source); + const targetType = typeOf(target); + + /** + * If we'll compare NOTHING with SOMETHING, the diff will be SOMETHING + */ + if (source === undefined) { + return target; + } + + /** + * If we'll compare SOMETHING with NOTHING, the diff will be NOTHING + */ + if (targetType === undefined) { + return undefined; + } + + /** + * We CAN'T compare apples with dogs + */ + if (sourceType !== targetType) { + return undefined; + } + + if (targetType === 'array') { return arrayDiff(source, target); - } else if (typeOf(target) === 'object') { + } else if (targetType === 'object') { return objectDiff(source, target); } else if (source !== target) { return target; diff --git a/lib/utils.test.js b/lib/utils.test.js index a0b49099..fa2b096f 100644 --- a/lib/utils.test.js +++ b/lib/utils.test.js @@ -117,6 +117,35 @@ describe('Utils', () => { files: [ { line: 1 }, { line: 2 }, { line: 3 } ], }, }, + + /** + * The first - an empty array + * The second - array with the children non-empty array + */ + { + sourceObject: { + prop: [], + }, + targetObject: { + prop: [ [ 'i am not empty' ] ], + }, + expectedDiff: { + prop: [ [ 'i am not empty' ] ], + }, + expectedMerge: { + prop: [ [ 'i am not empty' ] ], + }, + }, + + /** + * Trying to compare two things of different type + */ + { + sourceObject: [], + targetObject: {}, + expectedDiff: undefined, + expectedMerge: {}, + }, ]; test('should return right object diff', () => { @@ -135,4 +164,110 @@ describe('Utils', () => { expect(merge).toEqual(testCase.expectedMerge); }); }); + + /** + * This test is a temporary solution to handle case with invalid events format sent by the PHP catcher + * + * The problem: the PHP catcher sends some data via incompatible format under invalid names and types. + * Those fields leads to the issues with diff calculation since fields could have different structure and types. + * + * The solution: deepDiff will return undefined in case of comparison of things with different types + * + * Original issue: + * https://github.com/codex-team/hawk.workers/issues/312 + * + * PHP Catcher issue: + * https://github.com/codex-team/hawk.php/issues/39 + */ + test('should not throw error comparing events with incompatible format', () => { + const originalStackTrace = [ + { + function: 'postAddComment', + class: 'Components\\Comments\\Comments', + object: {}, + type: '->', + args: [ + 286131, + {}, + ], + }, + ]; + + const repetitionStackTrace = [ + { + file: '/var/www/osnova/vendor/php-di/invoker/src/Invoker.php', + line: 74, + function: 'call_user_func_array', + args: [ + [ + {}, + 'sendWebhooksJob', + ], + [ + [ + { + id: 6697, + token: '539506', + event: 'new_comment', + url: 'https://callback.angry.space/vc_callback?date=2020&code=lMzBjOWZh@DADAD@jFlZmUy', + filter: '[]', + data: '[]', + removed: false, + }, + ], + { + type: 'new_comment', + data: { + id: 3206086, + url: 'https://somesite.io/trade/286961', + text: 'Это только со стороны так вроде долго, а если смотреть изнутри, то пока там освободиться купьер, пока найдут товар пока разберуться куда везти может и 4 часа пройти.', + media: [], + date: '2021-08-27T18:08:30+03:00', + creator: { + id: 27823, + avatar: 'https://s3.somesite.io/8ddee2e8-28e4-7863-425e-dd9b06deae5d/', + name: 'John S.', + url: 'https://somesite.io/u/27823-john-s', + }, + content: { + id: 286961, + title: 'Wildberries запустил доставку товаров за 2 часа в Петербурге', + url: 'https://somesite.io/trade/286961', + owner: { + id: 199122, + name: 'Торговля', + avatar: 'https://leonardo.osnova.io/d8fbb348-a8fd-641c-55dd-6a404055b457/', + url: 'https://somesite.io/trade', + }, + }, + replyTo: { + id: 3205883, + url: 'https://somesite.io/trade/286961', + text: 'Никто не пошутил, тогда это сделаю я!\n\n- 2.. часа!!1', + media: [], + creator: { + id: 877711, + avatar: 'https://leonardo.osnova.io/476a4e2c-8045-5b77-8a37-f6b1eb58bf93/', + name: 'Вадим Осадчий', + url: 'https://somesite.io/u/877711-john-doe', + }, + }, + }, + }, + ], + ], + }, + ]; + + const diff = utils.deepDiff(originalStackTrace, repetitionStackTrace); + + expect(diff).toEqual([ + { + file: '/var/www/osnova/vendor/php-di/invoker/src/Invoker.php', + line: 74, + function: 'call_user_func_array', + args: [undefined, undefined], + }, + ]); + }); });