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(j-s): Logging more info for system status #16808

Merged
merged 6 commits into from
Nov 14, 2024

Conversation

unakb
Copy link
Member

@unakb unakb commented Nov 12, 2024

Logga betur successful köll í xrd-api þegar birting uppfærist.

What

Added logs to get a better feel for what´s going on in the system

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

Release Notes

  • New Features

    • Enhanced logging capabilities for case events in the EventService, including specific event tracking.
    • Added logging for successful subpoena deliveries in the SubpoenaService.
  • Bug Fixes

    • Improved error handling logging in the SubpoenaService during delivery processes.
  • Refactor

    • Simplified logging processes in the CaseService and LimitedAccessCaseService by removing unnecessary logging statements.
    • Updated logging level from debug to info in the AppController for subpoena updates.
    • Clarified API documentation for indictment case retrieval in the InternalCaseController to specify digital mailbox context.
    • Refined filtering logic in the InternalCaseService to ensure only relevant indictment cases are retrieved.

@unakb unakb requested a review from a team as a code owner November 12, 2024 09:31
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The pull request introduces several changes across multiple service files in the judicial system application. Key modifications include the removal of logging related to accusedPostponedAppealDate in the CaseService and LimitedAccessCaseService, updates to API endpoint descriptions in the InternalCaseController, enhancements to filtering logic in the InternalCaseService, and the addition of specific event logging in the EventService. Additionally, a new logging statement is added in the SubpoenaService, and the logging level is adjusted in the AppController. Overall, the changes streamline logging and improve data retrieval without altering core functionalities.

Changes

File Path Change Summary
.../case/case.service.ts Removed logging for accusedPostponedAppealDate updates.
.../case/internalCase.controller.ts Updated API endpoint descriptions to specify "for digital mailbox."
.../case/internalCase.service.ts Updated getIndictmentCases and getIndictmentCase methods to include additional filtering criteria.
.../case/limitedAccessCase.service.ts Removed logging for accusedPostponedAppealDate in the update method.
.../event/event.service.ts Added caseEventsToLog constant and logInfo method for specific event logging.
.../subpoena/subpoena.service.ts Added logging statement in deliverSubpoenaToPolice method to confirm delivery to police.
.../xrd-api/app.controller.ts Changed logging level from debug to info in updateSubpoena method.

Possibly related PRs

Suggested reviewers

  • unakb

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 71ee33d and 1d39350.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts

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: 2

🧹 Outside diff range and nitpick comments (3)
apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

74-76: Consider enhancing logging with more context and result tracking

While the current logging is good, consider adding more structured context and result tracking for better observability:

-    this.logger.info(`Updating subpoena ${subpoenaId}`)
+    this.logger.info('Updating subpoena', {
+      subpoenaId,
+      updateType: updateSubpoena.type,
+      operation: 'start'
+    })
 
-    return this.appService.updateSubpoena(subpoenaId, updateSubpoena)
+    const result = await this.appService.updateSubpoena(subpoenaId, updateSubpoena)
+    this.logger.info('Subpoena updated successfully', {
+      subpoenaId,
+      operation: 'complete'
+    })
+    return result
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

Line range hint 1-251: Consider splitting event notification and logging responsibilities

The EventService currently handles both Slack notifications and system logging, which violates the Single Responsibility Principle. Consider splitting these into separate services:

  1. EventNotificationService: Handle Slack notifications
  2. EventLoggingService: Handle system logging

This would:

  • Improve maintainability
  • Make the code easier to test
  • Allow independent scaling of notification and logging systems
  • Make it easier to add new notification channels or logging backends
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1)

334-337: Enhance the log message with additional context.

The addition of logging for successful subpoena delivery is good. However, consider enriching the log message with more context for better traceability.

-      this.logger.info(
-        `Subpoena ${createdSubpoena.subpoenaId} delivered to police`,
-      )
+      this.logger.info(
+        `Subpoena ${createdSubpoena.subpoenaId} delivered to police for case ${theCase.id}`,
+        {
+          caseId: theCase.id,
+          defendantId: defendant.id,
+          subpoenaId: createdSubpoena.subpoenaId
+        }
+      )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df859d4 and 35f3862.

