Gerrit: skip ref-updated /meta events

Approximately 40% of all Gerrit events that OpenDev processes are
ref-updated events for refs/changes/.../meta refs.  This is likely
due to the increased use of notedb for storing data in Gerrit.  Since
Zuul users are not likely to need to trigger off of ref-updates to
the meta ref, let's avoid enqueing them into Zuul's event queue.
This will reduce ZK traffic.

Change-Id: I724f5b20790d1ad32e72b1ce642355c2257026c1
This commit is contained in:
James E. Blair 2024-04-18 14:45:35 -07:00
parent 01e9472306
commit 239fe205ec
2 changed files with 41 additions and 0 deletions

View File

@ -973,6 +973,38 @@ class TestGerritConnection(ZuulTestCase):
self.assertEqual(A.data['status'], 'MERGED')
self.assertEqual(B.data['status'], 'MERGED')
def test_ignored_events(self):
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
event_queue = self.fake_gerrit.gerrit_event_connector.event_queue
# Hold the lock so the scheduler does not pull any events from
# the queue
with self.scheds[0].sched.run_handler_lock:
# This is ignored unconditionally
self.fake_gerrit.addEvent({
"type": "cache-eviction",
})
self.assertEqual(0, len(event_queue._listEvents()))
# This is ignored for meta refs only
self.fake_gerrit.addEvent({
"type": "ref-updated",
"submitter": {
"name": "User Name",
},
"refUpdate": {
"oldRev": '0',
"newRev": '0',
"refName": 'refs/changes/01/1/meta',
"project": 'org/project',
}
})
self.assertEqual(0, len(event_queue._listEvents()))
# This is not ignored
A.setMerged()
self.fake_gerrit.addEvent(A.getRefUpdatedEvent())
self.assertEqual(1, len(event_queue._listEvents()))
self.waitUntilSettled()
def test_submit_requirements(self):
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
A.addApproval('Code-Review', 2)

View File

@ -1163,6 +1163,15 @@ class GerritConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection):
# here to keep logs clean.
if data.get('type') in GerritEventConnector.IGNORED_EVENTS:
return
# Due to notedb, an high percentage of all events Zuul
# processes are ref-updated of the /meta ref, and that is
# unlikely to be used in Zuul. Skip those here so that we
# reduce traffic on the event queue.
if data.get('type') == 'ref-updated':
refname = data.get('refUpdate', {}).get('refName', '')
if (refname.startswith('refs/changes/') and
refname.endswith('/meta')):
return
event_uuid = uuid4().hex
attributes = {