-
Notifications
You must be signed in to change notification settings - Fork 183
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
Service Time
measurement Trail_Approach_1
#679
Changes from all commits
870bc4a
bb18726
bff6a93
0484efb
b8b7c37
365d2f0
45e9c5b
98b6ac0
f848639
f9f6b71
f394b6f
e133d52
4e5e9aa
921cd55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ | |
pool_maxsize: Any = None, | ||
**kwargs: Any | ||
) -> None: | ||
self.kwargs=kwargs | ||
if not REQUESTS_AVAILABLE: | ||
raise ImproperlyConfigured( | ||
"Please install requests to use RequestsHttpConnection." | ||
|
@@ -166,6 +167,10 @@ | |
ignore: Collection[int] = (), | ||
headers: Optional[Mapping[str, str]] = None, | ||
) -> Any: | ||
|
||
calculate_service_time=False | ||
if "calculate_service_time" in self.kwargs: | ||
calculate_service_time=self.kwargs["calculate_service_time"] | ||
url = self.base_url + url | ||
headers = headers or {} | ||
if params: | ||
|
@@ -176,7 +181,6 @@ | |
body = self._gzip_compress(body) | ||
headers["content-encoding"] = "gzip" # type: ignore | ||
|
||
start = time.time() | ||
request = requests.Request(method=method, headers=headers, url=url, data=body) | ||
prepared_request = self.session.prepare_request(request) | ||
settings = self.session.merge_environment_settings( | ||
|
@@ -187,13 +191,15 @@ | |
"allow_redirects": allow_redirects, | ||
} | ||
send_kwargs.update(settings) | ||
start = time.time() | ||
try: | ||
response = self.session.send(prepared_request, **send_kwargs) | ||
duration = time.time() - start | ||
raw_data = response.content.decode("utf-8", "surrogatepass") | ||
except reraise_exceptions: | ||
raise | ||
except Exception as e: | ||
duration = time.time() - start | ||
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. I don't see this variable being used anywhere since |
||
self.log_request_fail( | ||
method, | ||
url, | ||
|
@@ -207,7 +213,11 @@ | |
if isinstance(e, requests.Timeout): | ||
raise ConnectionTimeout("TIMEOUT", str(e), e) | ||
raise ConnectionError("N/A", str(e), e) | ||
|
||
|
||
# Add the service time to the raw_data | ||
if calculate_service_time: | ||
raw_data = raw_data.rstrip()[:-1] + f', "__client": {{"Service_Time": "{duration}"}}' + '}' | ||
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. After a quick look, I think rather than attempting to modify the JSON string like this, it'd make more sense to just return the value from this function. ie. changing Adding it to the return signature of the connection class gives a clear and uniform way of returning this information across all connection implementations. Some one with more Python prowess will hopefully be able to give a better idea of what's actually idiomatic. 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. +1 for this. |
||
|
||
# raise warnings if any from the 'Warnings' header. | ||
warnings_headers = ( | ||
(response.headers["warning"],) if "warning" in response.headers else () | ||
|
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.
I think the start at line 179 is fine. Any reason otherwise?
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.
Hello @VachaShah, I am adding start timer just before sending request. I think we don't need timer to start before prepared_request right?