📒 Files selected for processing (5)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/event/event.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1 hunks)
  • apps/judicial-system/xrd-api/src/app/app.controller.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

74-74: LGTM! Appropriate logging level change

The change from debug to info level is appropriate as subpoena updates represent significant business events that should be visible in standard logging output.

apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

81-90: LGTM! Well-chosen events for logging

The selection of events to log covers critical system state transitions and important operational events, which aligns well with the PR objective of improving system status visibility.

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: 2

🧹 Outside diff range and nitpick comments (5)
apps/judicial-system/xrd-api/src/app/app.controller.ts (2)

71-77: Consider enhancing error handling and logging context.

While the logging change is good, consider these improvements:

  1. Add try-catch block to handle service errors explicitly
  2. Include update details in the log message for better traceability

Consider applying this enhancement:

  @Patch('subpoena/:subpoenaId')
  @ApiResponse({ status: 500, description: 'Failed to update subpoena' })
  async updateSubpoena(
    @Param('subpoenaId', new ParseUUIDPipe()) subpoenaId: string,
    @Body() updateSubpoena: UpdateSubpoenaDto,
  ): Promise<SubpoenaResponse> {
-    this.logger.info(`Updating subpoena ${subpoenaId}`)
-    return this.appService.updateSubpoena(subpoenaId, updateSubpoena)
+    try {
+      this.logger.info(`Updating subpoena ${subpoenaId}`, {
+        operation: 'updateSubpoena',
+        updates: Object.keys(updateSubpoena),
+      })
+      return await this.appService.updateSubpoena(subpoenaId, updateSubpoena)
+    } catch (error) {
+      this.logger.error(`Failed to update subpoena ${subpoenaId}`, error)
+      throw new InternalServerErrorException('Failed to update subpoena')
+    }
  }

71-71: Enhance Swagger documentation for better API clarity.

The current API response documentation could be more descriptive.

Consider enhancing the Swagger decoration:

- @ApiResponse({ status: 500, description: 'Failed to update subpoena' })
+ @ApiResponse({ type: SubpoenaResponse, description: 'Updates an existing subpoena with the provided data' })
+ @ApiResponse({ status: 400, description: 'Invalid subpoena ID or update data format' })
+ @ApiResponse({ status: 500, description: 'Internal server error while updating subpoena' })
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

81-90: LGTM! Consider adding documentation.

The selection of events to log is well-thought-out and covers critical system state transitions. Consider adding a brief comment explaining the criteria for including events in this list.

+// Events that require additional logging for system status monitoring
 const caseEventsToLog = [
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1)

334-337: Enhance the logging context for better traceability.

The addition of success logging is valuable for tracking subpoena delivery status. However, consider enriching the log message with more context for better debugging and monitoring.

Consider applying this improvement:

-      this.logger.info(
-        `Subpoena ${createdSubpoena.subpoenaId} delivered to police`,
-      )
+      this.logger.info(
+        `Subpoena ${createdSubpoena.subpoenaId} delivered to police`,
+        {
+          caseId: theCase.id,
+          defendantId: defendant.id,
+          subpoenaId: createdSubpoena.subpoenaId,
+          userId: user.id,
+        }
+      )

This structured logging approach will:

  • Make logs more queryable in log aggregation systems
  • Provide complete context for troubleshooting
  • Enable better metrics and analytics
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)

1226-1231: LGTM! Consider extracting the allowed states into a constant.

The filtering logic correctly prevents exposure of deleted or inaccessible cases. This is a good security practice.

Consider extracting the allowed states into a constant for better maintainability:

+const ACCESSIBLE_INDICTMENT_STATES = [
+  CaseState.RECEIVED,
+  CaseState.COMPLETED,
+  CaseState.WAITING_FOR_CANCELLATION,
+] as const;

