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

just logging the entire req from Nginx #3542

Merged
merged 1 commit into from
Sep 29, 2024
Merged

Conversation

Baalmart
Copy link
Contributor

@Baalmart Baalmart commented Sep 29, 2024

Description

just logging the entire req from Nginx. This is all part of our investigations as to why we are not receiving the request body in the application server. So we are trying logging the entire request object to see what's being received.

Changes Made

  • just logging the entire req from Nginx

Affected Services

  • Which services were modified:
    • Auth Service

API Documentation Updated?

  • Yes, API documentation was updated
  • No, API documentation does not need updating

Additional Notes

None

Summary by CodeRabbit

  • New Features

    • Enhanced logging functionality for incoming requests, providing more context in the logs.
  • Bug Fixes

    • Updated import paths for job modules to reflect the new directory structure, ensuring correct module resolution.
  • Chores

    • Adjusted logger initialization strings across various job scripts to accurately represent their file paths.

Copy link

codecov bot commented Sep 29, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 29.89%. Comparing base (07b88f9) to head (047d223).
Report is 2 commits behind head on staging.

Files with missing lines Patch % Lines
src/auth-service/bin/server.js 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           staging    #3542   +/-   ##
========================================
  Coverage    29.89%   29.89%           
========================================
  Files          184      184           
  Lines        24692    24692           
  Branches      3257     3257           
========================================
  Hits          7382     7382           
  Misses       17188    17188           
  Partials       122      122           
Flag Coverage Δ
29.89% <25.00%> (ø)

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

Files with missing lines Coverage Δ
src/auth-service/bin/index.js 20.68% <100.00%> (ø)
src/auth-service/bin/jobs/kafka-consumer.js 21.27% <ø> (ø)
src/auth-service/bin/server.js 11.50% <0.00%> (ø)

Copy link
Contributor

coderabbitai bot commented Sep 29, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several changes across multiple files in the src/auth-service directory. The primary modifications include updating import paths for various job modules to reflect a new directory structure, enhancing logging statements for clarity, and adjusting logger initialization strings to accurately represent file locations. These changes aim to improve the organization and readability of the codebase.

Changes

Files Change Summary
src/auth-service/bin/index.js, src/auth-service/bin/jobs/test/ut_kafka-consumer.js Updated import paths for kafkaConsumer from relative to absolute paths.
src/auth-service/bin/jobs/active-status-job.js, incomplete-profile-job.js, token-expiration-job.js, kafka-consumer.js Modified logger initialization strings to reflect the correct file paths, enhancing logging clarity.
src/auth-service/bin/server.js Updated import paths for job modules to include the jobs directory in their paths.
src/auth-service/middleware/passport.js Enhanced logging functionality by modifying request body logs and adding a log for the entire request object.

Possibly related PRs

🌟 In the code's embrace, paths now align,
With logs that speak clear, like a well-crafted rhyme.
Jobs find their place, in the directory's heart,
Each change a note, in the developer's art.
So here's to the tweaks, both subtle and bright,
Making our codebase a joy to ignite! 🎉


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

Auth-service changes in this PR available for preview here

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 07b88f9 and 047d223.

