Skip to content

Commit 7bc8a85

Browse files
github-actions[bot]e11syTatianaFomina
authored
Update prod (#427)
* chore: update notifier readme (#421) * chore: update notifier readme * chore: typo * chore(notifier): add pic to readme * chore(notifer): rm redundant * chore: reorder * chore: rm redundant * fix(emails): Update unsubscribe link (#424) * Update link * Upd * Fix tests * Fix(grouper): grouping patterns (#426) * fix: grouping patterns * fix: mocks fixed --------- Co-authored-by: e11sy <130844513+e11sy@users.noreply.github.com> Co-authored-by: Tatiana Fomina <fomina.tatianaaa@yandex.ru>
1 parent e0a1166 commit 7bc8a85

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

workers/grouper/src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Worker } from '../../../lib/worker';
66
import * as WorkerNames from '../../../lib/workerNames';
77
import * as pkg from '../package.json';
88
import type { GroupWorkerTask, RepetitionDelta } from '../types/group-worker-task';
9-
import type { EventAddons, EventDataAccepted, GroupedEventDBScheme, BacktraceFrame, SourceCodeLine } from '@hawk.so/types';
9+
import type { EventAddons, EventDataAccepted, GroupedEventDBScheme, BacktraceFrame, SourceCodeLine, ProjectEventGroupingPatternsDBScheme } from '@hawk.so/types';
1010
import type { RepetitionDBScheme } from '../types/repetition';
1111
import { DatabaseReadWriteError, DiffCalculationError, ValidationError } from '../../../lib/workerErrors';
1212
import { decodeUnsafeFields, encodeUnsafeFields } from '../../../lib/utils/unsafeFields';
@@ -317,11 +317,11 @@ export default class GrouperWorker extends Worker {
317317

318318
if (matchingPattern !== null && matchingPattern !== undefined) {
319319
try {
320-
const originalEvent = await this.cache.get(`${projectId}:${matchingPattern}:originalEvent`, async () => {
320+
const originalEvent = await this.cache.get(`${projectId}:${matchingPattern._id}:originalEvent`, async () => {
321321
return await this.eventsDb.getConnection()
322322
.collection(`events:${projectId}`)
323323
.findOne(
324-
{ 'payload.title': { $regex: matchingPattern } },
324+
{ 'payload.title': { $regex: matchingPattern.pattern } },
325325
{ sort: { _id: 1 } }
326326
);
327327
});
@@ -332,7 +332,7 @@ export default class GrouperWorker extends Worker {
332332
return originalEvent;
333333
}
334334
} catch (e) {
335-
this.logger.error(`Error while getting original event for pattern ${matchingPattern}`);
335+
this.logger.error(`Error while getting original event for pattern ${matchingPattern}: ${e.message}`);
336336
}
337337
}
338338
}
@@ -345,15 +345,18 @@ export default class GrouperWorker extends Worker {
345345
*
346346
* @param patterns - list of the patterns of the related project
347347
* @param event - event which title would be cheched
348-
* @returns {string | null} matched pattern or null if no match
348+
* @returns {ProjectEventGroupingPatternsDBScheme | null} matched pattern object or null if no match
349349
*/
350-
private async findMatchingPattern(patterns: string[], event: EventDataAccepted<EventAddons>): Promise<string | null> {
350+
private async findMatchingPattern(
351+
patterns: ProjectEventGroupingPatternsDBScheme[],
352+
event: EventDataAccepted<EventAddons>
353+
): Promise<ProjectEventGroupingPatternsDBScheme | null> {
351354
if (!patterns || patterns.length === 0) {
352355
return null;
353356
}
354357

355358
return patterns.filter(pattern => {
356-
const patternRegExp = new RegExp(pattern);
359+
const patternRegExp = new RegExp(pattern.pattern);
357360

358361
return event.title.match(patternRegExp);
359362
}).pop() || null;
@@ -363,9 +366,9 @@ export default class GrouperWorker extends Worker {
363366
* Method that gets event patterns for a project
364367
*
365368
* @param projectId - id of the project to find related event patterns
366-
* @returns {string[]} EventPatterns object with projectId and list of patterns
369+
* @returns {ProjectEventGroupingPatternsDBScheme[]} EventPatterns object with projectId and list of patterns
367370
*/
368-
private async getProjectPatterns(projectId: string): Promise<string[]> {
371+
private async getProjectPatterns(projectId: string): Promise<ProjectEventGroupingPatternsDBScheme[]> {
369372
return this.cache.get(`project:${projectId}:patterns`, async () => {
370373
const project = await this.accountsDb.getConnection()
371374
.collection('projects')

workers/grouper/tests/index.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const projectMock = {
6767
},
6868
unreadCount: 0,
6969
description: 'Test project for grouper worker tests',
70-
eventGroupingPatterns: [ 'New error .*' ],
70+
eventGroupingPatterns: [ { _id: mongodb.ObjectId(), pattern: 'New error .*' }],
7171
};
7272

7373
/**
@@ -490,7 +490,9 @@ describe('GrouperWorker', () => {
490490
});
491491

492492
test('should group events with titles matching one pattern', async () => {
493-
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([ 'New error .*' ]);
493+
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([
494+
{ _id: new mongodb.ObjectId, pattern: 'New error .*' }
495+
]);
494496
const findMatchingPatternSpy = jest.spyOn(GrouperWorker.prototype as any, 'findMatchingPattern');
495497

496498
await worker.handle(generateTask({ title: 'New error 0000000000000000' }));
@@ -507,9 +509,9 @@ describe('GrouperWorker', () => {
507509

508510
test('should handle multiple patterns and match the first one that applies', async () => {
509511
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([
510-
'Database error: .*',
511-
'Network error: .*',
512-
'New error: .*',
512+
{ _id: mongodb.ObjectId(), pattern: 'Database error: .*' },
513+
{ _id: mongodb.ObjectId(), pattern: 'Network error: .*' },
514+
{ _id: mongodb.ObjectId(), pattern: 'New error: .*' },
513515
]);
514516

515517
await worker.handle(generateTask({ title: 'Database error: connection failed' }));
@@ -526,8 +528,8 @@ describe('GrouperWorker', () => {
526528

527529
test('should handle complex regex patterns', async () => {
528530
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([
529-
'Error \\d{3}: [A-Za-z\\s]+ in file .*\\.js$',
530-
'Warning \\d{3}: .*',
531+
{ _id: mongodb.ObjectId(), pattern: 'Error \\d{3}: [A-Za-z\\s]+ in file .*\\.js$' },
532+
{ _id: mongodb.ObjectId(), pattern: 'Warning \\d{3}: .*' },
531533
]);
532534

533535
await worker.handle(generateTask({ title: 'Error 404: Not Found in file index.js' }));
@@ -544,8 +546,8 @@ describe('GrouperWorker', () => {
544546

545547
test('should maintain separate groups for different patterns', async () => {
546548
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([
547-
'TypeError: .*',
548-
'ReferenceError: .*',
549+
{ _id: mongodb.ObjectId(), pattern: 'TypeError: .*' },
550+
{ _id: mongodb.ObjectId(), pattern: 'ReferenceError: .*' },
549551
]);
550552

551553
await worker.handle(generateTask({ title: 'TypeError: null is not an object' }));
@@ -566,8 +568,8 @@ describe('GrouperWorker', () => {
566568

567569
test('should handle patterns with special regex characters', async () => {
568570
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([
569-
'Error \\[\\d+\\]: .*',
570-
'Warning \\(code=\\d+\\): .*',
571+
{ _id: new mongodb.ObjectID(), pattern: 'Error \\[\\d+\\]: .*'} ,
572+
{ _id: new mongodb.ObjectID(), pattern: 'Warning \\(code=\\d+\\): .*'} ,
571573
]);
572574

573575
await worker.handle(generateTask({ title: 'Error [123]: Database connection failed' }));

0 commit comments

Comments
 (0)