async getIndictmentCases(nationalId: string): Promise<Case[]> {
  return this.caseModel.findAll({
    // ... other options ...
    where: {
      type: CaseType.INDICTMENT,
      // Make sure we don't send cases that are in deleted or other inaccessible states
-     state: [
-       CaseState.RECEIVED,
-       CaseState.COMPLETED,
-       CaseState.WAITING_FOR_CANCELLATION,
-     ],
+     state: ACCESSIBLE_INDICTMENT_STATES,
      '$defendants.national_id$': normalizeAndFormatNationalId(nationalId),
    },
  })
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df859d4 and c42f518.

📒 Files selected for processing (7)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/event/event.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1 hunks)
  • apps/judicial-system/xrd-api/src/app/app.controller.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts
🧰 Additional context used
📓 Path-based instructions (4)
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (1)
apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

74-74: LGTM! Logging level change aligns with PR objectives.

The change from debug to info level is appropriate for tracking system status updates.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 13.33333% with 13 lines in your changes missing coverage. Please review.

Project coverage is 36.46%. Comparing base (9685529) to head (1d39350).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tem/backend/src/app/modules/event/event.service.ts 14.28% 12 Missing ⚠️
...ckend/src/app/modules/subpoena/subpoena.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16808      +/-   ##
==========================================
+ Coverage   36.45%   36.46%   +0.01%     
==========================================
  Files        6851     6852       +1     
  Lines      143558   143594      +36     
  Branches    40977    41040      +63     
==========================================
+ Hits        52330    52360      +30     
- Misses      91228    91234       +6     
Flag Coverage Δ
judicial-system-backend 55.13% <13.33%> (-0.04%) ⬇️
judicial-system-web 27.16% <ø> (ø)

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

Files with missing lines Coverage Δ
...ystem/backend/src/app/modules/case/case.service.ts 90.63% <ø> (+0.32%) ⬆️
...nd/src/app/modules/case/internalCase.controller.ts 97.60% <ø> (ø)
...ckend/src/app/modules/case/internalCase.service.ts 85.12% <ø> (ø)
.../src/app/modules/case/limitedAccessCase.service.ts 72.56% <ø> (-0.71%) ⬇️
...ckend/src/app/modules/subpoena/subpoena.service.ts 26.41% <0.00%> (-0.26%) ⬇️
...tem/backend/src/app/modules/event/event.service.ts 30.13% <14.28%> (-3.77%) ⬇️

... and 25 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 9685529...1d39350. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 12, 2024

Datadog Report

All test runs 309c0ae 🔗

2 Total Test Services: 0 Failed, 2 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.03%), 1 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 0 0 0 21271 0 22m 35.59s 1 decreased (-0.03%) Link
judicial-system-xrd-api 0 0 0 6 0 5.81s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-backend - jest 58.7% (-0.03%) - Details

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 (1)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

226-250: Consider adding XRD-specific logging information

To better understand XRD-API operations, consider adding more context when logging CREATE_XRD events.

  switch (event) {
+   case 'CREATE_XRD':
+     extraInfo = `source: xrd-api, prosecutorsOffice: ${theCase.prosecutorsOffice?.name}`
+     break
    case 'SCHEDULE_COURT_DATE':
      // existing code...
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c42f518 and 71ee33d.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/event/event.service.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (2)

81-90: LGTM! Well-defined event filtering.

The constant effectively defines a focused set of important events to log, which aligns well with the PR objective of improving system status tracking.


166-166: Refer to previous review comment about moving logInfo call

The previous review comment about moving the logInfo call inside the try block is still valid and should be addressed.

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 (1)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

81-90: LGTM! Consider documenting selection criteria.

The event filtering list is well-structured and includes key system events. Consider adding a comment explaining why these specific events were chosen for logging.

+// Events that represent significant state changes or user actions that require monitoring
 const caseEventsToLog = [
   'CREATE',
   'CREATE_XRD',
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c42f518 and 71ee33d.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/event/event.service.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (1)
apps/judicial-system/backend/src/app/modules/event/event.service.ts (1)

166-166: Placement of logInfo call already addressed.

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Nov 14, 2024
@kodiakhq kodiakhq bot merged commit 64ad820 into main Nov 14, 2024
34 checks passed
@kodiakhq kodiakhq bot deleted the j-s/info-log-for-monitoring branch November 14, 2024 14:07
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* chore(j-s): Logging more info for system status

* fix(j-s): Filtering case list to remove deleted indictments for digital mailbox

* Update event.service.ts

* Update event.service.ts

---------

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