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

Tdl 16328 implement request timeout #38

Merged

Conversation

namrata270998
Copy link
Contributor

Description of change
Added request timeout for SDK library functions with default timeout 300 seconds

Manual QA steps

  • The request should backoff 5 times in case it is timed out.
  • Error should be thrown in case of retries not successful after 5 trials
  • Checked the request timeout works for each stream and backoff

Risks

Rollback steps

  • revert this branch

Comment on lines 90 to 95
# if request_timeout is other than 0,"0" or "" then use request_timeout
request_timeout = config.get('request_timeout')
if request_timeout and float(request_timeout):
request_timeout = float(request_timeout)
else: # If value is 0,"0" or "" then set default to 300 seconds.
request_timeout = REQUEST_TIMEOUT

Choose a reason for hiding this comment

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

@namrata270998, Create a separate function to calculate request timeout based on provided config as we are calculating the same thing in multiple functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 219 to 222
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Choose a reason for hiding this comment

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

Suggested change
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 119 to 122
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Choose a reason for hiding this comment

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

Suggested change
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 41 to 44
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Choose a reason for hiding this comment

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

Suggested change
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)
@backoff.on_exception(backoff.expo,
(ReadTimeoutError, ConnectTimeoutError),
max_tries=5,
factor=2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

make lint
pylint tap_dynamodb --disable 'duplicate-code,missing-module-docstring,missing-class-docstring,too-few-public-methods,line-too-long,fixme,missing-function-docstring,raise-missing-from,consider-using-f-string,too-many-locals,invalid-name,too-many-arguments'

Choose a reason for hiding this comment

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

@namrata270998 Do we need this change for any specific reason?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted the change

@@ -35,7 +37,11 @@ def scan_table(table_name, projection, last_evaluated_key, config):

has_more = result.get('LastEvaluatedKey', False)


# Backoff for both ReadTimeout and ConnectTimeout error for 5 times

Choose a reason for hiding this comment

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

@namrata270998 Please add this bckoff expression above the scan_table function instead. Update the test cases accordingly.

Copy link
Contributor Author

@namrata270998 namrata270998 Jan 7, 2022

Choose a reason for hiding this comment

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

@karanpanchal-crest The function scan_table contains a yield. Hence the backoff won't work on that function
Please refer


for reference

from unittest import mock
from unittest.mock import Mock
from unittest.case import TestCase
from botocore.exceptions import ClientError, ConnectTimeoutError, ReadTimeoutError

Choose a reason for hiding this comment

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

Remove ClientError if not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Makefile Outdated
@@ -4,6 +4,6 @@ lint-tests:
pylint tests -d broad-except,chained-comparison,empty-docstring,fixme,invalid-name,line-too-long,missing-class-docstring,missing-function-docstring,missing-module-docstring,no-else-raise,no-else-return,too-few-public-methods,too-many-arguments,too-many-branches,too-many-lines,too-many-locals,ungrouped-imports,wrong-spelling-in-comment,wrong-spelling-in-docstring,duplicate-code,no-name-in-module,import-error,consider-using-f-string

lint-code:
pylint tap_dynamodb -d broad-except,chained-comparison,empty-docstring,fixme,invalid-name,line-too-long,missing-class-docstring,missing-function-docstring,missing-module-docstring,no-else-raise,no-else-return,too-few-public-methods,too-many-arguments,too-many-branches,too-many-lines,too-many-locals,ungrouped-imports,wrong-spelling-in-comment,wrong-spelling-in-docstring,raise-missing-from,consider-using-f-string
pylint tap_dynamodb -d broad-except,chained-comparison,empty-docstring,fixme,invalid-name,line-too-long,missing-class-docstring,missing-function-docstring,missing-module-docstring,no-else-raise,no-else-return,too-few-public-methods,too-many-arguments,too-many-branches,too-many-lines,too-many-locals,ungrouped-imports,wrong-spelling-in-comment,wrong-spelling-in-docstring,raise-missing-from,consider-using-f-string,duplicate-code

Choose a reason for hiding this comment

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

Remove the duplicate-code from the global level. Instead handle it where needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@kspeer825 kspeer825 left a comment

Choose a reason for hiding this comment

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

The tests look great. One improvement I see would be using variables on repeated values in those unittests to ensure typo's cannot hurt us.

@@ -19,6 +19,17 @@ jobs:
command: |
source /usr/local/share/virtualenvs/tap-dynamodb/bin/activate
make lint
- run:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this file in line with the changes required on PR #37 and #35

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kspeer825 Updated this file as requested

"""
Check whether the request backoffs properly for discover_streams for 5 times in case of ReadTimeoutError error.
"""
with self.assertRaises(ReadTimeoutError):
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this pattern

Comment on lines +153 to +155
config = {"region_name": "dummy_region", "request_timeout": "100"}
dynamodb.get_client(config)
mock_config.assert_called_with(connect_timeout=100, read_timeout=100)
Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing I can think to change is it would be better to set the default timeout value as a reusable variable for expectations. Also repeated values could be replaced with variables as well within each test. Just a suggestion though. I think they are readable and maintainable as-is, which is the important part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kspeer825 updated the code and replaced values with reusable variables.


def get_stream_client(config):
# get the request_timeout

Choose a reason for hiding this comment

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

What is the difference between get_stream_client and get_client function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KrisPersonal Amazon DynamoDB Streams provides API actions for accessing streams and processing stream records, which can be done through get_stream_client. Whereas, the get_client returns a low-level client representing Amazon DynamoDB

Copy link
Contributor

@kspeer825 kspeer825 left a comment

Choose a reason for hiding this comment

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

Just a couple config changes. Tests look good.

- store_test_results:
path: test_output/report.xml
- store_artifacts:
path: htmlcov
- run:
name: 'Tap Tester'
command: |
aws s3 cp s3://com-stitchdata-dev-deployment-assets/environments/tap-tester/sandbox tap-tester.env
Copy link
Contributor

Choose a reason for hiding this comment

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

These environment variables are not the up-to-date set. Please use tap-tester-sandbox over sandbox.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update to tap-tester-sandbox env variables set

tests
run-test --tap=tap-dynamodb tests
- slack/notify-on-failure:
only_for_branches: master
workflows:
version: 2
commit:
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 add the tap-tester-user context as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the tap-tester-user context

@namrata270998 namrata270998 merged commit 1665782 into TDL-16126-Crest-Master Feb 11, 2022
KrisPersonal pushed a commit that referenced this pull request Feb 14, 2022
* Tdl 16328 implement request timeout (#38)

* added request timeout

* added test cases for the backoff

* resolved pylint errors

* updated pylint

* fixd pylint

* updated config.yml

* resolved comments

* resolved comments

* resolved pylint errors

* resolved comments

* resolved comments

* resolved comments

* resolved slack-on-notify failure

* removed scenarios

* added tap-tester-user in config

* TDL-16291 added code comments (#36)

* added code comments

* fixed typo

* TDL-13692: Missing parent objects from projection expression causes key error and TDL-16140: Fix key error and index error while applying projection expression (#35)

* added code change for handling key error and index error

* resolve pylint error

* updated the unittests

* updated config.yml to run unittest to run on CCi

* added unittests

* updated the code to handle child dict data

* added comments with example for projection

* updated config.yml file and resolved PR review comments

* resolve slack failure error in config file

* updated version 2 to 2.1

* remoed SCENARIO from the test cases

* resolved comments

* reverted changes

* added tap-tester-venv, tap_tester_sandbox and check for verifying that we replicated records

Co-authored-by: namrata270998 <namrata.brahmbhatt@crestdatasys.com>

* Tdl 15171 implement expression attributes (#37)

* Initial commit for expression attributes

* Updated circleci and full_table.py

* resolved pylint error

* Updated circleci

* Updated unittest case path in circleci

* Updated expression attribute

* resolved pylint error

* Updated prepare exprssion logic

* Handled empty projection

* added logic for nested expressions

* added in log_based test and comments

* added code comments

* Updated comments

* Resolved review comments

* added comment

* resolved comments

* resolved pylint errors

* updated config.yml and a typo

* resolved slack-on-notify failure

* removed scenarios

* Changed the expressionattribute logic as suggested

* resolved pylint error

* fixed typo

* added test case for '.' in fields

* added testcase for prepare_projection()

* resolved comments

* added check for empty expression

* handled corner case

* resolved comments and updated unittests

* removed unused import

* resolved comments

* fixed pylint failure

* updated comment

* changed the name of catalog's expression to expression-attributes

* added tap-tester-user to the config, updated to nosetests

* updated to nosetests

* Changed expression-attributes to expression-attribute

* Changed expression-attributes to expression-attribute

* added tests for primary and replication key reserved words

* renamed the file

* added funciton comments

* fixed pylint

* changed the parameter name to attribute

* changed the attribute name in new files added

* expression-attribute -> expression-attributes in full table

* test fixes for pk and hash key as expression-attributes

* expression-attribute -> expression-attributes in one more test

* fix log sync ref and log projection test name

* Changed from attribute to attributes

Co-authored-by: namrata270998 <namrata.brahmbhatt@crestdatasys.com>
Co-authored-by: KrishnanG <kgurusamy@talend.com>
Co-authored-by: kspeer <kspeer@stitchdata.com>

Co-authored-by: Harsh <80324346+harshpatel4crest@users.noreply.github.com>
Co-authored-by: Prijen Khokhani <88327452+prijendev@users.noreply.github.com>
Co-authored-by: KrishnanG <kgurusamy@talend.com>
Co-authored-by: kspeer <kspeer@stitchdata.com>
@luandy64 luandy64 deleted the TDL-16328-implement-request-timeout branch July 18, 2023 16:04
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.

6 participants