Skip to content

Commit 84209bf

Browse files
Make untrusted_host use timestamps instead of dates (#4181)
It's simpler to use timestamps with protos, and we've been doing this already in chrome and internal google. Fixes: https://pantheon.corp.google.com/errors/detail/CM3Hppa8wfSgCQ;time=PT6H;locations=global?e=-13802955&mods=logs_tg_prod&project=clusterfuzz-external ``` AttributeError: 'datetime.date' object has no attribute 'utctimetuple' at .FromDatetime ( /mnt/scratch0/bots/oss-fuzz-linux-zone5-host-9xqb-0/clusterfuzz/src/third_party/google/protobuf/internal/well_known_types.py:270 ) at ._extract_coverage_information ( /mnt/scratch0/bots/oss-fuzz-linux-zone5-host-9xqb-0/clusterfuzz/src/clusterfuzz/_internal/bot/tasks/utasks/corpus_pruning_task.py:960 ) at .utask_main ( /mnt/scratch0/bots/oss-fuzz-linux-zone5-host-9xqb-0/clusterfuzz/src/clusterfuzz/_internal/bot/tasks/utasks/corpus_pruning_task.py:1024 ) ```
1 parent 60a3995 commit 84209bf

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/clusterfuzz/_internal/bot/tasks/utasks/corpus_pruning_task.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,18 @@ def _try_save_coverage_information():
952952
'Failed to save corpus pruning result: %s.' % repr(e))
953953

954954

955+
def _get_proto_timestamp(initial_timestamp):
956+
timestamp = timestamp_pb2.Timestamp() # pylint: disable=no-member
957+
timestamp.FromDatetime(initial_timestamp)
958+
return timestamp
959+
960+
955961
def _extract_coverage_information(context, result):
956962
"""Extracts and stores the coverage information in a proto."""
957963
coverage_info = uworker_msg_pb2.CoverageInformation() # pylint: disable=no-member
958964
coverage_info.project_name = context.fuzz_target.project_qualified_name()
959-
timestamp = timestamp_pb2.Timestamp() # pylint: disable=no-member
960-
timestamp.FromDatetime(result.coverage_info.date)
961-
coverage_info.timestamp.CopyFrom(timestamp)
965+
proto_timestamp = _get_proto_timestamp(result.coverage_info.date)
966+
coverage_info.timestamp.CopyFrom(proto_timestamp)
962967
# Intentionally skip edge and function coverage values as those would come
963968
# from fuzzer coverage cron task.
964969
coverage_info.corpus_size_units = result.coverage_info.corpus_size_units

src/clusterfuzz/_internal/bot/untrusted_runner/tasks_host.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def _fuzz_target_to_proto(fuzz_target):
3939
)
4040

4141

42+
def _get_datetime():
43+
return datetime.datetime.utcnow()
44+
45+
4246
def do_corpus_pruning(uworker_input, context, revision):
4347
"""Do corpus pruning on untrusted worker."""
4448
cross_pollinate_fuzzers = [
@@ -58,7 +62,7 @@ def do_corpus_pruning(uworker_input, context, revision):
5862
response = host.stub().PruneCorpus(request)
5963

6064
project_qualified_name = context.fuzz_target.project_qualified_name()
61-
today_date = datetime.datetime.utcnow().date()
65+
today_date = _get_datetime()
6266
coverage_info = data_types.CoverageInformation(
6367
fuzzer=project_qualified_name, date=today_date)
6468

src/clusterfuzz/_internal/tests/core/bot/tasks/utasks/corpus_pruning_task_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,14 @@ def compare(stats):
586586
return compare
587587

588588

589+
class GetProtoTimestampTest(unittest.TestCase):
590+
591+
def test_get_proto_timestamp_utcnow(self):
592+
"""Tests that _get_proto_timestamp works with utcnow. It should not be used
593+
with date()."""
594+
corpus_pruning_task._get_proto_timestamp(datetime.datetime.utcnow())
595+
596+
589597
@test_utils.supported_platforms('LINUX')
590598
@test_utils.with_cloud_emulators('datastore')
591599
class CrashProcessingTest(unittest.TestCase, BaseTest):

0 commit comments

Comments
 (0)