Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(application-system): Add logging to notification service and make it awaitable #16821

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

norda-gunni
Copy link
Member

@norda-gunni norda-gunni commented Nov 12, 2024

...

Attach a link to issue if relevant

What

Logging applicationIds alongside returned messageIds

Why

For better traceability

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced notification system with improved logging capabilities.
    • Added support for an optional applicationId parameter in notifications.
  • Bug Fixes

    • Improved error handling and asynchronous notification sending for better performance.

@norda-gunni norda-gunni requested a review from a team as a code owner November 12, 2024 13:42
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the functionality and logging capabilities of the ChildrenResidenceChangeServiceV2 and NotificationsService classes. The ChildrenResidenceChangeServiceV2 has updated notification methods to use asynchronous handling with the addition of an applicationId parameter. The NotificationsService has been modified to include a logger for improved traceability and to accommodate the new applicationId in its sendNotification method. Additionally, a LoggingModule has been integrated into the notification module.

Changes

File Path Change Summary
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts Removed Inject decorator from imports; updated sendNotification calls in approvedByOrganization, rejectedByCounterParty, and rejectedByOrganization methods to use await and include applicationId in notifications. Maintained error handling.
libs/application/template-api-modules/src/lib/notification/notifications.module.ts Added LoggingModule to the imports array of ApplicationsNotificationsModule.
libs/application/template-api-modules/src/lib/notification/notifications.service.ts Added logger dependency to constructor; updated sendNotification method to include optional applicationId, changed return type to Promise<CreateNotificationResponse>, and included logging after notification sending.

Possibly related PRs

Suggested labels

automerge, deploy-feature

Suggested reviewers

  • thorkellmani
  • rafnarnason
  • HjorturJ

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
libs/application/template-api-modules/src/lib/notification/notifications.service.ts (1)

27-27: Update examples to use national IDs instead of email addresses

The JSDoc examples use email addresses for recipients, but based on the parameter description and type, it should be using national IDs. This could be misleading for other developers.

Consider updating the examples like this:

-     recipient: '[email protected]',
+     recipient: '1234567890',

Also applies to: 38-38, 52-52, 60-68

libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (3)

224-247: Consider improving caseNumber fallback handling

While the Promise.all implementation for parallel notifications is excellent, the caseNumber fallback to an empty string might not be the best approach. Consider using a more descriptive placeholder or logging when caseNumber is missing.

-caseNumber: caseNumber || '',
+caseNumber: caseNumber || 'PENDING',
+// Add logging when caseNumber is missing
+if (!caseNumber) {
+  this.logger.warn(`No case number available for application ${application.id}`);
+}

301-322: Consider extracting syslumennName resolution logic

The Promise.all implementation for parallel notifications is good. However, the syslumennName resolution logic could be extracted to improve readability and reusability.

