Skip to content

Commit a574cee

Browse files
authored
feat(workers): add logging to verify oss-fuzz-specific tasks (#4041)
Add some logging to confirm my understanding of the oss-fuzz-specific worker tasks. Also made oss-fuzz `update` tasks publish a separate `update-oss-fuzz` type (though the handling is the same) so our eventual decoupling is clearer.
1 parent 5a9d1ab commit a574cee

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

gcp/workers/importer/importer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ def _request_analysis_external(self,
197197
path,
198198
deleted=False):
199199
"""Request analysis."""
200+
# TODO(michaelkedar): Making a distinction for oss-fuzz updates so we can
201+
# track the logic flow for our eventual decoupling of the special logic.
202+
task_type = 'update'
203+
if source_repo.name == 'oss-fuzz':
204+
task_type = 'update-oss-fuzz'
200205
self._publisher.publish(
201206
self._tasks_topic,
202207
data=b'',
203-
type='update',
208+
type=task_type,
204209
source=source_repo.name,
205210
path=path,
206211
original_sha256=original_sha256,

gcp/workers/importer/importer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def test_basic(self, unused_mock_time: mock.MagicMock,
202202
'19a3cd03fc15360bf16187f54df92a75'),
203203
path='2021-111.yaml',
204204
source='oss-fuzz',
205-
type='update',
205+
type='update-oss-fuzz',
206206
req_timestamp='12345')
207207
])
208208
bug = osv.Bug.get_by_id('OSV-2017-134')
@@ -357,7 +357,7 @@ def test_scheduled_updates(self, unused_mock_time: mock.MagicMock,
357357
'19a3cd03fc15360bf16187f54df92a75'),
358358
path='proj/OSV-2021-1337.yaml',
359359
source='oss-fuzz',
360-
type='update',
360+
type='update-oss-fuzz',
361361
req_timestamp='12345'),
362362
mock.call(
363363
self.tasks_topic,

gcp/workers/worker/worker.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,20 @@ def _do_process_task(self, subscriber, subscription, ack_id, message,
621621
_state.bug_id = message.attributes.get('allocated_bug_id', None)
622622

623623
task_type = message.attributes['type']
624+
625+
# Validating that oss-fuzz-related tasks are only sent by oss-fuzz and
626+
# the non-oss-fuzz task is not used by oss-fuzz.
627+
if not source_id:
628+
logging.error('got message without source_id: %s', message)
629+
elif source_id.startswith('oss-fuzz'):
630+
if task_type not in ('regressed', 'fixed', 'impact', 'invalid',
631+
'update-oss-fuzz'):
632+
logging.error('got unexpected \'%s\' task for oss-fuzz source %s',
633+
task_type, source_id)
634+
elif task_type != 'update':
635+
logging.error('got unexpected \'%s\' task for non-oss-fuzz source %s',
636+
task_type, source_id)
637+
624638
if task_type in ('regressed', 'fixed'):
625639
oss_fuzz.process_bisect_task(self._oss_fuzz_dir, task_type, source_id,
626640
message)
@@ -631,6 +645,9 @@ def _do_process_task(self, subscriber, subscription, ack_id, message,
631645
logging.exception('Failed to process impact: ')
632646
elif task_type == 'invalid':
633647
mark_bug_invalid(message)
648+
elif task_type == 'update-oss-fuzz':
649+
# TODO(michaelkedar): create separate _source_update for oss-fuzz.
650+
self._source_update(message)
634651
elif task_type == 'update':
635652
self._source_update(message)
636653

0 commit comments

Comments
 (0)