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(sqs): Better logs #16776

Merged
merged 6 commits into from
Nov 27, 2024
Merged

chore(sqs): Better logs #16776

merged 6 commits into from
Nov 27, 2024

Conversation

AndesKrrrrrrrrrrr
Copy link
Member

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr commented Nov 8, 2024

Currently logging raw args as list of key/value objects.

Summary by CodeRabbit

  • New Features

    • Enhanced logging for notifications, providing clearer context with structured argument representation and additional queue details.
    • Added a new property queueName to improve queue management in the service.
  • Bug Fixes

    • Improved error handling and assertions for queue operations.
  • Documentation

    • No changes made to existing documentation annotations.

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The pull request introduces modifications to two components: the NotificationsController and the QueueService. In NotificationsController, the logging within the createHnippNotification method has been enhanced by removing the args property and replacing it with a structured representation of the arguments, along with additional context about the queue. In QueueService, a new property queueName has been added, initialized in the constructor, allowing for direct reference to the queue name. Both components maintain their existing functionalities and control flows.

Changes

File Path Change Summary
apps/services/user-notification/src/app/modules/not... Updated logging in createHnippNotification to improve clarity by replacing args with flattenedArgs and including queue URL and name. No changes to method signatures or overall functionality.
libs/message-queue/src/lib/nest/queue.service.ts Added queueName property in QueueService and updated constructor to initialize it from config. Control flow and logic remain unchanged.

Possibly related PRs

  • fix(auth-admin): Move sleep logic from messgeHandler to worker service #16712: The changes in this PR involve moving sleep logic related to working hours from the message handler to the worker service, which is directly related to the NotificationsController class's logging improvements in the main PR, as both deal with notification processing and management during specific operational hours.

Suggested labels

deploy-feature

Suggested reviewers

  • eirikurn

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.

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr marked this pull request as ready for review November 8, 2024 10:37
@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr requested review from a team as code owners November 8, 2024 10:37
@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr added the automerge Merge this PR as soon as all checks pass label Nov 8, 2024
Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.89%. Comparing base (15571ef) to head (adc2f04).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16776      +/-   ##
==========================================
+ Coverage   35.69%   35.89%   +0.20%     
==========================================
  Files        6939     6919      -20     
  Lines      147080   146870     -210     
  Branches    41832    42106     +274     
==========================================
+ Hits        52497    52719     +222     
+ Misses      94583    94151     -432     
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 38.74% <ø> (-0.01%) ⬇️
application-template-api-modules 27.77% <ø> (-0.03%) ⬇️
judicial-system-backend 55.63% <ø> (ø)
message-queue 68.13% <100.00%> (-0.66%) ⬇️
services-user-notification 46.76% <100.00%> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
.../modules/notifications/notifications.controller.ts 100.00% <ø> (ø)
libs/message-queue/src/lib/nest/queue.service.ts 90.90% <100.00%> (+0.28%) ⬆️

... and 173 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 15571ef...adc2f04. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 8, 2024

Datadog Report

All test runs 266725f 🔗

34 Total Test Services: 0 Failed, 32 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.75%), 1 increased (+0.1%), 152 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 7.02s 1 no change Link
api 0 0 0 4 0 2.37s 1 no change Link
application-api-files 0 0 0 2 0 4.26s 1 no change Link
application-core 0 0 0 97 0 14.74s 1 no change Link
application-system-api 0 0 0 34 0 2m 15.44s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 24.65s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 18.34s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 11.82s 1 no change Link
application-templates-driving-license 0 0 0 13 0 16.5s 1 no change Link
application-templates-example-payment 0 0 0 2 0 11.44s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • message-queue - jest 68.52% (-0.75%) - Details

Copy link
Member

@rafnarnason rafnarnason left a comment

Choose a reason for hiding this comment

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

lgtm

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 (2)
libs/message-queue/src/lib/nest/queue.service.ts (1)

10-10: Consider making queueName readonly

