Skip to content

Commit 772e136

Browse files
authored
Bug 1831941 - Ingest replicates in a new PerformanceDatumReplicate table. (#7693)
* Bug XXX - Ingest replicates in a new PerformanceDatumReplicate table. * Changes * changes * changes * lint fixes
1 parent 7e7155a commit 772e136

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

treeherder/etl/perf.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
import logging
33
from datetime import datetime
44
from hashlib import sha1
5-
from typing import List, Tuple
5+
from typing import List, Optional, Tuple
66

77
import simplejson as json
88

99
from django.conf import settings
1010
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
1212
from treeherder.perf.models import (
1313
MultiCommitDatum,
1414
PerformanceDatum,
15+
PerformanceDatumReplicate,
1516
PerformanceFramework,
1617
PerformanceSignature,
1718
)
@@ -117,6 +118,18 @@ def _test_should_alert_based_on(
117118
)
118119

119120

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+
120133
def _load_perf_datum(job: Job, perf_datum: dict):
121134
validate_perf_data(perf_datum)
122135

@@ -271,6 +284,25 @@ def _load_perf_datum(job: Job, perf_datum: dict):
271284
push_timestamp=deduced_timestamp,
272285
defaults={'value': value[0], 'application_version': application_version},
273286
)
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+
274306
if subtest_datum.should_mark_as_multi_commit(is_multi_commit, datum_created):
275307
# keep a register with all multi commit perf data
276308
MultiCommitDatum.objects.create(perf_datum=subtest_datum)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 4.0.8 on 2023-05-08 17:59
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
('perf', '0048_performancedatum_application_version'),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='PerformanceDatumReplicate',
15+
fields=[
16+
('id', models.BigAutoField(primary_key=True, serialize=False)),
17+
('value', models.FloatField()),
18+
(
19+
'performance_datum',
20+
models.ForeignKey(
21+
on_delete=django.db.models.deletion.CASCADE, to='perf.performancedatum'
22+
),
23+
),
24+
],
25+
options={
26+
'db_table': 'performance_datum_replicate',
27+
},
28+
),
29+
]

treeherder/perf/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _get_alert_change_type(alert_change_type_input):
105105
Maps a schema-specified alert change type to the internal index
106106
value
107107
"""
108-
for (idx, enum_val) in PerformanceSignature.ALERT_CHANGE_TYPES:
108+
for idx, enum_val in PerformanceSignature.ALERT_CHANGE_TYPES:
109109
if enum_val == alert_change_type_input:
110110
return idx
111111
return None
@@ -227,6 +227,15 @@ def __str__(self):
227227
return "{} {}".format(self.value, self.push_timestamp)
228228

229229

230+
class PerformanceDatumReplicate(models.Model):
231+
id = models.BigAutoField(primary_key=True)
232+
performance_datum = models.ForeignKey(PerformanceDatum, on_delete=models.CASCADE)
233+
value = models.FloatField()
234+
235+
class Meta:
236+
db_table = 'performance_datum_replicate'
237+
238+
230239
class MultiCommitDatum(models.Model):
231240
perf_datum = models.OneToOneField(
232241
PerformanceDatum,

0 commit comments

Comments
 (0)