-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
📝 WalkthroughWalkthroughThe pull request introduces several changes across multiple files in the Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Auth-service changes in this PR available for preview here |
There was a problem hiding this 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
📒 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 changesAfter 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:
- Are the changes for logging Nginx requests implemented in other files not included in this review?
- If not, what is the relationship between the import path change and the stated PR objective?
- 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 consistencyThe 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:
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.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.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" fisrc/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:
- It might be worthwhile to verify that all other parts of the codebase that rely on these job modules have been updated accordingly.
- 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"); |
There was a problem hiding this comment.
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
logObject("Request Body", requestBody); | ||
logObject("logging the entire req", req); |
There was a problem hiding this comment.
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:
-
Security: Logging the entire request object might inadvertently expose sensitive information. Consider implementing a sanitization step to remove or mask sensitive data before logging.
-
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.
-
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.
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
Affected Services
API Documentation Updated?
Additional Notes
None
Summary by CodeRabbit
New Features
Bug Fixes
Chores