Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions workers/grouper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import HawkCatcher from '@hawk.so/nodejs';
import { MS_IN_SEC } from '../../../lib/utils/consts';
import DataFilter from './data-filter';
import RedisHelper from './redisHelper';
import levenshtein from 'js-levenshtein';
import { computeDelta } from './utils/repetitionDiff';
import TimeMs from '../../../lib/utils/time';

Expand Down Expand Up @@ -244,22 +243,24 @@ export default class GrouperWorker extends Worker {
*/
private async findSimilarEvent(projectId: string, event: EventDataAccepted<EventAddons>): Promise<GroupedEventDBScheme | undefined> {
const eventsCountToCompare = 60;
const diffTreshold = 0.35;
// const diffTreshold = 0.35;

const lastUniqueEvents = await this.findLastEvents(projectId, eventsCountToCompare);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, we can find event by title using mongo. We dont need to get 60 events for that.


/**
* First try to find by Levenshtein distance
* First try to find similar event by title
*/
const similarByLevenshtein = lastUniqueEvents.filter(prevEvent => {
const distance = levenshtein(event.title, prevEvent.payload.title);
const threshold = event.title.length * diffTreshold;
const similarByTitle = lastUniqueEvents.filter(prevEvent => {
// const distance = levenshtein(event.title, prevEvent.payload.title);

return distance < threshold;
// const threshold = event.title.length * diffTreshold;

// return distance < threshold;
return event.title.toLowerCase() === prevEvent.payload.title.toLowerCase();
}).pop();
Comment on lines +253 to 260
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets just comment out grouping by Levenshtein and implement grouping by title below.


if (similarByLevenshtein) {
return similarByLevenshtein;
if (similarByTitle) {
return similarByTitle;
}

/**
Expand All @@ -280,13 +281,14 @@ export default class GrouperWorker extends Worker {
{ sort: { _id: 1 } }
);
});

this.logger.info(`original event for pattern: ${JSON.stringify(originalEvent)}`);

if (originalEvent) {
return originalEvent;
}
} catch (e) {
this.logger.error(`Error while getting original event for pattern ${matchingPattern}`)
this.logger.error(`Error while getting original event for pattern ${matchingPattern}`);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions workers/grouper/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,17 @@
});

describe('Grouping', () => {
test('should group events with partially different titles', async () => {
await worker.handle(generateTask({ title: 'Some error (but not filly identical) example' }));
await worker.handle(generateTask({ title: 'Some error (yes, it is not the identical) example' }));
await worker.handle(generateTask({ title: 'Some error (and it is not identical) example' }));
// test('should group events with partially different titles', async () => {
// await worker.handle(generateTask({ title: 'Some error (but not filly identical) example' }));
// await worker.handle(generateTask({ title: 'Some error (yes, it is not the identical) example' }));
// await worker.handle(generateTask({ title: 'Some error (and it is not identical) example' }));

const originalEvent = await eventsCollection.findOne({});
// const originalEvent = await eventsCollection.findOne({});

expect((await repetitionsCollection.find({
groupHash: originalEvent.groupHash,
}).toArray()).length).toBe(2);
});
// expect((await repetitionsCollection.find({
// groupHash: originalEvent.groupHash,
// }).toArray()).length).toBe(2);
// });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for grouping by title

describe('Pattern matching', () => {
beforeEach(() => {
Expand All @@ -490,8 +490,8 @@
});

test('should group events with titles matching one pattern', async () => {
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([ 'New error .*' ]);

Check warning on line 493 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
const findMatchingPatternSpy = jest.spyOn(GrouperWorker.prototype as any, 'findMatchingPattern');

Check warning on line 494 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type

await worker.handle(generateTask({ title: 'New error 0000000000000000' }));
await worker.handle(generateTask({ title: 'New error 1111111111111111' }));
Expand All @@ -506,7 +506,7 @@
});

test('should handle multiple patterns and match the first one that applies', async () => {
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([

Check warning on line 509 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
'Database error: .*',
'Network error: .*',
'New error: .*',
Expand All @@ -525,7 +525,7 @@
});

test('should handle complex regex patterns', async () => {
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([

Check warning on line 528 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
'Error \\d{3}: [A-Za-z\\s]+ in file .*\\.js$',
'Warning \\d{3}: .*',
]);
Expand All @@ -543,7 +543,7 @@
});

test('should maintain separate groups for different patterns', async () => {
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([

Check warning on line 546 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
'TypeError: .*',
'ReferenceError: .*',
]);
Expand All @@ -565,7 +565,7 @@
});

test('should handle patterns with special regex characters', async () => {
jest.spyOn(GrouperWorker.prototype as any, 'getProjectPatterns').mockResolvedValue([

Check warning on line 568 in workers/grouper/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ESlint

Unexpected any. Specify a different type
'Error \\[\\d+\\]: .*',
'Warning \\(code=\\d+\\): .*',
]);
Expand Down
2 changes: 1 addition & 1 deletion workers/grouper/tests/mocks/randomId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export function generateRandomId(): string {

return Math.random().toString(RADIX)
.substring(FIRST_RANDOM_START, FIRST_RANDOM_END) + Math.random().toString(RADIX)
.substring(FIRST_RANDOM_START, FIRST_RANDOM_END);
.substring(FIRST_RANDOM_START, FIRST_RANDOM_END);
}
Loading