Skip to content

TDL-16353: Add request timeout#36

Merged
KrisPersonal merged 12 commits intomasterfrom
add-request-timeout
Jan 11, 2022
Merged

TDL-16353: Add request timeout#36
KrisPersonal merged 12 commits intomasterfrom
add-request-timeout

Conversation

@hpatel41
Copy link
Contributor

Description of change

TDL-16353: Add request timeout

  • Use default timeout of 300 seconds if the user does not enter the preferred timeout value

Manual QA steps

Risks

Rollback steps

  • revert this branch

@hpatel41 hpatel41 marked this pull request as ready for review November 16, 2021 11:10
timeout_value = float(timeout)
# update the request timeout for the requests
self.request_timeout = timeout_value
else:

Choose a reason for hiding this comment

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

Can you please add the comment related to 0, "0", "" values for else 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.

Added

Comment on lines +34 to +37
timeout_value = float(timeout)
# set the request timeout for the requests
# if value is 0,"0", "" or None then it will set default to default to 300.0 seconds if not passed in config.
self.request_timeout = timeout_value

Choose a reason for hiding this comment

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

Suggested change
timeout_value = float(timeout)
# set the request timeout for the requests
# if value is 0,"0", "" or None then it will set default to default to 300.0 seconds if not passed in config.
self.request_timeout = timeout_value
self.request_timeout = float(timeout)

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

sorted_files = sorted(matching_files, key = lambda x: (x['last_modified']).timestamp())
return sorted_files

@backoff.on_exception(backoff.expo,
Copy link

@namrata270998 namrata270998 Nov 26, 2021

Choose a reason for hiding this comment

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

@harshpatel4crest Add comments for this backoff

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 comment.


return records_streamed

@backoff.on_exception(backoff.expo,

Choose a reason for hiding this comment

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

@harshpatel4crest add comments for this backoff

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 comment.

self.transport.connect(username= self.username, password = self.password, hostkey = None, pkey = None)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
self.__active_connection = True
# get 'socket'

Choose a reason for hiding this comment

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

Please elaborate more, why do we need to get a socket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To set the timeout we need socket.

Test case to verify the timeout value is set as expected
"""

def test_timeout_value_not_passed_in_config(self):

Choose a reason for hiding this comment

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

Please add comments for each function, what it is testing.

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 comment for each test case function.


def close(self):
if self.__active_connection:
# get socket

Choose a reason for hiding this comment

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

Please elaborate more, why do we need to get a socket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To set the timeout we need socket.

@hpatel41 hpatel41 requested a review from dbshah1212 December 23, 2021 12:44
# get 'socket' to set the timeout
socket = self.sftp.get_channel()
# set request timeout to 'None' ie. default value
socket.settimeout(None)

Choose a reason for hiding this comment

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

@harshpatel4crest Why do you have to set the timeout manually? Why not using the same request_timeout parameter?

Copy link
Contributor Author

@hpatel41 hpatel41 Jan 4, 2022

Choose a reason for hiding this comment

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

Here, before closing the connection, the timeout is set to None (Default value).

Choose a reason for hiding this comment

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

Please use the default value/configured value provided in the tap. Request timeout should never have None value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the code as during the connection we are setting the desired timeout value.


class SFTPConnection():
def __init__(self, host, username, password=None, private_key_file=None, port=None):
def __init__(self, host, username, password=None, private_key_file=None, port=None, timeout=None):

Choose a reason for hiding this comment

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

@harshpatel4crest Why timeout = None? You can set it to REQUEST_TIMEOUT instead to denote that default value will be taken if not provided

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 REQUEST_TIMEOUT instead of None.

private_key_file=config.get('private_key_file'),
port=config.get('port'))
port=config.get('port'),
timeout=config.get('request_timeout'))

Choose a reason for hiding this comment

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

@harshpatel4crest Why have you used request_timeout from config directly? Can't we useself.request_timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we are initializing the connection. Hence we are passing the timeout value from the config.

Copy link

@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 image needs updated.

source /usr/local/share/virtualenvs/tap-sftp/bin/activate
pip install nose
nosetests tests/unittests/
pip install nose coverage

Choose a reason for hiding this comment

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

Please update the tap-tester image to the latest stitch-tap-tester

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 When we are updating image we are getting ModuleNotFoundError: No module named 'paramiko' error. Please find the error reference

Choose a reason for hiding this comment

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

That dependency will need to be imported directly in the circleci config. The preferred method for this is to use a test group under extras_require in the setup.py. Then this will have to be installed via pip under the integration test step in the workflow definition. This was one of the breaking changes to tap-tester that resulted in the image actually - removing tap dependencies from the test framework repo.

Comment on lines +40 to +47
run-test --tap=tap-sftp \
--target=target-stitch \
--orchestrator=stitch-orchestrator \
--email=harrison+sandboxtest@stitchdata.com \
--password=$SANDBOX_PASSWORD \
--token=$DEV_TOKEN \
--client-id=50 \
tests

Choose a reason for hiding this comment

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

something like pip install ../.[test] prior to the run-test command where the test group contains the same paramiko 2.6 dependency that is required by the tap.

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 test group to install paramiko.

@hpatel41 hpatel41 requested a review from kspeer825 January 7, 2022 14:32
@KrisPersonal KrisPersonal merged commit 935d7f9 into master Jan 11, 2022
@KrisPersonal KrisPersonal deleted the add-request-timeout branch January 11, 2022 16:59
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.

8 participants