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

fix: partial response handling oauthv2 is enabled #4653

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

sanpj2292
Copy link
Contributor

@sanpj2292 sanpj2292 commented May 6, 2024

Description

When partial responses are to be handled for destinations that are on proxy v1, we are setting 200 status for all of them.
Through this PR, we are aiming to fix this.

Note: additionally info logging for checking oauthv2 flag has been moved to debug logging

Linear Ticket

Resolves INT-2100

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • Bug Fixes

    • Improved logging granularity by updating log levels from Info to Debug for OAuthV2-related messages.
  • Tests

    • Aligned test cases with standard HTTP status codes for better clarity and consistency.
  • Refactor

    • Removed redundant code related to oauthV2Enabled in the proxy request method to streamline response handling.

- chore: propagate interceptor response to jobsdb
- chore: add documentation
- chore: add test-cases
@sanpj2292 sanpj2292 self-assigned this May 6, 2024
Copy link
Contributor

coderabbitai bot commented May 6, 2024

Walkthrough

The changes primarily focus on refining logging and response handling within the transformer and worker components. Logging levels for specific OAuthV2-related messages are adjusted from Info to Debug for less verbosity. Response metadata handling is enhanced based on interceptor responses. In tests, HTTP status codes are standardized using http constants for better clarity. Additionally, the oauthV2Enabled block is removed from the worker's proxyRequest method.

Changes

File Path Change Summary
router/transformer/transformer.go Updated logging levels from Info to Debug for OAuthV2 messages; enhanced response metadata handling based on interceptor responses.
router/transformer/transformer_test.go Standardized HTTP status codes using http constants in test cases for clarity.
router/worker.go Removed oauthV2Enabled block affecting response status codes, bodies, and content type assignment.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Transformer
    participant OAuthInterceptor
    participant Backend

    Client->>Transformer: Send Request
    Transformer->>OAuthInterceptor: Check OAuthV2
    OAuthInterceptor-->>Transformer: Interceptor Response
    Transformer->>Backend: Forward Request
    Backend-->>Transformer: Response
    Transformer-->>Client: Forward Response

Poem

In the land of code, where changes flow,
Debug logs now whisper, info shouts no more.
HTTP constants stand tall, clear as day,
OAuth's grip loosens, paving a new way.
CodeRabbit smiles, in the fields of green,
For clarity and precision, like never seen.
🌟🐰


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

codecov bot commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.64%. Comparing base (1ff62ff) to head (91cf43d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4653      +/-   ##
==========================================
+ Coverage   74.61%   74.64%   +0.03%     
==========================================
  Files         414      414              
  Lines       48654    48657       +3     
==========================================
+ Hits        36304    36322      +18     
+ Misses       9966     9955      -11     
+ Partials     2384     2380       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@achettyiitr achettyiitr left a comment

Choose a reason for hiding this comment

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

Approved with minor changes.

router/transformer/transformer.go Outdated Show resolved Hide resolved
router/transformer/transformer_test.go Outdated Show resolved Hide resolved
router/transformer/transformer_test.go Outdated Show resolved Hide resolved
router/transformer/transformer_test.go Outdated Show resolved Hide resolved
@achettyiitr achettyiitr deleted the branch master May 22, 2024 19:03
@sanpj2292 sanpj2292 requested a review from koladilip May 30, 2024 10:35
@sanpj2292 sanpj2292 reopened this May 30, 2024
@sanpj2292 sanpj2292 changed the base branch from release/1.25.x to master June 10, 2024 04:49
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: 3

Outside diff range and nitpick comments (4)
router/transformer/transformer_test.go (4)

Line range hint 745-754: Refactor repeated test case structures for efficiency.

The test cases in TestProxyRequest have a lot of repeated setup and teardown code. Consider using table-driven tests or helper functions to reduce redundancy and improve maintainability.

Also applies to: 799-799, 814-817, 831-840, 885-885, 895-896, 900-903, 917-926, 971-971, 986-989, 1003-1012, 1057-1057, 1072-1075, 1090-1099, 1144-1144, 1156-1156, 1200-1200, 1213-1213, 1252-1252, 1264-1264, 1302-1302, 1313-1313


Line range hint 745-754: Ensure proper cleanup and resource management in tests.

The tests in TestRouterTransformationWithOAuthV2 do not consistently ensure that all resources (like HTTP test servers) are properly closed. This can lead to resource leaks during testing.

+ defer svr.Close()
+ defer cfgBeSvr.Close()

Also applies to: 799-799, 814-817, 831-840, 885-885, 895-896, 900-903, 917-926, 971-971, 986-989, 1003-1012, 1057-1057, 1072-1075, 1090-1099, 1144-1144, 1156-1156, 1200-1200, 1213-1213, 1252-1252, 1264-1264, 1302-1302, 1313-1313


Line range hint 745-754: Use constants for repeated literal values.

In TestTransformNoValidationErrors, the same URL and other configuration values are repeated multiple times. Consider defining these as constants at the beginning of your test file to improve maintainability and reduce the chance of errors in future changes.

Also applies to: 799-799, 814-817, 831-840, 885-885, 895-896, 900-903, 917-926, 971-971, 986-989, 1003-1012, 1057-1057, 1072-1075, 1090-1099, 1144-1144, 1156-1156, 1200-1200, 1213-1213, 1252-1252, 1264-1264, 1302-1302, 1313-1313


Line range hint 745-754: Improve error handling and messaging.

The function TestTransformValidationUnmarshallingError could improve its error handling by providing more specific error messages and ensuring that all potential error paths are accounted for.

+ if err != nil {
+     t.Fatalf("Expected no error, got %v", err)
+ }

Also applies to: 799-799, 814-817, 831-840, 885-885, 895-896, 900-903, 917-926, 971-971, 986-989, 1003-1012, 1057-1057, 1072-1075, 1090-1099, 1144-1144, 1156-1156, 1200-1200, 1213-1213, 1252-1252, 1264-1264, 1302-1302, 1313-1313

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ff62ff and 91cf43d.

Files selected for processing (3)
  • router/transformer/transformer.go (3 hunks)
  • router/transformer/transformer_test.go (26 hunks)
  • router/worker.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • router/transformer/transformer.go
Additional comments not posted (1)
router/worker.go (1)

802-804: Ensure appropriate logging levels in the proxyRequest method.

Verification successful

The logging statements in the proxyRequest method use the Debugn level, which is generally appropriate for debugging purposes. The information logged includes:

  • oauthV2Enabled status
  • traceParent status during various stages (transform, batch transform, process)
  • jobId and jobMetadata.JobID
  • A message indicating the sending of a request for an OAuth destination

These logging statements do not appear to expose any sensitive information and are appropriate for debugging purposes.

  • [router/worker.go:802-804]
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the logging levels in the `proxyRequest` method are appropriate and do not expose sensitive information.
# Test: Review the logging statements and their levels in the method.
rg --type go $'logger.Debugn' --context 5 router/worker.go

Length of output: 2050

router/worker.go Show resolved Hide resolved
@sanpj2292 sanpj2292 merged commit 211b421 into master Jun 10, 2024
55 checks passed
@sanpj2292 sanpj2292 deleted the fix.oauthv2-rt-resp-handling branch June 10, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants