Skip to content

Commit e455cb2

Browse files
authored
Measure http requests duration (#1379)
* Clarify log on released version * Fixes #1374 * Update docs * Compute URL in log only once
1 parent 95bb47d commit e455cb2

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

doc/what-is-new.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Next version yet unreleased
1+
# Version 3.5
2+
3+
- Display HTTP request durations in DEBUG logs
24

35
# Version 3.4
46

migration/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ When sonar-migration complete successfully they return exit code 0. En case of f
111111
## Version 0.3
112112

113113
- Robustness: Handle `connectionError` errors in project extract threads
114-
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract which may be necessary on large platforms extracts
115-
- Added export of analysis history
114+
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract (To speed up extract on very large platforms)
115+
- Added export of analysis history of each branch
116+
- Support of incremental dump of projects extracts
117+
- Display of HTTP requests duration in DEBUG logs
118+
- Fixes in documentation
116119

117120
## Version 0.2
118121

migration/what-is-new.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Version 0.3
22

33
- Robustness: Handle `connectionError` errors in project extract threads
4-
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract which may be necessary on large platforms extracts
5-
- Added export of analysis history
4+
- Added option `--skipIssues` to skip expensive issue count extraction task from the extract (To speed up extract on very large platforms)
5+
- Added export of analysis history of each branch
6+
- Support of incremental dump of projects extracts
7+
- Display of HTTP requests duration in DEBUG logs
8+
- Fixes in documentation
69

710
# Version 0.2
811

sonar/platform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import datetime
3333
import json
3434
import tempfile
35+
import logging
3536
import requests
3637
import jprops
3738
from requests.exceptions import HTTPError
@@ -221,12 +222,15 @@ def __run_request(
221222
headers["Authorization"] = f"Bearer {self.__token}"
222223
if kwargs.get("with_organization", True):
223224
params["organization"] = self.organization
224-
req_type = getattr(request, "__name__", repr(request)).upper()
225-
log.debug("%s: %s", req_type, self.__urlstring(api, params))
225+
if log.get_level() >= logging.DEBUG:
226+
req_type = getattr(request, "__name__", repr(request)).upper()
227+
url = self.__urlstring(api, params)
228+
log.debug("%s: %s", req_type, url)
226229

227230
try:
228231
retry = True
229232
while retry:
233+
start = time.perf_counter_ns()
230234
r = request(
231235
url=self.url + api,
232236
auth=self.__credentials(),
@@ -236,6 +240,7 @@ def __run_request(
236240
timeout=self.http_timeout,
237241
)
238242
(retry, new_url) = _check_for_retry(r)
243+
log.debug("%s: %s took %d ms", req_type, url, (time.perf_counter_ns() - start) // 1000000)
239244
if retry:
240245
self.url = new_url
241246
r.raise_for_status()

sonar/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def check_last_version(package_url: str) -> None:
5757
return
5858
txt_version = json.loads(r.text)["versions"][-1]
5959
package_name = package_url.split("/")[-1]
60-
log.info("Latest %s version is %s", package_name, txt_version)
60+
log.info("Latest %s released version is %s", package_name, txt_version)
6161
if tuple(".".split(txt_version)) > tuple(".".split(version.PACKAGE_VERSION)):
6262
log.warning("A more recent version of %s (%s) is available, your are advised to upgrade", package_name, txt_version)
6363

0 commit comments

Comments
 (0)