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: (CDK) (AsyncRetriever) - Add the request and response to each async operations #356

Merged

Conversation

bazarnov
Copy link
Contributor

@bazarnov bazarnov commented Feb 20, 2025

What

Resolves:

How

  • add format_http_message to the following methods while handling the response:
    • _get_validated_polling_response() - to track the ASYNC_POLL message types
    • _start_job_and_validate_response() - to track the ASYNC_CREATE message types
    • abort() - to track the ASYNC_ABORT message types
    • delete() - to track the ASYNC_DELETE message types

User Impact

No impact is expected this is not a breaking change

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced logging now provides richer contextual details for HTTP operations during job polling, initiation, cancellation, and deletion, improving system observability and aiding troubleshooting.
    • Introduced a new field for logging cursor slice information in the AsyncRetriever class, enhancing logging capabilities.
  • Documentation

    • Added comments indicating future enhancements to support additional file types in the extractor.

@github-actions github-actions bot added bug Something isn't working security labels Feb 20, 2025
@bazarnov bazarnov self-assigned this Feb 20, 2025
@bazarnov bazarnov marked this pull request as ready for review February 20, 2025 14:42
@bazarnov
Copy link
Contributor Author

bazarnov commented Feb 20, 2025

This linters check will FAIL until this PR is merged and the main branch is updated. Because of the model dependencies.

Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

📝 Walkthrough

Walkthrough

The changes introduce enhancements across three components. In the response extractor, a comment is added in the _read_with_chunks method to indicate future support for processing JSON files using pd.read_json(). The HTTP job repository now includes log_formatter parameters in several methods to improve logging of HTTP messages. Additionally, the async retriever has a new slice_logger field and a private method for retrieving cursor slice information, with modifications to enhance logging in the read_records method. No alterations were made to core functionality or control flow.

Changes

File(s) Summary
airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py Added a comment in _read_with_chunks indicating future support for JSON files using pd.read_json().
airbyte_cdk/sources/declarative/requesters/http_job_repository.py Added log_formatter lambda parameters in methods (_get_validated_polling_response, _start_job_and_validate_response, abort, delete) to enhance logging; added an import for format_http_message.
airbyte_cdk/sources/declarative/retrievers/async_retriever.py Added slice_logger field and _get_cursor_slice method; modified stream_slices to use yield from; added logging in read_records.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Repo as AsyncHttpJobRepository
    participant HTTP as HTTP Endpoint
    participant Logger as Logger

    Client ->> Repo: Call _start_job_and_validate_response()
    Repo ->> HTTP: send_request(log_formatter)
    HTTP -->> Repo: Return HTTP Response
    Repo ->> Logger: format_http_message(http message)
    Repo -->> Client: Return Response
Loading

Suggested labels

enhancement

Suggested reviewers

  • maxi297
  • natikgadzhi
  • brianjlai

Would you like to see any further adjustments or additional diagrams for clarity, wdyt?


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c1711e and 1886f5e.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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

🧹 Nitpick comments (1)
airbyte_cdk/sources/declarative/requesters/http_job_repository.py (1)

254-254: Minor typo in variable name.

There's a typo in delete_job_reponse (missing 's'). Wdyt about fixing it?

