Annotate getChangeByUrl logs with event id

This causes e.g. web requests that should be trackable via the event
id in the logs.

Change-Id: Iade2558f2312aedca7480b4ea1d3df60735cfc90
This commit is contained in:
Tobias Henkel 2020-07-30 15:28:30 +02:00
parent 9c623851c4
commit e4a207e5c9
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
8 changed files with 23 additions and 17 deletions

View File

@ -55,7 +55,7 @@ class GerritSource(BaseSource):
def getChange(self, event, refresh=False): def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh) return self.connection.getChange(event, refresh)
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
try: try:
parsed = urllib.parse.urlparse(url) parsed = urllib.parse.urlparse(url)
except ValueError: except ValueError:
@ -71,11 +71,12 @@ class GerritSource(BaseSource):
except ValueError: except ValueError:
return None return None
query = "change:%s" % (change_no,) query = "change:%s" % (change_no,)
results = self.connection.simpleQuery(query) results = self.connection.simpleQuery(query, event=event)
if not results: if not results:
return None return None
change = self.connection._getChange( change = self.connection._getChange(
results[0].number, results[0].current_patchset) results[0].number, results[0].current_patchset,
event=event)
return change return change
def getChangesDependingOn(self, change, projects, tenant): def getChangesDependingOn(self, change, projects, tenant):

View File

@ -38,7 +38,7 @@ class GitSource(BaseSource):
def getChange(self, event, refresh=False): def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh) return self.connection.getChange(event, refresh)
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
return None return None
def getChangesDependingOn(self, change, projects, tenant): def getChangesDependingOn(self, change, projects, tenant):

View File

@ -67,7 +67,7 @@ class GithubSource(BaseSource):
change_re = re.compile(r"/(.*?)/(.*?)/pull/(\d+)[\w]*") change_re = re.compile(r"/(.*?)/(.*?)/pull/(\d+)[\w]*")
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
try: try:
parsed = urllib.parse.urlparse(url) parsed = urllib.parse.urlparse(url)
except ValueError: except ValueError:
@ -81,14 +81,16 @@ class GithubSource(BaseSource):
num = int(m.group(3)) num = int(m.group(3))
except ValueError: except ValueError:
return None return None
pull, pr_obj = self.connection.getPull('%s/%s' % (org, proj), int(num)) pull, pr_obj = self.connection.getPull(
'%s/%s' % (org, proj), int(num), event=event)
if not pull: if not pull:
return None return None
proj = pull.get('base').get('repo').get('full_name') proj = pull.get('base').get('repo').get('full_name')
project = self.getProject(proj) project = self.getProject(proj)
change = self.connection._getChange( change = self.connection._getChange(
project, num, project, num,
patchset=pull.get('head').get('sha')) patchset=pull.get('head').get('sha'),
event=event)
return change return change
def getChangesDependingOn(self, change, projects, tenant): def getChangesDependingOn(self, change, projects, tenant):

View File

@ -55,7 +55,7 @@ class GitlabSource(BaseSource):
def getChange(self, event, refresh=False): def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh) return self.connection.getChange(event, refresh)
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
try: try:
parsed = urllib.parse.urlparse(url) parsed = urllib.parse.urlparse(url)
except ValueError: except ValueError:
@ -68,12 +68,13 @@ class GitlabSource(BaseSource):
num = int(m.group(2)) num = int(m.group(2))
except ValueError: except ValueError:
return None return None
mr = self.connection.getPull(project_name, num) mr = self.connection.getPull(project_name, num, event=event)
if not mr: if not mr:
return None return None
project = self.getProject(project_name) project = self.getProject(project_name)
change = self.connection._getChange( change = self.connection._getChange(
project, num, mr['sha'], url=url) project, num, mr['sha'], url=url,
event=event)
return change return change
def getChangesDependingOn(self, change, projects, tenant): def getChangesDependingOn(self, change, projects, tenant):

View File

@ -753,12 +753,13 @@ class PagureConnection(BaseConnection):
change.project.name, change.number, can_merge) change.project.name, change.number, can_merge)
return can_merge return can_merge
def getPull(self, project_name, number): def getPull(self, project_name, number, event=None):
log = get_annotated_logger(self.log, event=event)
pagure = self.get_project_api_client(project_name) pagure = self.get_project_api_client(project_name)
pr = pagure.get_pr(number) pr = pagure.get_pr(number)
diffstats = pagure.get_pr_diffstats(number) diffstats = pagure.get_pr_diffstats(number)
pr['files'] = list(diffstats.keys()) pr['files'] = list(diffstats.keys())
self.log.info('Got PR %s#%s', project_name, number) log.info('Got PR %s#%s', project_name, number)
return pr return pr
def getStatus(self, project, number): def getStatus(self, project, number):

View File

@ -62,7 +62,7 @@ class PagureSource(BaseSource):
def getChange(self, event, refresh=False): def getChange(self, event, refresh=False):
return self.connection.getChange(event, refresh) return self.connection.getChange(event, refresh)
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
try: try:
parsed = urllib.parse.urlparse(url) parsed = urllib.parse.urlparse(url)
except ValueError: except ValueError:
@ -75,14 +75,15 @@ class PagureSource(BaseSource):
num = int(m.group(2)) num = int(m.group(2))
except ValueError: except ValueError:
return None return None
pull = self.connection.getPull(project_name, num) pull = self.connection.getPull(project_name, num, event=event)
if not pull: if not pull:
return None return None
project = self.getProject(project_name) project = self.getProject(project_name)
change = self.connection._getChange( change = self.connection._getChange(
project, num, project, num,
patchset=pull.get('commit_stop'), patchset=pull.get('commit_stop'),
url=url) url=url,
event=event)
return change return change
def getChangesDependingOn(self, change, projects, tenant): def getChangesDependingOn(self, change, projects, tenant):

View File

@ -445,7 +445,7 @@ class PipelineManager(metaclass=ABCMeta):
if not source: if not source:
continue continue
log.debug(" Found source: %s", source) log.debug(" Found source: %s", source)
dep = source.getChangeByURL(match) dep = source.getChangeByURL(match, event)
if dep and (not dep.is_merged) and dep not in dependencies: if dep and (not dep.is_merged) and dep not in dependencies:
log.debug(" Adding dependency: %s", dep) log.debug(" Adding dependency: %s", dep)
dependencies.append(dep) dependencies.append(dep)

View File

@ -59,7 +59,7 @@ class BaseSource(object, metaclass=abc.ABCMeta):
""" """
@abc.abstractmethod @abc.abstractmethod
def getChangeByURL(self, url): def getChangeByURL(self, url, event):
"""Get the change corresponding to the supplied URL. """Get the change corresponding to the supplied URL.
The URL may may not correspond to this source; if it doesn't, The URL may may not correspond to this source; if it doesn't,