vcs-client: report more data about the call for better request tracking
This commit is contained in:
parent
7a2bd60f22
commit
455020bf4a
3 changed files with 23 additions and 5 deletions
|
|
@ -124,7 +124,7 @@ class CurlSession(object):
|
|||
# TODO: johbo: I did test with 7.19 of libcurl. This version has
|
||||
# trouble with 100 - continue being set in the expect header. This
|
||||
# can lead to massive performance drops, switching it off here.
|
||||
curl.setopt(curl.HTTPHEADER, ["Expect:"])
|
||||
|
||||
curl.setopt(curl.TCP_NODELAY, True)
|
||||
curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP)
|
||||
curl.setopt(curl.USERAGENT, 'RhodeCode HTTP {}'.format(rhodecode.__version__))
|
||||
|
|
@ -132,7 +132,10 @@ class CurlSession(object):
|
|||
curl.setopt(curl.SSL_VERIFYHOST, 0)
|
||||
self._curl = curl
|
||||
|
||||
def post(self, url, data, allow_redirects=False):
|
||||
def post(self, url, data, allow_redirects=False, headers=None):
|
||||
headers = headers or {}
|
||||
# format is ['header_name1: header_value1', 'header_name2: header_value2'])
|
||||
headers_list = ["Expect:"] + ['{}: {}'.format(k, v) for k, v in headers.items()]
|
||||
response_buffer = StringIO()
|
||||
|
||||
curl = self._curl
|
||||
|
|
@ -141,6 +144,7 @@ class CurlSession(object):
|
|||
curl.setopt(curl.POSTFIELDS, data)
|
||||
curl.setopt(curl.FOLLOWLOCATION, allow_redirects)
|
||||
curl.setopt(curl.WRITEDATA, response_buffer)
|
||||
curl.setopt(curl.HTTPHEADER, headers_list)
|
||||
curl.perform()
|
||||
|
||||
status_code = curl.getinfo(pycurl.HTTP_CODE)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ EXCEPTIONS_MAP = {
|
|||
|
||||
def _remote_call(url, payload, exceptions_map, session):
|
||||
try:
|
||||
response = session.post(url, data=msgpack.packb(payload))
|
||||
headers = {
|
||||
'X-RC-Method': payload.get('method'),
|
||||
'X-RC-Repo-Name': payload.get('_repo_name')
|
||||
}
|
||||
response = session.post(url, data=msgpack.packb(payload), headers=headers)
|
||||
except pycurl.error as e:
|
||||
msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc())
|
||||
raise exceptions.HttpVCSCommunicationError(msg)
|
||||
|
|
@ -188,13 +192,16 @@ class RemoteRepo(object):
|
|||
self._session = remote_maker._session_factory()
|
||||
|
||||
cache_repo_id = self._repo_id_sanitizer(repo_id)
|
||||
_repo_name = self._get_repo_name(config, path)
|
||||
self._cache_region, self._cache_namespace = \
|
||||
remote_maker.init_cache_region(cache_repo_id)
|
||||
|
||||
with_wire = with_wire or {}
|
||||
|
||||
repo_state_uid = with_wire.get('repo_state_uid') or 'state'
|
||||
|
||||
self._wire = {
|
||||
"_repo_name": _repo_name,
|
||||
"path": path, # repo path
|
||||
"repo_id": repo_id,
|
||||
"cache_repo_id": cache_repo_id,
|
||||
|
|
@ -213,6 +220,10 @@ class RemoteRepo(object):
|
|||
|
||||
self.cert_dir = get_cert_path(rhodecode.CONFIG.get('__file__'))
|
||||
|
||||
def _get_repo_name(self, config, path):
|
||||
repo_store = config.get('paths', '/')
|
||||
return path.split(repo_store)[-1].lstrip('/')
|
||||
|
||||
def _repo_id_sanitizer(self, repo_id):
|
||||
pathless = repo_id.replace('/', '__').replace('-', '_')
|
||||
return ''.join(char if ord(char) < 128 else '_{}_'.format(ord(char)) for char in pathless)
|
||||
|
|
@ -238,6 +249,7 @@ class RemoteRepo(object):
|
|||
payload = {
|
||||
'id': str(uuid.uuid4()),
|
||||
'method': name,
|
||||
"_repo_name": wire['_repo_name'],
|
||||
'params': {'wire': wire, 'args': args, 'kwargs': kwargs}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,8 @@ def test_repo_maker_uses_session_for_classmethods(stub_session_factory):
|
|||
'server_and_port', 'endpoint', 'test_dummy_scm', stub_session_factory)
|
||||
repo_maker.example_call()
|
||||
stub_session_factory().post.assert_called_with(
|
||||
'http://server_and_port/endpoint', data=mock.ANY)
|
||||
'http://server_and_port/endpoint', data=mock.ANY,
|
||||
headers={'X-RC-Method': 'example_call', 'X-RC-Repo-Name': None})
|
||||
|
||||
|
||||
def test_repo_maker_uses_session_for_instance_methods(
|
||||
|
|
@ -110,7 +111,8 @@ def test_repo_maker_uses_session_for_instance_methods(
|
|||
repo = repo_maker('stub_path', 'stub_repo_id', config)
|
||||
repo.example_call()
|
||||
stub_session_factory().post.assert_called_with(
|
||||
'http://server_and_port/endpoint', data=mock.ANY)
|
||||
'http://server_and_port/endpoint', data=mock.ANY,
|
||||
headers={'X-RC-Method': 'example_call', 'X-RC-Repo-Name': 'stub_path'})
|
||||
|
||||
|
||||
@mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue