Skip to content

Commit

Permalink
Chore(notifications): added verbose logs for notification rules valid…
Browse files Browse the repository at this point in the history
…ation and sender (#353)

* chore(sender): add verbose logs to sender

* chore(notifier): add verbose logs to rule validator

* tests(notifier): update rule validator tests

* chore(notifier): remove redundant variable
  • Loading branch information
e11sy authored Feb 4, 2025
1 parent e7cb8c1 commit 023352f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
15 changes: 4 additions & 11 deletions workers/notifier/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,9 @@ export default class NotifierWorker extends Worker {
*/
const rules = await this.getFittedRules(projectId, event);

this.logger.info(`Found ${rules} fitted rules for the event for event ${event.groupHash}`);

this.logger.info(`Found ${rules.length} fitted rules for the event ${event.groupHash}`);
for (const rule of rules) {
/**
* If rule is disabled no need to store data in redis
*/
if (rule.isEnabled === false) {
this.logger.info(`Rule ${rule._id} is disabled, skipping`);

continue;
}

/**
* If validation for rule with whatToReceive.New passed, then event is new and we can send it to channels
*/
Expand Down Expand Up @@ -133,6 +124,8 @@ export default class NotifierWorker extends Worker {
try {
new RuleValidator(rule, event).checkAll();
} catch (e) {
this.logger.info(`Rule ${rule._id} does not match becasue of ${e}, skipping...`);

return false;
}

Expand Down
8 changes: 4 additions & 4 deletions workers/notifier/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class RuleValidator {
const { rule } = this;

if (!rule.isEnabled) {
throw Error('Rule is disabled');
throw Error('rule is disabled');
}

return this;
Expand All @@ -66,7 +66,7 @@ export default class RuleValidator {
(event.isNew && rule.whatToReceive === WhatToReceive.New);

if (!result) {
throw Error('Event doesn\'t match `what to receive` filter');
throw Error('event doesn\'t match `what to receive` filter');
}

return this;
Expand All @@ -91,7 +91,7 @@ export default class RuleValidator {
}

if (!result) {
throw Error('Event title doesn\'t include required words');
throw Error('event title doesn\'t include required words');
}

return this;
Expand All @@ -116,7 +116,7 @@ export default class RuleValidator {
}

if (!result) {
throw Error('Event title includes unwanted words');
throw Error('event title includes unwanted words');
}

return this;
Expand Down
8 changes: 4 additions & 4 deletions workers/notifier/tests/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('RuleValidator', () => {

const validator = new RuleValidator(rule, eventMock);

expect(() => validator.checkIfRuleIsOn()).toThrowError('Rule is disabled');
expect(() => validator.checkIfRuleIsOn()).toThrowError('rule is disabled');
});
});

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('RuleValidator', () => {

const validator = new RuleValidator(rule, event);

expect(() => validator.checkWhatToReceive()).toThrowError('Event doesn\'t match `what to receive` filter');
expect(() => validator.checkWhatToReceive()).toThrowError('event doesn\'t match `what to receive` filter');
});
});

Expand Down Expand Up @@ -113,7 +113,7 @@ describe('RuleValidator', () => {

const validator = new RuleValidator(rule, event);

expect(() => validator.checkIncludingWords()).toThrowError('Event title doesn\'t include required words');
expect(() => validator.checkIncludingWords()).toThrowError('event title doesn\'t include required words');
});
});

Expand All @@ -140,7 +140,7 @@ describe('RuleValidator', () => {

const validator = new RuleValidator(rule, event);

expect(() => validator.checkExcludingWords()).toThrowError('Event title includes unwanted words');
expect(() => validator.checkExcludingWords()).toThrowError('event title includes unwanted words');
});

it('should pass if words list is empty', () => {
Expand Down
2 changes: 2 additions & 0 deletions workers/sender/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export default abstract class SenderWorker extends Worker {
notificationType = 'several-events';
}

this.logger.info(`Sending ${notificationType} notification to ${channel.endpoint}`);

this.provider.send(channel.endpoint, {
type: notificationType,
payload: {
Expand Down
2 changes: 1 addition & 1 deletion workers/telegram/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class TelegramProvider extends NotificationsProvider {

switch (notification.type) {
case 'event': template = templates.EventTpl; break;
case 'several-events':template = templates.SeveralEventsTpl; break;
case 'several-events': template = templates.SeveralEventsTpl; break;
/**
* @todo add assignee notification for telegram provider
*/
Expand Down

0 comments on commit 023352f

Please sign in to comment.