The queueName property should be immutable since it's initialized once in the constructor and shouldn't change during the service lifecycle.

- queueName: string
+ readonly queueName: string
apps/services/user-notification/src/app/modules/notifications/notifications.controller.ts (1)

Line range hint 96-100: Consider using Array.reduce for better readability

The args flattening logic could be more concise using Array.reduce.

-    const flattenedArgs: Record<string, string> = {}
-    for (const arg of body.args) {
-      flattenedArgs[arg.key] = arg.value
-    }
+    const flattenedArgs = body.args.reduce<Record<string, string>>(
+      (acc, { key, value }) => ({ ...acc, [key]: value }),
+      {}
+    )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1805590 and df13ffd.

📒 Files selected for processing (2)
  • apps/services/user-notification/src/app/modules/notifications/notifications.controller.ts (1 hunks)
  • libs/message-queue/src/lib/nest/queue.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/services/user-notification/src/app/modules/notifications/notifications.controller.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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."
libs/message-queue/src/lib/nest/queue.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 (3)
libs/message-queue/src/lib/nest/queue.service.ts (1)

10-14: Verify the usage of queueName property

Let's verify how this new property is being used across the codebase to ensure it meets the logging improvement objectives.

✅ Verification successful

No issues found with queueName property addition

The queueName property is appropriately used for queue creation and configuration, with proper logging in place. The property is:

  • Used internally by the QueueService for queue creation and management
  • Referenced in dead letter queue configuration
  • Logged appropriately during queue creation via ClientService
  • Not used in any problematic contexts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct usage of queueName property
echo "=== Direct queueName property usage ==="
rg -t typescript "\.queueName" --no-filename

# Search for logging related to queue names
echo -e "\n=== Queue name logging patterns ==="
rg -t typescript "log.*queue.*name" --no-filename

Length of output: 344


Script:

#!/bin/bash
# Search for direct usage of queueName property without file type restriction
echo "=== Direct queueName property usage ==="
rg "\.queueName"

# Search for logging related to queue names
echo -e "\n=== Queue name logging patterns ==="
rg "log.*queue.*name"

# Find all TypeScript files that might be related to queues
echo -e "\n=== Queue-related TypeScript files ==="
fd -e ts -e tsx queue

Length of output: 132621


Script:

#!/bin/bash
# Search for queueName property usage in TypeScript files
echo "=== queueName property usage ==="
ast-grep --pattern 'queueName' -l ts

# Search for queue-related logging patterns
echo -e "\n=== Queue logging patterns ==="
rg -l "log.*queue" -g "*.ts"

# Find all queue-related TypeScript files
echo -e "\n=== Queue-related files ==="
fd -e ts -e tsx -p "queue|Queue"

Length of output: 1864


Script:

#!/bin/bash
# Check the content of queue.service.ts to understand queueName usage
echo "=== queue.service.ts content ==="
rg -A 5 -B 5 "queueName" libs/message-queue/src/lib/nest/queue.service.ts

# Check for references to queueName in logging contexts
echo -e "\n=== Queue name in logging contexts ==="
rg "log.*queueName|queueName.*log" -A 2 -B 2

# Check client.service.ts for queue name usage in logging
echo -e "\n=== Client service queue name usage ==="
rg "queue.*name" libs/message-queue/src/lib/nest/client.service.ts

Length of output: 1794

apps/services/user-notification/src/app/modules/notifications/notifications.controller.ts (2)

Line range hint 1-24: LGTM! Follows NestJS architectural patterns

The implementation adheres to NestJS best practices with proper separation of concerns, dependency injection, and API documentation.


108-109: LGTM! Improved log structure enhances observability

The changes improve log clarity by:

  1. Removing redundant args
  2. Adding queue context for better filtering

This aligns well with the PR objective of enhancing logging clarity.

@kodiakhq kodiakhq bot merged commit 34a9064 into main Nov 27, 2024
46 checks passed
@kodiakhq kodiakhq bot deleted the chore/sqs-more branch November 27, 2024 16:03
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