Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: scripts/master/deferred_resource.py

Issue 2254643002: Instrument HTTP client requests to buildbucket (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@reland-tsmon-metrics
Patch Set: Fix test include paths Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scripts/master/buildbucket/client.py ('k') | tests/test_env.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/master/deferred_resource.py
diff --git a/scripts/master/deferred_resource.py b/scripts/master/deferred_resource.py
index 0f613f1ec2c8c0d627bc4f68a122bdfe60c8be9a..bfff7ac875c1dc80c796d87d41f6c8dfb3b02047 100644
--- a/scripts/master/deferred_resource.py
+++ b/scripts/master/deferred_resource.py
@@ -17,9 +17,10 @@ from twisted.python import log as twistedLog
from twisted.python.threadpool import ThreadPool
import apiclient
import apiclient.discovery
-import httplib2
import oauth2client
+from infra_libs import InstrumentedHttp
+
DEFAULT_RETRY_ATTEMPT_COUNT = 5
DEFAULT_RETRY_WAIT_SECONDS = 1
@@ -121,7 +122,7 @@ class DeferredResource(object):
def __init__(
self, resource, credentials=None, max_concurrent_requests=1,
retry_wait_seconds=None, retry_attempt_count=None, verbose=False,
- log_prefix='', timeout=None, _pool=None):
+ log_prefix='', timeout=None, _pool=None, http_client_name=None):
"""Creates a DeferredResource.
Args:
@@ -141,6 +142,8 @@ class DeferredResource(object):
then Python's default timeout for sockets will be used. See
for example the docs of socket.setdefaulttimeout():
http://docs.python.org/library/socket.html#socket.setdefaulttimeout
+ http_client_name (str): an identifier for the HTTP requests made by this
+ resource. Included with monitoring metrics.
"""
max_concurrent_requests = max_concurrent_requests or 1
assert resource, 'resource not specified'
@@ -150,6 +153,8 @@ class DeferredResource(object):
if retry_attempt_count is None:
retry_attempt_count = DEFAULT_RETRY_ATTEMPT_COUNT
assert isinstance(retry_attempt_count, int)
+ if http_client_name is None:
+ http_client_name = 'deferred_resource'
self._pool = _pool or self._create_thread_pool(max_concurrent_requests)
self._resource = resource
@@ -162,6 +167,7 @@ class DeferredResource(object):
self._th_local = threading.local()
self.started = False
self.timeout = timeout
+ self.http_client_name = http_client_name
@classmethod
def _create_thread_pool(cls, max_concurrent_requests):
@@ -335,7 +341,8 @@ class DeferredResource(object):
if create_creds:
self._th_local.credentials = None
self._th_local.credentials_expiry = None
- self._th_local.http = httplib2.Http(timeout=self.timeout)
+ self._th_local.http = InstrumentedHttp(
+ self.http_client_name, timeout=self.timeout)
if self.credentials is not None:
creds = self.credentials
ttl = None
« no previous file with comments | « scripts/master/buildbucket/client.py ('k') | tests/test_env.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698