libmozdata 0.2.15__tar.gz → 0.2.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {libmozdata-0.2.15/libmozdata.egg-info → libmozdata-0.2.16}/PKG-INFO +1 -1
  2. libmozdata-0.2.16/VERSION +1 -0
  3. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/lando.py +5 -6
  4. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/phabricator.py +7 -27
  5. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/utils.py +44 -0
  6. {libmozdata-0.2.15 → libmozdata-0.2.16/libmozdata.egg-info}/PKG-INFO +1 -1
  7. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata.egg-info/requires.txt +1 -0
  8. {libmozdata-0.2.15 → libmozdata-0.2.16}/requirements.txt +1 -0
  9. libmozdata-0.2.15/VERSION +0 -1
  10. {libmozdata-0.2.15 → libmozdata-0.2.16}/MANIFEST.in +0 -0
  11. {libmozdata-0.2.15 → libmozdata-0.2.16}/README.md +0 -0
  12. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/BZInfo.py +0 -0
  13. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/FXRevision.py +0 -0
  14. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/FileStats.py +0 -0
  15. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/HGFileInfo.py +0 -0
  16. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/__init__.py +0 -0
  17. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/bugzilla.py +0 -0
  18. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/buildhub.py +0 -0
  19. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/clouseau.py +0 -0
  20. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/config.py +0 -0
  21. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/connection.py +0 -0
  22. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/fx_trains.py +0 -0
  23. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/handler.py +0 -0
  24. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/hgmozilla.py +0 -0
  25. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/modules.json +0 -0
  26. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/modules.py +0 -0
  27. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/patchanalysis.py +0 -0
  28. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/redash.py +0 -0
  29. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/socorro.py +0 -0
  30. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/vcs_map.py +0 -0
  31. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/versions.py +0 -0
  32. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata/wiki_parser.py +0 -0
  33. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata.egg-info/SOURCES.txt +0 -0
  34. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata.egg-info/dependency_links.txt +0 -0
  35. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata.egg-info/not-zip-safe +0 -0
  36. {libmozdata-0.2.15 → libmozdata-0.2.16}/libmozdata.egg-info/top_level.txt +0 -0
  37. {libmozdata-0.2.15 → libmozdata-0.2.16}/setup.cfg +0 -0
  38. {libmozdata-0.2.15 → libmozdata-0.2.16}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: libmozdata
3
- Version: 0.2.15
3
+ Version: 0.2.16
4
4
  Summary: Library to access and aggregate several Mozilla data sources.
5
5
  Home-page: https://github.com/mozilla/libmozdata
6
6
  Author: Mozilla Release Management
@@ -0,0 +1 @@
1
+ 0.2.16
@@ -6,9 +6,8 @@
6
6
  from collections import namedtuple
7
7
  from urllib.parse import urljoin
8
8
 
9
- import requests
10
-
11
9
  from . import config
10
+ from .utils import get_session
12
11
 
13
12
 
14
13
  class LandoWarnings(object):
@@ -28,7 +27,7 @@ class LandoWarnings(object):
28
27
  for warning in warnings:
29
28
  warning_id = warning["id"]
30
29
 
