-
Notifications
You must be signed in to change notification settings - Fork 47
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-14354 log request_id #135
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3b55e10
logged request_id for the sdk calls
namrata270998 b4b6398
unittests for debug log
namrata270998 407dfba
changed the logic of new_list and updated unittests
namrata270998 aacce18
added code comments
namrata270998 5c8bde3
rsolved pylint error
namrata270998 d4e8a46
resolved cci failures
namrata270998 df25290
resolved pylint errors
namrata270998 1d21478
rsolved pylint
namrata270998 4b3b254
changed the function overwritten for logging request id
namrata270998 c7cd2e0
resolved PR review comments
namrata270998 f9036d8
skipped schema missing fields to pass the cci
namrata270998 649d85c
fixed cci issue
namrata270998 ce127a0
added schema missing fields
namrata270998 3d88a06
added receipt_url in fickle fields
namrata270998 ab04713
resolved PR comments
namrata270998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ | |||||
import stripe | ||||||
import stripe.error | ||||||
from stripe.stripe_object import StripeObject | ||||||
from stripe.api_requestor import APIRequestor | ||||||
from stripe.util import convert_to_stripe_object | ||||||
import singer | ||||||
from singer import utils, Transformer, metrics | ||||||
|
@@ -392,6 +393,18 @@ def reduce_foreign_keys(rec, stream_name): | |||||
rec['lines'][k] = [li.to_dict_recursive() for li in val] | ||||||
return rec | ||||||
|
||||||
def new_request(self, method, url, params=None, headers=None): | ||||||
'''The new request function to overwrite the request() in the APIRequestor class.''' | ||||||
rbody, rcode, rheaders, my_api_key = self.request_raw( | ||||||
method.lower(), url, params, headers, is_streaming=False | ||||||
) | ||||||
resp = self.interpret_response(rbody, rcode, rheaders) | ||||||
LOGGER.debug(f'request id : {resp.request_id}') | ||||||
return resp, my_api_key | ||||||
|
||||||
# To log the request_id, we replaced the request() function of the APIRequestor | ||||||
# class, captured the response and logged the request_id | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the comment |
||||||
APIRequestor.request = new_request | ||||||
|
||||||
def paginate(sdk_obj, filter_key, start_date, end_date, stream_name, request_args=None, limit=100): | ||||||
yield from sdk_obj.list( | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unittest | ||
from unittest import mock | ||
from tap_stripe import new_request | ||
|
||
class MockRequest(): | ||
'''Mock Request object''' | ||
def __init__(self, response): | ||
self.last_response = response | ||
|
||
def request_raw(self, method, url, params=None, supplied_headers=None, is_streaming=False): | ||
return {}, {}, {}, {} | ||
|
||
def interpret_response(self, rbody, rcode, rheaders): | ||
return get_request_id() | ||
|
||
class MockResponse(): | ||
'''Mock response object which contains the request_id''' | ||
def __init__(self, request_id): | ||
self.request_id = request_id | ||
|
||
|
||
def get_request_id(): | ||
'''Return the MockRequest object which contains request_id''' | ||
response = MockResponse('dummy_request_id') | ||
return response | ||
|
||
class TestDebugLogger(unittest.TestCase): | ||
@mock.patch('tap_stripe.LOGGER.debug') | ||
def test_debug_logger(self, mock_debug): | ||
'''Test that the debug is called with proper request id.''' | ||
mock_request = MockRequest('url') | ||
new_request(mock_request, 'GET', 'dummy_url') | ||
mock_debug.assert_called_with('request id : dummy_request_id') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U[dated the comment