-        delete_job_reponse = self.delete_requester.send_request(
+        delete_job_response = self.delete_requester.send_request(
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 978be1b and b3d46aa.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py (1 hunks)
  • airbyte_cdk/sources/declarative/requesters/http_job_repository.py (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/requesters/http_job_repository.py

[error] 76-76: Unexpected keyword argument 'type' for 'format_http_message' [call-arg]


[error] 131-131: Unexpected keyword argument 'type' for 'format_http_message' [call-arg]


[error] 240-240: Unexpected keyword argument 'type' for 'format_http_message' [call-arg]


[error] 256-256: Unexpected keyword argument 'type' for 'format_http_message' [call-arg]

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (2)
airbyte_cdk/sources/declarative/requesters/http_job_repository.py (2)

26-26: LGTM! Good addition of http logging.

The import of format_http_message aligns well with the PR objectives to add request and response logging to async operations.


74-84: Great job on consistent logging across async operations!

The logging additions provide excellent context for each async operation with descriptive titles and messages. This will help with debugging and monitoring of async jobs.

Also applies to: 129-139, 238-248, 254-264

🧰 Tools
🪛 GitHub Actions: Linters

[error] 76-76: Unexpected keyword argument 'type' for 'format_http_message' [call-arg]

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

🧹 Nitpick comments (1)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (1)

107-110: Consider enhancing logging for request/response?

The slice logging is a good addition, but to align with the PR objectives of adding request/response to async operations, would it make sense to extend the logging to include HTTP request/response details? We could potentially:

  1. Add request/response fields to the slice log message
  2. Create separate log messages for request/response events

What approach would you prefer? 🎯

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3d46aa and 7fdd067.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (3)

4-4: Clean addition of logging capability!

The slice logger field is well-structured with appropriate default factory and typing. Nice job! 🎯

Also applies to: 18-18, 31-34


81-97: Verify alignment with PR objectives?

The method is well-implemented and documented, but I notice it's focused on cursor slice info rather than the PR's objective of adding request/response to async operations. Would it make sense to include request/response info in the cursor slice, or should this be handled separately? wdyt? 🤔


99-100: Nice optimization with yield from!

The change to yield from improves memory efficiency by avoiding the creation of intermediate collections. Well done! 🚀

Copy link
Contributor

@lazebnyi lazebnyi 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: 0

🧹 Nitpick comments (1)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (1)

31-34: Consider using a regular instance attribute instead of field?

The slice_logger is initialized with a default factory but marked as init=False. Since it's a simple initialization with no dependencies, we could potentially simplify this to a regular instance attribute. wdyt?

-    slice_logger: AlwaysLogSliceLogger = field(
-        init=False,
-        default_factory=lambda: AlwaysLogSliceLogger(),
-    )
+    slice_logger: AlwaysLogSliceLogger = AlwaysLogSliceLogger()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fdd067 and 0c1711e.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Analyze (python)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (4)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (4)

81-97: Well-documented helper method, LGTM! 👍

The _get_cursor_slice method is nicely documented and follows a clear single responsibility principle. The implementation is concise and handles edge cases appropriately.


99-100: Good use of yield from! 🎯

Nice improvement using yield from instead of return for the generator method.


1-121: Missing request/response logging mentioned in PR objectives

The PR objectives mention adding request and response to async operations, but I don't see those changes in this file. Should we add similar logging for HTTP requests/responses in the async operations (_get_validated_polling_response(), _start_job_and_validate_response(), etc.)?

#!/bin/bash
# Search for async operation methods that might need request/response logging
ast-grep --pattern $'class AsyncRetriever {
  $$$
  _get_validated_polling_response($_) {
    $$$
  }
  $$$
}'

Likely an incorrect or invalid review comment.


107-110:

✅ Verification successful

Verify impact on existing logs

The slice logging addition looks good, but let's ensure it doesn't affect existing log consumers. Would you mind confirming if this new log message could interfere with any existing log parsing or monitoring systems?


🏁 Script executed:

#!/bin/bash
# Search for existing log message handling or parsing
rg -g '!*.pyc' -g '!*test*' 'slice.*log' .

Length of output: 6530


Verified: Existing slice log messages are consistent

I searched the repo for "slice.*log" and confirmed that the usage of create_slice_log_message in the async retriever mirrors the pattern found in other parts of the codebase (e.g., in concurrent and streams modules). It appears that the new log message maintains compatibility with existing log consumers and should not interfere with current log parsing or monitoring systems. wdyt?

Copy link
Contributor

@aldogonzalez8 aldogonzalez8 left a comment

Choose a reason for hiding this comment

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

APPROVED

@bazarnov bazarnov merged commit 4dbb6fe into main Feb 24, 2025
23 checks passed
@bazarnov bazarnov deleted the baz/cdk/add-async-retriever-operation-auxiliary-requests branch February 24, 2025 15:31
rpopov added a commit to rpopov/airbyte-python-cdk that referenced this pull request Mar 5, 2025
* main:
  fix: update cryptography package to latest version to address CVE (airbytehq#377)
  fix: (CDK) (HttpRequester) - Make the `HttpRequester.path` optional (airbytehq#370)
  feat: improved custom components handling (airbytehq#350)
  feat: add microseconds timestamp format (airbytehq#373)
  fix: Replace Unidecode with anyascii for permissive license (airbytehq#367)
  feat: add IncrementingCountCursor (airbytehq#346)
  feat: (low-code cdk)  datetime format with milliseconds (airbytehq#369)
  fix: (CDK) (AsyncRetriever) - Improve UX on variable naming and interpolation (airbytehq#368)
  fix: (CDK) (AsyncRetriever) - Add the `request` and `response` to each `async` operations (airbytehq#356)
  fix: (CDK) (ConnectorBuilder) - Add `auxiliary requests` to slice; support `TestRead` for AsyncRetriever (part 1/2) (airbytehq#355)
  feat(concurrent perpartition cursor): Add parent state updates (airbytehq#343)
  fix: update csv parser for builder compatibility (airbytehq#364)
  feat(low-code cdk): add interpolation for limit field in Rate (airbytehq#353)
  feat(low-code cdk): add AbstractStreamFacade processing as concurrent streams in declarative source (airbytehq#347)
  fix: (CDK) (CsvParser) - Fix the `\\` escaping when passing the `delimiter` from Builder's UI (airbytehq#358)
  feat: expose `str_to_datetime` jinja macro (airbytehq#351)
  fix: update CDK migration for 6.34.0 (airbytehq#348)
  feat: Removes `stream_state` interpolation from CDK (airbytehq#320)
  fix(declarative): Pass `extra_fields` in `global_substream_cursor` (airbytehq#195)
  feat(concurrent perpartition cursor): Refactor ConcurrentPerPartitionCursor (airbytehq#331)
  feat(HttpMocker): adding support for PUT requests and bytes responses (airbytehq#342)
  chore: use certified source for manifest-only test (airbytehq#338)
  feat: check for request_option mapping conflicts in individual components (airbytehq#328)
  feat(file-based): sync file acl permissions and identities (airbytehq#260)
  fix: (CDK) (Connector Builder) - refactor the `MessageGrouper` > `TestRead` (airbytehq#332)
  fix(low code): Fix missing cursor for ClientSideIncrementalRecordFilterDecorator (airbytehq#334)
  feat(low-code): Add API Budget (airbytehq#314)
  chore(decoder): clean decoders and make csvdecoder available (airbytehq#326)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants