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

Side by Side Diff: scripts/master/buildbucket/client.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: Rebase 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 unified diff | Download patch
« no previous file with comments | « no previous file | scripts/master/deferred_resource.py » ('j') | scripts/master/deferred_resource.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This file contains buildbucket service client.""" 5 """This file contains buildbucket service client."""
6 6
7 import datetime 7 import datetime
8 import json 8 import json
9 import os 9 import os
10 import urlparse 10 import urlparse
11 11
12 from master import auth 12 from master import auth
13 from master import deferred_resource 13 from master import deferred_resource
14 from master.buildbucket import common 14 from master.buildbucket import common
15 import apiclient 15 import apiclient
16 import httplib2 16
17 from infra_libs import InstrumentedHttp
17 18
18 BUILDBUCKET_HOSTNAME_PRODUCTION = 'cr-buildbucket.appspot.com' 19 BUILDBUCKET_HOSTNAME_PRODUCTION = 'cr-buildbucket.appspot.com'
19 BUILDBUCKET_HOSTNAME_TESTING = 'cr-buildbucket-test.appspot.com' 20 BUILDBUCKET_HOSTNAME_TESTING = 'cr-buildbucket-test.appspot.com'
20 21
21 THIS_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) 22 THIS_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
22 DISCOVERY_DOC_PATH = os.path.join(THIS_DIR, 'discovery_doc.json') 23 DISCOVERY_DOC_PATH = os.path.join(THIS_DIR, 'discovery_doc.json')
23 24
24 25
25 def get_default_buildbucket_hostname(master): 26 def get_default_buildbucket_hostname(master):
26 return ( 27 return (
(...skipping 14 matching lines...) Expand all
41 ttl=datetime.timedelta(minutes=5), 42 ttl=datetime.timedelta(minutes=5),
42 ) 43 )
43 44
44 with open(DISCOVERY_DOC_PATH) as f: 45 with open(DISCOVERY_DOC_PATH) as f:
45 discovery_doc = json.load(f) 46 discovery_doc = json.load(f)
46 47
47 # This block of code is adapted from 48 # This block of code is adapted from
48 # https://chromium.googlesource.com/chromium/tools/build/+/08b404f/third_party /google_api_python_client/googleapiclient/discovery.py#146 49 # https://chromium.googlesource.com/chromium/tools/build/+/08b404f/third_party /google_api_python_client/googleapiclient/discovery.py#146
49 # https://chromium.googlesource.com/chromium/tools/build/+/08b404f/third_party /google_api_python_client/googleapiclient/discovery.py#218 50 # https://chromium.googlesource.com/chromium/tools/build/+/08b404f/third_party /google_api_python_client/googleapiclient/discovery.py#218
50 resource = apiclient.discovery.Resource( 51 resource = apiclient.discovery.Resource(
51 http=httplib2.Http(), 52 http=InstrumentedHttp('buildbucket'),
52 # Note that this does not include _ah/ in URL path, which means 53 # Note that this does not include _ah/ in URL path, which means
53 # we bypass Cloud Endpoints proxy server. See also: 54 # we bypass Cloud Endpoints proxy server. See also:
54 # https://bugs.chromium.org/p/chromium/issues/detail?id=626650 55 # https://bugs.chromium.org/p/chromium/issues/detail?id=626650
55 # https://codereview.chromium.org/2117833003/ 56 # https://codereview.chromium.org/2117833003/
56 # https://codereview.chromium.org/2116783003/ 57 # https://codereview.chromium.org/2116783003/
57 baseUrl='https://%s/api/buildbucket/v1/' % hostname, 58 baseUrl='https://%s/api/buildbucket/v1/' % hostname,
58 model=apiclient.model.JsonModel(False), 59 model=apiclient.model.JsonModel(False),
59 requestBuilder=apiclient.http.HttpRequest, 60 requestBuilder=apiclient.http.HttpRequest,
60 developerKey=None, 61 developerKey=None,
61 resourceDesc=discovery_doc, 62 resourceDesc=discovery_doc,
62 rootDesc=discovery_doc, 63 rootDesc=discovery_doc,
63 schema=apiclient.schema.Schemas(discovery_doc)) 64 schema=apiclient.schema.Schemas(discovery_doc))
64 65
65 return deferred_resource.DeferredResource( 66 return deferred_resource.DeferredResource(
66 resource, 67 resource,
67 credentials=cred_factory, 68 credentials=cred_factory,
68 max_concurrent_requests=10, 69 max_concurrent_requests=10,
69 verbose=verbose or False, 70 verbose=verbose or False,
70 log_prefix=common.LOG_PREFIX, 71 log_prefix=common.LOG_PREFIX,
71 timeout=60, 72 timeout=60,
72 ) 73 )
OLDNEW
« no previous file with comments | « no previous file | scripts/master/deferred_resource.py » ('j') | scripts/master/deferred_resource.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698