##// END OF EJS Templates
statsd/audit-logs: cleanup push/pull user agent code....
super-admin -
r4858:6f1f534f default
parent child Browse files
Show More
@@ -31,6 +31,7 b' log = logging.getLogger(__name__)'
31 31
32 32
33 33 class VcsServer(object):
34 repo_user_agent = None # set in child classes
34 35 _path = None # set executable path for hg/git/svn binary
35 36 backend = None # set in child classes
36 37 tunnel = None # subprocess handling tunnel
@@ -106,7 +107,7 b' class VcsServer(object):'
106 107 'make_lock': None,
107 108 'locked_by': [None, None],
108 109 'server_url': None,
109 'user_agent': 'ssh-user-agent',
110 'user_agent': '{}/ssh-user-agent'.format(self.repo_user_agent),
110 111 'hooks': ['push', 'pull'],
111 112 'hooks_module': 'rhodecode.lib.hooks_daemon',
112 113 'is_shadow_repo': False,
@@ -59,6 +59,7 b' class GitTunnelWrapper(object):'
59 59
60 60 class GitServer(VcsServer):
61 61 backend = 'git'
62 repo_user_agent = 'git'
62 63
63 64 def __init__(self, store, ini_path, repo_name, repo_mode,
64 65 user, user_permissions, config, env):
@@ -97,6 +97,7 b' class MercurialTunnelWrapper(object):'
97 97
98 98 class MercurialServer(VcsServer):
99 99 backend = 'hg'
100 repo_user_agent = 'mercurial'
100 101 cli_flags = ['phases', 'largefiles', 'extensions', 'experimental', 'hooks']
101 102
102 103 def __init__(self, store, ini_path, repo_name, user, user_permissions, config, env):
@@ -222,6 +222,7 b' class SubversionTunnelWrapper(object):'
222 222
223 223 class SubversionServer(VcsServer):
224 224 backend = 'svn'
225 repo_user_agent = 'svn'
225 226
226 227 def __init__(self, store, ini_path, repo_name,
227 228 user, user_permissions, config, env):
@@ -148,7 +148,7 b' class TestGitServer(object):'
148 148 'hooks_module': 'rhodecode.lib.hooks_daemon',
149 149 'check_branch_perms': False,
150 150 'detect_force_push': False,
151 'user_agent': u'ssh-user-agent',
151 'user_agent': u'git/ssh-user-agent',
152 152 'SSH': True,
153 153 'SSH_PERMISSIONS': 'repository.admin',
154 154 }
@@ -30,7 +30,7 b' import rhodecode'
30 30 from rhodecode import events
31 31 from rhodecode.lib import helpers as h
32 32 from rhodecode.lib import audit_logger
33 from rhodecode.lib.utils2 import safe_str
33 from rhodecode.lib.utils2 import safe_str, user_agent_normalizer
34 34 from rhodecode.lib.exceptions import (
35 35 HTTPLockedRC, HTTPBranchProtected, UserCreationError)
36 36 from rhodecode.model.db import Repository, User
@@ -222,8 +222,9 b' def post_pull(extras):'
222 222
223 223 statsd = StatsdClient.statsd
224 224 if statsd:
225 statsd.incr('rhodecode_pull_total')
226
225 statsd.incr('rhodecode_pull_total', tags=[
226 'user-agent:{}'.format(user_agent_normalizer(extras.user_agent)),
227 ])
227 228 output = ''
228 229 # make lock is a tri state False, True, None. We only make lock on True
229 230 if extras.make_lock is True and not is_shadow_repo(extras):
@@ -271,7 +272,9 b' def post_push(extras):'
271 272
272 273 statsd = StatsdClient.statsd
273 274 if statsd:
274 statsd.incr('rhodecode_push_total')
275 statsd.incr('rhodecode_push_total', tags=[
276 'user-agent:{}'.format(user_agent_normalizer(extras.user_agent)),
277 ])
275 278
276 279 # Propagate to external components.
277 280 output = ''
@@ -1146,3 +1146,20 b' def retry(func=None, exception=Exception'
1146 1146 return func(*args, **kwargs)
1147 1147
1148 1148 return wrapper
1149
1150
1151 def user_agent_normalizer(user_agent_raw):
1152 log = logging.getLogger('rhodecode.user_agent_normalizer')
1153 ua = (user_agent_raw or '').strip().lower()
1154
1155 try:
1156 if 'mercurial/proto-1.0' in ua:
1157 ua = ua.replace('mercurial/proto-1.0', '')
1158 ua = ua.replace('(', '').replace(')', '').strip()
1159 ua = ua.replace('mercurial ', 'mercurial/')
1160 elif ua.startswith('git'):
1161 pass
1162 except Exception:
1163 log.exception('Failed to parse scm user-agent')
1164
1165 return ua
@@ -939,8 +939,9 b' class PullRequestModel(BaseModel):'
939 939 return commit_ids
940 940
941 941 def merge_repo(self, pull_request, user, extras):
942 repo_type = pull_request.source_repo.repo_type
942 943 log.debug("Merging pull request %s", pull_request.pull_request_id)
943 extras['user_agent'] = 'internal-merge'
944 extras['user_agent'] = '{}/internal-merge'.format(repo_type)
944 945 merge_state = self._merge_pull_request(pull_request, user, extras)
945 946 if merge_state.executed:
946 947 log.debug("Merge was successful, updating the pull request comments.")
General Comments 0
You need to be logged in to leave comments. Login now