Log more information about what events trigger a reconfig
A tenant reconfiguration might be caused by a branch creation, deletion, or change to files. Cause TriggerEvents to repr themselves with flags indicating which of those are true. Have the GithubTriggerEvent also repr itself with the associated delivery id for easier tracing. Finally, have the scheduler log these events when performing a tenant reconfiguration so we can see all the info. Change-Id: I2cfc7615dfb3533aeb9d42b009cc67ce88a5ee48
This commit is contained in:
parent
057d664ecc
commit
9a0d4df0a3
|
@ -2809,10 +2809,10 @@ class TestScheduler(ZuulTestCase):
|
|||
self.sched.run_handler_lock.acquire()
|
||||
self.assertEqual(self.sched.management_event_queue.qsize(), 0)
|
||||
|
||||
self.sched.reconfigureTenant(tenant, project)
|
||||
self.sched.reconfigureTenant(tenant, project, None)
|
||||
self.assertEqual(self.sched.management_event_queue.qsize(), 1)
|
||||
|
||||
self.sched.reconfigureTenant(tenant, project)
|
||||
self.sched.reconfigureTenant(tenant, project, None)
|
||||
# The second event should have been combined with the first
|
||||
# so we should still only have one entry.
|
||||
self.assertEqual(self.sched.management_event_queue.qsize(), 1)
|
||||
|
@ -4853,7 +4853,7 @@ For CI problems and help debugging, contact ci@example.org"""
|
|||
self.waitUntilSettled()
|
||||
# Reconfigure while we still have an outstanding merge job
|
||||
self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'],
|
||||
None)
|
||||
None, None)
|
||||
self.waitUntilSettled()
|
||||
# Verify the merge job is still running and that the item is
|
||||
# in the pipeline
|
||||
|
|
|
@ -133,8 +133,9 @@ class GithubGearmanWorker(object):
|
|||
self.log.debug("Request headers missing the X-Github-Event.")
|
||||
raise Exception('Please specify a X-Github-Event header.')
|
||||
|
||||
delivery = headers.get('x-github-delivery')
|
||||
try:
|
||||
self.connection.addEvent(body, event)
|
||||
self.connection.addEvent(body, event, delivery)
|
||||
except Exception:
|
||||
message = 'Exception deserializing JSON body'
|
||||
self.log.exception(message)
|
||||
|
@ -183,7 +184,7 @@ class GithubEventConnector(threading.Thread):
|
|||
self.connection.addEvent(None)
|
||||
|
||||
def _handleEvent(self):
|
||||
ts, json_body, event_type = self.connection.getEvent()
|
||||
ts, json_body, event_type, delivery = self.connection.getEvent()
|
||||
if self._stopped:
|
||||
return
|
||||
|
||||
|
@ -218,6 +219,7 @@ class GithubEventConnector(threading.Thread):
|
|||
event = None
|
||||
|
||||
if event:
|
||||
event.delivery = delivery
|
||||
if event.change_number:
|
||||
project = self.connection.source.getProject(event.project_name)
|
||||
self.connection._getChange(project,
|
||||
|
@ -671,8 +673,8 @@ class GithubConnection(BaseConnection):
|
|||
# check if we need to do further paged calls
|
||||
url = response.links.get('next', {}).get('url')
|
||||
|
||||
def addEvent(self, data, event=None):
|
||||
return self.event_queue.put((time.time(), data, event))
|
||||
def addEvent(self, data, event=None, delivery=None):
|
||||
return self.event_queue.put((time.time(), data, event, delivery))
|
||||
|
||||
def getEvent(self):
|
||||
return self.event_queue.get()
|
||||
|
|
|
@ -53,6 +53,7 @@ class GithubTriggerEvent(TriggerEvent):
|
|||
self.title = None
|
||||
self.label = None
|
||||
self.unlabel = None
|
||||
self.delivery = None
|
||||
|
||||
def isPatchsetCreated(self):
|
||||
if self.type == 'pull_request':
|
||||
|
@ -64,6 +65,12 @@ class GithubTriggerEvent(TriggerEvent):
|
|||
return 'closed' == self.action
|
||||
return False
|
||||
|
||||
def _repr(self):
|
||||
r = [super(GithubTriggerEvent, self)._repr()]
|
||||
if self.delivery:
|
||||
r.append('delivery: %s' % self.delivery)
|
||||
return ' '.join(r)
|
||||
|
||||
|
||||
class GithubCommonFilter(object):
|
||||
def __init__(self, required_reviews=[], required_statuses=[],
|
||||
|
|
|
@ -2463,6 +2463,20 @@ class TriggerEvent(object):
|
|||
def isChangeAbandoned(self):
|
||||
return False
|
||||
|
||||
def _repr(self):
|
||||
flags = [str(self.type)]
|
||||
if self.branch_updated:
|
||||
flags.append('branch_updated')
|
||||
if self.branch_created:
|
||||
flags.append('branch_created')
|
||||
if self.branch_deleted:
|
||||
flags.append('branch_deleted')
|
||||
return ' '.join(flags)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s 0x%x %s>' % (self.__class__.__name__,
|
||||
id(self), self._repr())
|
||||
|
||||
|
||||
class BaseFilter(ConfigObject):
|
||||
"""Base Class for filtering which Changes and Events to process."""
|
||||
|
|
|
@ -425,9 +425,10 @@ class Scheduler(threading.Thread):
|
|||
self.result_event_queue.put(event)
|
||||
self.wake_event.set()
|
||||
|
||||
def reconfigureTenant(self, tenant, project):
|
||||
def reconfigureTenant(self, tenant, project, event):
|
||||
self.log.debug("Submitting tenant reconfiguration event for "
|
||||
"%s due to project %s", tenant.name, project)
|
||||
"%s due to event %s in project %s",
|
||||
tenant.name, event, project)
|
||||
event = TenantReconfigureEvent(tenant, project)
|
||||
self.management_event_queue.put(event)
|
||||
self.wake_event.set()
|
||||
|
@ -942,7 +943,7 @@ class Scheduler(threading.Thread):
|
|||
# or a branch was just created or deleted. Clear
|
||||
# out cached data for this project and perform a
|
||||
# reconfiguration.
|
||||
self.reconfigureTenant(tenant, change.project)
|
||||
self.reconfigureTenant(tenant, change.project, event)
|
||||
for pipeline in tenant.layout.pipelines.values():
|
||||
if event.isPatchsetCreated():
|
||||
pipeline.manager.removeOldVersionsOfChange(change)
|
||||
|
|
Loading…
Reference in New Issue