31
- response = requests.delete(
30
+ response = get_session("lando").delete(
32
31
  f"{self.api_url}{warning_id}",
33
32
  headers={
34
33
  "X-Phabricator-API-Key": self.api_key,
@@ -45,7 +44,7 @@ class LandoWarnings(object):
45
44
  """
46
45
  Adds a warning to Lando
47
46
  """
48
- response = requests.post(
47
+ response = get_session("lando").post(
49
48
  self.api_url,
50
49
  json={
51
50
  "revision_id": revision_id,
@@ -67,7 +66,7 @@ class LandoWarnings(object):
67
66
  """
68
67
  Gets a list of warnings
69
68
  """
70
- response = requests.get(
69
+ response = get_session("lando").get(
71
70
  self.api_url,
72
71
  params={
73
72
  "revision_id": revision_id,
@@ -122,7 +121,7 @@ class LandoCommitMapAPI:
122
121
  with both full hashes
123
122
  """
124
123
  url = urljoin(self.api_url, f"{method}/{repository}/{revision}")
125
- resp = requests.get(
124
+ resp = get_session("lando").get(
126
125
  url,
127
126
  headers={
128
127
  "User-Agent": self.USER_AGENT,
@@ -7,15 +7,13 @@ import collections
7
7
  import enum
8
8
  import json
9
9
  import logging
10
- import math
11
- import time
12
10
  from functools import cached_property
13
11
  from urllib.parse import urlencode, urlparse
14
12
 
15
13
  import hglib
16
- import requests
17
14
 
18
15
  from . import config
16
+ from .utils import get_session
19
17
 
20
18
  HGMO_JSON_REV_URL_TEMPLATE = "https://hg.mozilla.org/mozilla-central/json-rev/{}"
21
19
  MOZILLA_PHABRICATOR_PROD = "https://phabricator.services.mozilla.com/api/"
@@ -210,18 +208,12 @@ class PhabricatorAPI(object):
210
208
  Phabricator Rest API client
211
209
  """
212
210
 
213
- def __init__(self, api_key, url=MOZILLA_PHABRICATOR_PROD, max_retries=5):
211
+ def __init__(self, api_key, url=MOZILLA_PHABRICATOR_PROD):
214
212
  self.USER_AGENT = config.get("User-Agent", "name", required=True)
215
213
  self.api_key = api_key
216
214
  self.url = url
217
215
  assert self.url.endswith("/api/"), "Phabricator API must end with /api/"
218
216
 
219
- # Number of API calls retries on 50x before raising an error
220
- self.max_retries = max_retries
221
- assert (
222
- isinstance(self.max_retries, int) and self.max_retries > 0
223
- ), "Invalid max_retries parameter"
224
-
225
217
  @cached_property
226
218
  def user(self):
227
219
  """
@@ -669,23 +661,11 @@ class PhabricatorAPI(object):
669
661
  # Add api token to payload
670
662
  payload["__conduit__"] = {"token": self.api_key}
671
663
 
672
- # Run POST request on api, retrying on 50x errors
673
- for nb_try in range(1, self.max_retries + 1):
674
- response = requests.post(
675
- self.url + path,
676
- headers=self.get_header(),
677
- data=urlencode({"params": json.dumps(payload), "output": "json"}),
678
- )
679
- if response.status_code >= 500:
680
- # Retry after a while on 50x using exponential backoff
681
- backoff = math.exp(nb_try)
682
- logger.info(
683
- f"Phabricator failed with status code {response.status_code}, retrying in {backoff:.1f} seconds..."
684
- )
685
- time.sleep(backoff)
686
- else:
687
- # Stop retrying on the first successful try or other HTTP errors
688
- break
664
+ response = get_session("phabricator").post(
665
+ self.url + path,
666
+ headers=self.get_header(),
667
+ data=urlencode({"params": json.dumps(payload), "output": "json"}),
668
+ )
689
669
 
690
670
  # Raise immediate 40x errors or out-of-retries 50x
691
671
  response.raise_for_status()
@@ -8,17 +8,61 @@ import operator
8
8
  import os.path
9
9
  import random
10
10
  from datetime import date, datetime, timedelta, timezone
11
+ from functools import cache
11
12
  from itertools import count
12
13
 
13
14
  import dateutil.parser
14
15
  import pytz
16
+ import requests
15
17
  import six
16
18
  from dateutil.relativedelta import relativedelta
17
19
  from requests.utils import quote
20
+ from urllib3.util.retry import Retry
18
21
 
19
22
  __pacific = pytz.timezone("US/Pacific")
20
23
 
21
24
 
25
+ @cache
26
+ def get_session(name: str) -> requests.Session:
27
+ """Get a `requests` session with retries enabled on connection errors and
28
+ 50x HTTP error codes, using exponential backoff.
29
+
30
+ Sessions are cached by name, so calling this function multiple times with
31
+ the same name will return the same session.
32
+
33
+ Args:
34
+ name (str): an arbitrary name identifying the caller, used to cache
35
+ the session
36
+
37
+ Returns:
38
+ requests.Session: a session with retries enabled
39
+ """
40
+ session = requests.Session()
41
+
42
+ retry = Retry(
43
+ total=8,
44
+ backoff_factor=1,
45
+ status_forcelist=[429, 500, 502, 503, 504],
46
+ # Also retry non-idempotent methods (e.g. POST), since urllib3
47
+ # excludes them by default.
48
+ allowed_methods=None,
49
+ # Return the last response instead of raising, once retries are
50
+ # exhausted, so callers can keep inspecting status_code/text.
51
+ raise_on_status=False,
52
+ )
53
+
54
+ # Default HTTPAdapter uses 10 connections. Mount custom adapter to increase
55
+ # that limit. Connections are established as needed, so using a large value
56
+ # should not negatively impact performance.
57
+ http_adapter = requests.adapters.HTTPAdapter(
58
+ pool_connections=50, pool_maxsize=50, max_retries=retry
59
+ )
60
+ session.mount("https://", http_adapter)
61
+ session.mount("http://", http_adapter)
62
+
63
+ return session
64
+
65
+
22
66
  def get_best(stats):
23
67
  """Get the key which has the higher value
24
68
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: libmozdata
3
- Version: 0.2.15
3
+ Version: 0.2.16
4
4
  Summary: Library to access and aggregate several Mozilla data sources.
5
5
  Home-page: https://github.com/mozilla/libmozdata
6
6
  Author: Mozilla Release Management
@@ -6,4 +6,5 @@ requests-futures>=0.9.8
6
6
  requests[security]>=2.7.0
7
7
  setuptools>=83.0.0
8
8
  six>=1.17.0
9
+ urllib3>=1.26.0
9
10
  whatthepatch>=0.0.4
@@ -6,4 +6,5 @@ requests-futures>=0.9.8
6
6
  requests[security]>=2.7.0
7
7
  setuptools>=83.0.0
8
8
  six>=1.17.0
9
+ urllib3>=1.26.0
9
10
  whatthepatch>=0.0.4
libmozdata-0.2.15/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.15
File without changes
File without changes
File without changes
File without changes