+private getSyslumennNameFromChildResidenceInfo(
+  childResidenceInfo: ReturnType<typeof childrenResidenceInfo>
+): string {
+  return syslumennDataFromPostalCode(
+    childResidenceInfo?.future?.address?.postalCode || ''
+  ).name;
+}

 async rejectedByOrganization({ application }: Props) {
   // ... existing code ...
-  const syslumennName = syslumennDataFromPostalCode(
-    childResidenceInfo?.future?.address?.postalCode || '',
-  ).name;
+  const syslumennName = this.getSyslumennNameFromChildResidenceInfo(childResidenceInfo);
   // ... rest of the code ...

Line range hint 185-322: Consider implementing a notification helper method

The notification sending pattern is repeated across multiple methods. Consider implementing a helper method to reduce duplication and ensure consistent handling.

Example implementation:

private async sendApplicationNotification(params: {
  type: NotificationType;
  recipient: string;
  applicationId: string;
  args: Record<string, string>;
}) {
  return this.notificationsService.sendNotification({
    type: params.type,
    messageParties: {
      recipient: params.recipient,
    },
    applicationId: params.applicationId,
    args: params.args,
  });
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a89215d and ffed2e0.

📒 Files selected for processing (3)
  • libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (5 hunks)
  • libs/application/template-api-modules/src/lib/notification/notifications.module.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/notification/notifications.service.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/notification/notifications.module.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/notification/notifications.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (6)
libs/application/template-api-modules/src/lib/notification/notifications.module.ts (2)

5-5: LGTM: Clean import of LoggingModule

The import statement follows the established pattern and uses the proper scoped package.


8-8: LGTM: Module configuration is correct

The LoggingModule is properly added to the imports array while maintaining the existing configuration. This change appropriately supports the enhanced logging capabilities being added to the notification service.

libs/application/template-api-modules/src/lib/notification/notifications.service.ts (2)

1-7: LGTM: Import statements are well-structured

The new imports for logging functionality are properly organized and follow the project's import structure.


13-18: LGTM: Logger injection and configuration are well implemented

The constructor properly injects and configures the logger with a specific context, following dependency injection best practices.

libs/application/template-api-modules/src/lib/modules/templates/children-residence-change-v2/children-residence-change.service.ts (2)

263-268: LGTM! Consistent implementation

The changes maintain consistency with the notification service updates, properly including the applicationId while preserving existing error handling.


185-191: LGTM! Verify notification handling

The changes correctly implement awaitable notifications with application ID tracking. The error handling for missing custody information remains robust.

Let's verify the notification handling:

✅ Verification successful

NotificationType.AssignCounterParty is properly defined and used

The enum member AssignCounterParty is correctly defined in notificationsTemplates.ts and used in children-residence-change.service.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if NotificationType.AssignCounterParty is properly defined
ast-grep --pattern 'enum NotificationType {
  $$$
  AssignCounterParty = $_
  $$$
}'

Length of output: 86


Script:

#!/bin/bash
# Retrieve the full definition of the NotificationType enum
ast-grep --pattern 'enum NotificationType { 
  $$$
}' --file-type typescript

Length of output: 273


Script:

#!/bin/bash
# Search for the definition of AssignCounterParty in the codebase
rg 'AssignCounterParty' --glob '*.ts'

Length of output: 488

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.

Project coverage is 36.44%. Comparing base (da89b62) to head (30055d0).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...nce-change-v2/children-residence-change.service.ts 14.28% 6 Missing ⚠️
...ules/src/lib/notification/notifications.service.ts 60.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16821   +/-   ##
=======================================
  Coverage   36.43%   36.44%           
=======================================
  Files        6852     6853    +1     
  Lines      143537   143469   -68     
  Branches    40966    40940   -26     
=======================================
- Hits        52303    52287   -16     
+ Misses      91234    91182   -52     
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 40.98% <44.44%> (+<0.01%) ⬆️
application-template-api-modules 27.66% <0.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...dules/src/lib/notification/notifications.module.ts 100.00% <100.00%> (ø)
...ules/src/lib/notification/notifications.service.ts 53.33% <60.00%> (+3.33%) ⬆️
...nce-change-v2/children-residence-change.service.ts 17.35% <14.28%> (+0.28%) ⬆️

... and 14 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6293433...30055d0. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 12, 2024

Datadog Report

All test runs 3826366 🔗

3 Total Test Services: 0 Failed, 3 Passed
➡️ Test Sessions change in coverage: 4 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.13s 1 no change Link
application-system-api 0 0 0 112 2 3m 20.9s 1 no change Link
application-template-api-modules 0 0 0 113 0 2m 39.42s 1 no change Link

Copy link
Member

@HjorturJ HjorturJ left a comment

Choose a reason for hiding this comment

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

LGTM

@norda-gunni norda-gunni added the automerge Merge this PR as soon as all checks pass label Nov 12, 2024
@norda-gunni norda-gunni added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Nov 12, 2024
@kodiakhq kodiakhq bot merged commit c788e6a into main Nov 14, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the as-await-messages branch November 14, 2024 09:03
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
…ke it awaitable (#16821)

* chore(application-system): Add logging to notification service and make it awaitable

* Add templateId for clarity

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants