Skip to content

CDK improve error handling responses #11629

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

Merged
merged 6 commits into from
Mar 31, 2022

Conversation

marcosmarxm
Copy link
Member

@marcosmarxm marcosmarxm commented Mar 31, 2022

What

Closes #6790
Some cases Airbyte only raises the error class and doesn't print any meaningful logs.
One unit test was edited to match the output message this modification apply.
The change take places most here:

if self.should_retry(response):
custom_backoff_time = self.backoff_time(response)
if custom_backoff_time:
raise UserDefinedBackoffException(backoff=custom_backoff_time, request=request, response=response)
else:
raise DefaultBackoffException(request=request, response=response)

How

HTTPError is based on IOError, for those error exceptions you need to send the message you want to print with the error log.

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@github-actions github-actions bot added the CDK Connector Development Kit label Mar 31, 2022
@marcosmarxm marcosmarxm changed the title CDK improve error handling backoff CDK improve error handling responses Mar 31, 2022
Copy link
Contributor

@alafanechere alafanechere left a comment

Choose a reason for hiding this comment

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

Great initiative! I wonder if it could introduce a security concern: if response text contains sensitive information it will be displayed in the log.

@@ -167,7 +167,7 @@ def max_retries(self):
req.status_code = HTTPStatus.TOO_MANY_REQUESTS
send_mock = mocker.patch.object(requests.Session, "send", return_value=req)

with pytest.raises(UserDefinedBackoffException):
with pytest.raises(UserDefinedBackoffException, match="\nRequest URL: https://test_base_url.com/\nResponse Code: 429"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you unit test the change you also made to BaseBackoffException?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added one test for DefaultBackoffExeption but will spend some time to add a new test BaseBackoffException

@marcosmarxm
Copy link
Member Author

marcosmarxm commented Mar 31, 2022

if response text contains sensitive information it will be displayed in the log.

I don't think API's will return any secrets in responses but we can probably think in a better solution in the future.

@codecov
Copy link

codecov bot commented Mar 31, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@3c8aadc). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master   #11629   +/-   ##
=========================================
  Coverage          ?   88.39%           
=========================================
  Files             ?       37           
  Lines             ?     1637           
  Branches          ?        0           
=========================================
  Hits              ?     1447           
  Misses            ?      190           
  Partials          ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c8aadc...f4de60b. Read the comment docs.

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

make sure to follow the README for how to bump the version and publish a new CDK version, update the changelog etc..

pass
def __init__(self, request: requests.PreparedRequest, response: requests.Response):
error_message = f"Request URL: {request.url}, Response Code: {response.status_code}, Response Text: {response.text}"
super().__init__(error_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you pass request=request, response=response as named parameters here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sherifnada
Copy link
Contributor

: if response text contains sensitive information it will be displayed in the log.

@alafanechere I had this thought too but because we're only displaying responses from exception HTTP responses (400, 500 etc..) I'm guessing this kind of response doesn't have any sensitive information.

@alafanechere
Copy link
Contributor

: if response text contains sensitive information it will be displayed in the log.

@alafanechere I had this thought too but because we're only displaying responses from exception HTTP responses (400, 500 etc..) I'm guessing this kind of response doesn't have any sensitive information.

Yes I agree its an unlikely situation that would mean a poor source API design.

@marcosmarxm
Copy link
Member Author

marcosmarxm commented Mar 31, 2022

/publish-cdk dry-run=true

🕑 https://github.com/airbytehq/airbyte/actions/runs/2073033022
https://github.com/airbytehq/airbyte/actions/runs/2073033022

@marcosmarxm
Copy link
Member Author

marcosmarxm commented Mar 31, 2022

/publish-cdk dry-run=false

🕑 https://github.com/airbytehq/airbyte/actions/runs/2073188464
https://github.com/airbytehq/airbyte/actions/runs/2073188464

@marcosmarxm marcosmarxm merged commit 78cafc5 into master Mar 31, 2022
@marcosmarxm marcosmarxm deleted the marcos/cdk-improve-error-handling-backoff branch March 31, 2022 19:41
@@ -167,7 +167,7 @@ def max_retries(self):
req.status_code = HTTPStatus.TOO_MANY_REQUESTS
send_mock = mocker.patch.object(requests.Session, "send", return_value=req)

with pytest.raises(UserDefinedBackoffException):
with pytest.raises(UserDefinedBackoffException, match="Request URL: https://test_base_url.com/, Response Code: 429"):
Copy link
Contributor

@alafanechere alafanechere Mar 31, 2022

Choose a reason for hiding this comment

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

You can

Suggested change
with pytest.raises(UserDefinedBackoffException, match="Request URL: https://test_base_url.com/, Response Code: 429"):
with pytest.raises(UserDefinedBackoffException, match="Request URL: https://test_base_url.com/, Response Code: 429, Response Text: ?"):

If you tested both child classes I don't think you need to test the Base.

@@ -294,6 +294,7 @@ def _send(self, request: requests.PreparedRequest, request_kwargs: Mapping[str,
raise DefaultBackoffException(request=request, response=response)
elif self.raise_on_http_errors:
# Raise any HTTP exceptions that happened in case there were unexpected ones
self.logger.error(f"Request raised an error with response: {response.text}")
Copy link

Choose a reason for hiding this comment

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

@marcosmarxm, this log really confused me. At this point in code, there's no error to be thrown. The happy path for a response is to not require a retry whatsoever. Now I'm seeing this log in my logs that imply an error but really my stream is working just fine

Copy link
Contributor

Choose a reason for hiding this comment

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

@ethanve I tried to fix this in #11650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error logging in CDK
5 participants