📒 Files selected for processing (8)
  • src/auth-service/bin/index.js (1 hunks)
  • src/auth-service/bin/jobs/active-status-job.js (1 hunks)
  • src/auth-service/bin/jobs/incomplete-profile-job.js (1 hunks)
  • src/auth-service/bin/jobs/kafka-consumer.js (1 hunks)
  • src/auth-service/bin/jobs/test/ut_kafka-consumer.js (1 hunks)
  • src/auth-service/bin/jobs/token-expiration-job.js (1 hunks)
  • src/auth-service/bin/server.js (1 hunks)
  • src/auth-service/middleware/passport.js (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • src/auth-service/bin/jobs/active-status-job.js
  • src/auth-service/bin/jobs/incomplete-profile-job.js
  • src/auth-service/bin/jobs/kafka-consumer.js
  • src/auth-service/bin/jobs/token-expiration-job.js
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/auth-service/bin/server.js

[warning] 22-24: src/auth-service/bin/server.js#L22-L24
Added lines #L22 - L24 were not covered by tests

🔇 Additional comments (3)
src/auth-service/bin/index.js (2)

Line range hint 1-43: Discrepancy between PR objective and implemented changes

After reviewing the entire file, I noticed that there are no changes related to "logging the entire req from Nginx" as stated in the PR objective. The only modification in this file is the import path change for the kafkaConsumer module.

Could you please clarify:

  1. Are the changes for logging Nginx requests implemented in other files not included in this review?
  2. If not, what is the relationship between the import path change and the stated PR objective?
  3. If this PR's scope has changed, should the PR description be updated to reflect the current changes accurately?

To check if logging changes are implemented elsewhere, you can run:

This will help identify if the logging changes are present in other parts of the codebase.


5-5: Approve import path change with suggestions for consistency

The modification of the import statement from a relative path to an absolute path using module aliases is a positive change. It can enhance code readability and maintainability by providing consistent import paths across the project.

However, I have a few points to consider:

  1. Please ensure that the module alias @bin is properly configured in your project setup. This is crucial for the new import path to work correctly.

  2. For consistency, you might want to consider applying similar changes to other import statements in this file. For example, require("./server") could potentially be updated to use an absolute path with module aliases.

  3. While this change is beneficial, it doesn't seem directly related to the PR objective of "logging the entire req from Nginx". Could you clarify how this change contributes to that goal?

To verify the module alias configuration, please run the following command:

#!/bin/bash
# Description: Check for module alias configuration in package.json or tsconfig.json

# Check package.json
if jq -e '._moduleAliases | has("@bin")' package.json > /dev/null 2>&1; then
    echo "Module alias @bin is configured in package.json"
else
    echo "Module alias @bin is not found in package.json"
fi

# Check tsconfig.json if it exists
if [ -f tsconfig.json ]; then
    if jq -e '.compilerOptions.paths | has("@bin")' tsconfig.json > /dev/null 2>&1; then
        echo "Module alias @bin is configured in tsconfig.json"
    else
        echo "Module alias @bin is not found in tsconfig.json"
    fi
else
    echo "tsconfig.json not found"
fi
src/auth-service/bin/server.js (1)

22-24: Nicely done on the import path updates!

I appreciate the consistent refactoring of the job module imports. This change suggests a thoughtful reorganization of the project structure, which can improve code maintainability.

A couple of friendly suggestions:

  1. It might be worthwhile to verify that all other parts of the codebase that rely on these job modules have been updated accordingly.
  2. Consider adding test coverage for these imports to ensure they're working as expected in different environments.

To help ensure the changes are consistent throughout the codebase, you might want to run the following command:

This will help identify any places where the old import paths might still be in use and confirm the usage of the new paths.

Would you like me to draft some test cases to cover these import statements? I'd be happy to help ensure robust test coverage for this part of the codebase.

✅ Verification successful

Great job on updating the import paths!

The shell script confirmed that there are no remaining old import paths and that all imports in server.js are correctly using the new paths. This consistency suggests that the refactoring was successfully implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining old import paths and list files using the new import paths.

echo "Checking for any remaining old import paths:"
rg --type js "@bin/(active-status-job|token-expiration-job|incomplete-profile-job)"

echo "\nListing files using the new import paths:"
rg --type js "@bin/jobs/(active-status-job|token-expiration-job|incomplete-profile-job)"

Length of output: 593

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 22-24: src/auth-service/bin/server.js#L22-L24
Added lines #L22 - L24 were not covered by tests

@@ -1,7 +1,7 @@
require("module-alias/register");
const { expect } = require("chai");
const sinon = require("sinon");
const kafkaConsumer = require("@bin/kafka-consumer");
const kafkaConsumer = require("@bin/jobs/kafka-consumer");
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Remaining Instances of the Old Import Path Detected

The following files still use the old import path "@bin/kafka-consumer":

  • src/incentives/bin/test/ut_kafka-consumer.js
  • src/incentives/bin/test/ut_index.js
  • src/blog-content-manager/bin/test/ut_kafka-consumer.js
  • src/blog-content-manager/bin/test/ut_index.js
  • src/auth-service/bin/test/ut_index.js

Please update these import statements to "@bin/jobs/kafka-consumer" to maintain consistency across the codebase.

🔗 Analysis chain

Excellent restructuring of the kafka-consumer module!

The updated import path reflects a more organized project structure, which is a positive change. The kafka-consumer module is now appropriately placed within the 'jobs' subdirectory.

To ensure this change doesn't introduce any issues elsewhere in the codebase, let's verify other occurrences of the old import path:

If the first command returns any results, those files may need to be updated. The second command should confirm the existence of the kafka-consumer.js file in the new location.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old import path

# Test: Search for the old import path. Expect: No results.
rg --type js '"@bin/kafka-consumer"'

# Test: Verify the new module location exists
fd -t f kafka-consumer.js src/auth-service/bin/jobs

Length of output: 1016

Comment on lines +377 to +378
logObject("Request Body", requestBody);
logObject("logging the entire req", req);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider security and performance implications of extensive logging.

The addition of these logging statements aligns well with the PR objective of implementing logging for the entire request received from Nginx. This enhancement will undoubtedly improve our ability to debug and monitor incoming requests. However, I have a few friendly suggestions to ensure we're implementing this feature in the most effective and secure manner:

  1. Security: Logging the entire request object might inadvertently expose sensitive information. Consider implementing a sanitization step to remove or mask sensitive data before logging.

  2. Timing: These logging statements are placed at the beginning of the function, before any authentication checks. You might want to consider moving them after initial validations to avoid unnecessary logging of unauthorized requests.

  3. Performance: The logObject function might not be optimized for large objects like the entire request. Consider using a streaming or chunked logging approach for large objects to minimize memory usage.

Here's a potential refactoring to address these points:

- logObject("Request Body", requestBody);
- logObject("logging the entire req", req);
+ const sanitizedReq = sanitizeRequest(req);
+ logObject("Sanitized Request Body", sanitizedReq.body);
+ if (process.env.NODE_ENV === 'development') {
+   logObject("Full sanitized request (dev only)", sanitizedReq);
+ }

function sanitizeRequest(req) {
  // Implement sanitization logic here
  // e.g., remove sensitive headers, mask PII in body, etc.
}

This approach sanitizes the request, always logs the body (which is likely smaller), and only logs the full request in development environments. Remember to implement the sanitizeRequest function to remove or mask sensitive data!

Committable suggestion was skipped due to low confidence.

@Baalmart Baalmart merged commit 2f3f0f0 into staging Sep 29, 2024
49 of 50 checks passed
@Baalmart Baalmart deleted the log-entire-request branch September 29, 2024 08:18
@Baalmart Baalmart mentioned this pull request Sep 29, 2024
11 tasks
@coderabbitai coderabbitai bot mentioned this pull request Sep 29, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant