Show More
@@ -229,6 +229,7 b' class HTTPApplication(object):' | |||||
229 | self.config = Configurator(settings=settings) |
|
229 | self.config = Configurator(settings=settings) | |
230 | # Init our statsd at very start |
|
230 | # Init our statsd at very start | |
231 | self.config.registry.statsd = StatsdClient.statsd |
|
231 | self.config.registry.statsd = StatsdClient.statsd | |
|
232 | self.config.registry.vcs_call_context = {} | |||
232 |
|
233 | |||
233 | self.global_config = global_config |
|
234 | self.global_config = global_config | |
234 | self.config.include('vcsserver.lib.rc_cache') |
|
235 | self.config.include('vcsserver.lib.rc_cache') | |
@@ -326,6 +327,11 b' class HTTPApplication(object):' | |||||
326 | kwargs = params.get('kwargs') |
|
327 | kwargs = params.get('kwargs') | |
327 | context_uid = None |
|
328 | context_uid = None | |
328 |
|
329 | |||
|
330 | request.registry.vcs_call_context = { | |||
|
331 | 'method': method, | |||
|
332 | 'repo_name': payload.get('_repo_name') | |||
|
333 | } | |||
|
334 | ||||
329 | if wire: |
|
335 | if wire: | |
330 | try: |
|
336 | try: | |
331 | wire['context'] = context_uid = uuid.UUID(wire['context']) |
|
337 | wire['context'] = context_uid = uuid.UUID(wire['context']) | |
@@ -556,16 +562,19 b' class HTTPApplication(object):' | |||||
556 | @wsgiapp |
|
562 | @wsgiapp | |
557 | def _hg_stream(environ, start_response): |
|
563 | def _hg_stream(environ, start_response): | |
558 | log.debug('http-app: handling hg stream') |
|
564 | log.debug('http-app: handling hg stream') | |
559 | repo_path = environ['HTTP_X_RC_REPO_PATH'] |
|
565 | ||
560 |
|
|
566 | packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) | |
561 | packed_config = base64.b64decode( |
|
567 | call_context = msgpack.unpackb(packed_cc) | |
562 | environ['HTTP_X_RC_REPO_CONFIG']) |
|
568 | ||
563 | config = msgpack.unpackb(packed_config) |
|
569 | repo_path = call_context['repo_path'] | |
|
570 | repo_name = call_context['repo_name'] | |||
|
571 | config = call_context['repo_config'] | |||
|
572 | ||||
564 | app = scm_app.create_hg_wsgi_app( |
|
573 | app = scm_app.create_hg_wsgi_app( | |
565 | repo_path, repo_name, config) |
|
574 | repo_path, repo_name, config) | |
566 |
|
575 | |||
567 | # Consistent path information for hgweb |
|
576 | # Consistent path information for hgweb | |
568 |
environ['PATH_INFO'] = |
|
577 | environ['PATH_INFO'] = call_context['path_info'] | |
569 | environ['REPO_NAME'] = repo_name |
|
578 | environ['REPO_NAME'] = repo_name | |
570 | self.set_env_from_config(environ, config) |
|
579 | self.set_env_from_config(environ, config) | |
571 |
|
580 | |||
@@ -585,13 +594,15 b' class HTTPApplication(object):' | |||||
585 | @wsgiapp |
|
594 | @wsgiapp | |
586 | def _git_stream(environ, start_response): |
|
595 | def _git_stream(environ, start_response): | |
587 | log.debug('http-app: handling git stream') |
|
596 | log.debug('http-app: handling git stream') | |
588 | repo_path = environ['HTTP_X_RC_REPO_PATH'] |
|
597 | ||
589 |
|
|
598 | packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) | |
590 | packed_config = base64.b64decode( |
|
599 | call_context = msgpack.unpackb(packed_cc) | |
591 | environ['HTTP_X_RC_REPO_CONFIG']) |
|
|||
592 | config = msgpack.unpackb(packed_config) |
|
|||
593 |
|
600 | |||
594 | environ['PATH_INFO'] = environ['HTTP_X_RC_PATH_INFO'] |
|
601 | repo_path = call_context['repo_path'] | |
|
602 | repo_name = call_context['repo_name'] | |||
|
603 | config = call_context['repo_config'] | |||
|
604 | ||||
|
605 | environ['PATH_INFO'] = call_context['path_info'] | |||
595 | self.set_env_from_config(environ, config) |
|
606 | self.set_env_from_config(environ, config) | |
596 |
|
607 | |||
597 | content_type = environ.get('CONTENT_TYPE', '') |
|
608 | content_type = environ.get('CONTENT_TYPE', '') |
@@ -18,6 +18,8 b'' | |||||
18 | import time |
|
18 | import time | |
19 | import logging |
|
19 | import logging | |
20 |
|
20 | |||
|
21 | import msgpack | |||
|
22 | ||||
21 | import vcsserver |
|
23 | import vcsserver | |
22 | from vcsserver.str_utils import safe_str, ascii_str |
|
24 | from vcsserver.str_utils import safe_str, ascii_str | |
23 |
|
25 | |||
@@ -33,12 +35,15 b' def get_user_agent(environ):' | |||||
33 | return environ.get('HTTP_USER_AGENT') |
|
35 | return environ.get('HTTP_USER_AGENT') | |
34 |
|
36 | |||
35 |
|
37 | |||
36 | def get_vcs_method(environ): |
|
38 | def get_call_context(registry) -> dict: | |
37 | return environ.get('HTTP_X_RC_METHOD') |
|
39 | cc = {} | |
|
40 | if hasattr(registry, 'vcs_call_context'): | |||
|
41 | cc.update({ | |||
|
42 | 'X-RC-Method': registry.vcs_call_context.get('method'), | |||
|
43 | 'X-RC-Repo-Name': registry.vcs_call_context.get('repo_name') | |||
|
44 | }) | |||
38 |
|
45 | |||
39 |
|
46 | return cc | ||
40 | def get_vcs_repo(environ): |
|
|||
41 | return environ.get('HTTP_X_RC_REPO_NAME') |
|
|||
42 |
|
47 | |||
43 |
|
48 | |||
44 | class RequestWrapperTween(object): |
|
49 | class RequestWrapperTween(object): | |
@@ -53,23 +58,26 b' class RequestWrapperTween(object):' | |||||
53 | log.debug('Starting request time measurement') |
|
58 | log.debug('Starting request time measurement') | |
54 | response = None |
|
59 | response = None | |
55 |
|
60 | |||
56 | ua = get_user_agent(request.environ) |
|
|||
57 | vcs_method = get_vcs_method(request.environ) |
|
|||
58 | repo_name = get_vcs_repo(request.environ) |
|
|||
59 |
|
||||
60 | try: |
|
61 | try: | |
61 | response = self.handler(request) |
|
62 | response = self.handler(request) | |
62 | finally: |
|
63 | finally: | |
|
64 | ua = get_user_agent(request.environ) | |||
|
65 | call_context = get_call_context(request.registry) | |||
|
66 | vcs_method = call_context.get('X-RC-Method', '_NO_VCS_METHOD') | |||
|
67 | repo_name = call_context.get('X-RC-Repo-Name', '') | |||
|
68 | ||||
63 | count = request.request_count() |
|
69 | count = request.request_count() | |
64 | _ver_ = ascii_str(vcsserver.__version__) |
|
70 | _ver_ = ascii_str(vcsserver.__version__) | |
65 | _path = safe_str(get_access_path(request.environ)) |
|
71 | _path = safe_str(get_access_path(request.environ)) | |
|
72 | ||||
66 | ip = '127.0.0.1' |
|
73 | ip = '127.0.0.1' | |
67 | match_route = request.matched_route.name if request.matched_route else "NOT_FOUND" |
|
74 | match_route = request.matched_route.name if request.matched_route else "NOT_FOUND" | |
68 | resp_code = getattr(response, 'status_code', 'UNDEFINED') |
|
75 | resp_code = getattr(response, 'status_code', 'UNDEFINED') | |
69 |
|
76 | |||
|
77 | _view_path = f"{repo_name}@{_path}/{vcs_method}" | |||
|
78 | ||||
70 | total = time.time() - start |
|
79 | total = time.time() - start | |
71 |
|
80 | |||
72 | _view_path = f"{repo_name}@{_path}/{vcs_method}" |
|
|||
73 | log.info( |
|
81 | log.info( | |
74 | 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s', |
|
82 | 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s', | |
75 | count, ip, request.environ.get('REQUEST_METHOD'), |
|
83 | count, ip, request.environ.get('REQUEST_METHOD'), |
General Comments 0
You need to be logged in to leave comments.
Login now