|
2 | 2 | import logging
|
3 | 3 | from datetime import datetime
|
4 | 4 | from hashlib import sha1
|
5 |
| -from typing import List, Tuple |
| 5 | +from typing import List, Optional, Tuple |
6 | 6 |
|
7 | 7 | import simplejson as json
|
8 | 8 |
|
9 | 9 | from django.conf import settings
|
10 | 10 | from treeherder.log_parser.utils import validate_perf_data
|
11 |
| -from treeherder.model.models import Job, OptionCollection |
| 11 | +from treeherder.model.models import Job, OptionCollection, Repository |
12 | 12 | from treeherder.perf.models import (
|
13 | 13 | MultiCommitDatum,
|
14 | 14 | PerformanceDatum,
|
| 15 | + PerformanceDatumReplicate, |
15 | 16 | PerformanceFramework,
|
16 | 17 | PerformanceSignature,
|
17 | 18 | )
|
@@ -117,6 +118,18 @@ def _test_should_alert_based_on(
|
117 | 118 | )
|
118 | 119 |
|
119 | 120 |
|
| 121 | +def _test_should_gather_replicates_based_on( |
| 122 | + repository: Repository, replicates: Optional[List] = None |
| 123 | +) -> bool: |
| 124 | + """ |
| 125 | + Determine if we should gather/ingest replicates. Currently, it's |
| 126 | + only available on the try branch. Some tests also don't have replicates |
| 127 | + available as it's not a required field in our performance artifact |
| 128 | + schema. |
| 129 | + """ |
| 130 | + return replicates and len(replicates) > 0 and repository.name in ("try",) |
| 131 | + |
| 132 | + |
120 | 133 | def _load_perf_datum(job: Job, perf_datum: dict):
|
121 | 134 | validate_perf_data(perf_datum)
|
122 | 135 |
|
@@ -271,6 +284,25 @@ def _load_perf_datum(job: Job, perf_datum: dict):
|
271 | 284 | push_timestamp=deduced_timestamp,
|
272 | 285 | defaults={'value': value[0], 'application_version': application_version},
|
273 | 286 | )
|
| 287 | + |
| 288 | + if _test_should_gather_replicates_based_on( |
| 289 | + job.repository, subtest.get("replicates", []) |
| 290 | + ): |
| 291 | + try: |
| 292 | + # Add the replicates to the PerformanceDatumReplicate table, and |
| 293 | + # catch and ignore any exceptions that are produced here so we don't |
| 294 | + # impact the standard workflow |
| 295 | + PerformanceDatumReplicate.objects.bulk_create( |
| 296 | + [ |
| 297 | + PerformanceDatumReplicate( |
| 298 | + value=replicate, performance_datum=subtest_datum |
| 299 | + ) |
| 300 | + for replicate in subtest["replicates"] |
| 301 | + ] |
| 302 | + ) |
| 303 | + except Exception as e: |
| 304 | + logger.info(f"Failed to ingest replicates for datum {subtest_datum}: {e}") |
| 305 | + |
274 | 306 | if subtest_datum.should_mark_as_multi_commit(is_multi_commit, datum_created):
|
275 | 307 | # keep a register with all multi commit perf data
|
276 | 308 | MultiCommitDatum.objects.create(perf_datum=subtest_datum)
|
|
0 commit comments