Skip to content

Commit 7c073be

Browse files
committed
Fix LPID - proper list of pushes, classify all tasks in single .update where possible.
1 parent 43752bc commit 7c073be

File tree

1 file changed

+55
-34
lines changed

1 file changed

+55
-34
lines changed

treeherder/log_parser/intermittents.py

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
import datetime
22

3-
from treeherder.model.models import Group, GroupStatus, Job, Push
3+
from treeherder.model.models import Group, GroupStatus, Job, Push, TextLogError
4+
5+
6+
def classify(jobs_to_classify, jobs_to_unclassify):
7+
# TODO: consider job.result=(busted, exception)
8+
if jobs_to_classify:
9+
target_jobs = Job.objects.filter(
10+
id__in=jobs_to_classify, result="testfailed", failure_classification_id__in=[1, 6]
11+
)
12+
if target_jobs:
13+
target_jobs.update(failure_classification_id=8)
14+
15+
if jobs_to_unclassify:
16+
# TODO: query text_log_error for new_failure and use 6 if previously set
17+
new_jobs = (
18+
TextLogError.objects.filter(
19+
job__id__in=jobs_to_unclassify, new_failure=True, job__failure_classification_id=8
20+
)
21+
.values("job__id")
22+
.distinct()
23+
)
24+
jobs_to_six = [j["job__id"] for j in new_jobs]
25+
jobs_to_one = list(set(jobs_to_unclassify) - set(jobs_to_six))
26+
27+
if jobs_to_six:
28+
target_jobs = Job.objects.filter(id__in=jobs_to_six, result="testfailed")
29+
if target_jobs:
30+
target_jobs.update(failure_classification_id=6)
31+
if jobs_to_one:
32+
target_jobs = Job.objects.filter(id__in=jobs_to_one, result="testfailed")
33+
if target_jobs:
34+
target_jobs.update(failure_classification_id=1)
435

536

637
def _check_and_mark_infra(current_job, job_ids, push_ids):
@@ -42,7 +73,7 @@ def _check_and_mark_infra(current_job, job_ids, push_ids):
4273

4374
# ignore previous classified, we are looking for NEW extra jobs
4475
if len([ej for ej in extra_jobs if ej["failure_classification_id"] != 8]) == 0:
45-
return
76+
return [], []
4677

4778
# ensure 50% 'success' rate
4879
# success here means the task ran and produced groups | is success
@@ -52,20 +83,24 @@ def _check_and_mark_infra(current_job, job_ids, push_ids):
5283
if job["id"] not in job_ids and job["result"] != "success":
5384
extra_failed.append(job)
5485

86+
jobs_to_classify = []
87+
jobs_to_unclassify = []
88+
5589
# look for failure rate > 50% and exit early
5690
if len(extra_failed) / len(extra_jobs) > 0.5:
5791
# as failure rate > 50%, if any jobs are fc_id=8 classify as fc_id=1
5892
for job in extra_failed:
5993
if job["failure_classification_id"] == 8:
60-
Job.objects.filter(id=job["id"]).update(failure_classification_id=1)
61-
return
94+
jobs_to_unclassify.append(job["id"])
6295

6396
# any extra_jobs will be failures without groups (infra/timeout/etc.)
6497
# theoretically there could be many jobs here
6598
# mark extra_jobs as `intermittent_needs_classification`
6699
for job in extra_failed:
67100
if job["failure_classification_id"] not in [4, 8]:
68-
Job.objects.filter(id=job["id"]).update(failure_classification_id=8)
101+
jobs_to_classify.append(job["id"])
102+
103+
return jobs_to_classify, jobs_to_unclassify
69104

70105

71106
def check_and_mark_intermittent(job_id):
@@ -91,7 +126,7 @@ def check_and_mark_intermittent(job_id):
91126
)
92127
counter = -1
93128
for id in idlist:
94-
if id == current_job.push.id:
129+
if id["id"] == current_job.push.id:
95130
counter = 0
96131
continue
97132
if counter < 0:
@@ -100,7 +135,7 @@ def check_and_mark_intermittent(job_id):
100135
break
101136
elif current_job.repository.id != 77 and counter >= 3:
102137
break
103-
ids.append(id)
138+
ids.append(id["id"])
104139
counter += 1
105140

106141
all_groups = (
@@ -135,7 +170,8 @@ def check_and_mark_intermittent(job_id):
135170
# If no groups, look for infra
136171
distinct_job_ids = list(set([f["job_logs__job__id"] for f in all_groups]))
137172
if len(distinct_job_ids) == 1:
138-
return _check_and_mark_infra(current_job, distinct_job_ids, ids)
173+
to_classify, to_unclassify = _check_and_mark_infra(current_job, distinct_job_ids, ids)
174+
return classify(to_classify, to_unclassify)
139175

140176
mappings = {}
141177
job_classifications = {}
@@ -151,6 +187,7 @@ def check_and_mark_intermittent(job_id):
151187
# we have a variant
152188
continue
153189

190+
# TODO: consider storing a list of job.id that are fc_id=8
154191
# store job:fc_id so we can reference what needs changed
155192
if item["job_logs__job__id"] not in job_classifications:
156193
job_classifications[item["job_logs__job__id"]] = item[
@@ -181,18 +218,14 @@ def check_and_mark_intermittent(job_id):
181218
current_changed_groups = {}
182219
for group in mappings.get(current_job.push.id, {}).get("groups", []):
183220
all_data = []
184-
current_data = []
221+
current_data = [
222+
mappings[current_job.push.id]["groups"][group][j]
223+
for j in mappings[current_job.push.id]["groups"][group]
224+
]
185225
for id in mappings.keys():
186226
all_data.extend(
187227
[mappings[id]["groups"][group][j] for j in mappings[id]["groups"].get(group, {})]
188228
)
189-
if id == current_job.push.id:
190-
current_data.extend(
191-
[
192-
mappings[id]["groups"][group][j]
193-
for j in mappings[id]["groups"].get(group, {})
194-
]
195-
)
196229

197230
# if new data changes results, update
198231
pass_rate = len([s for s in all_data if s == GroupStatus.OK]) / len(all_data)
@@ -203,9 +236,9 @@ def check_and_mark_intermittent(job_id):
203236
current_changed_groups[group] = True
204237

205238
# all changed_groups need to be evaluated on previous 'failed' jobs to ensure all groups in that task are 'passing'
239+
jobs_to_classify = [] # mark as fcid=8 (known intermittent)
240+
jobs_to_unclassify = [] # previously parked as fcid=8, new failing data, now fcid=1
206241
for id in mappings.keys():
207-
jobs_to_classify = [] # mark as fcid=8 (known intermittent)
208-
jobs_to_unclassify = [] # previously parked as fcid=8, new failing data, now fcid=1
209242
for job in mappings[id]["jobs"]:
210243
all_green = True
211244
current_all_green = True
@@ -229,19 +262,7 @@ def check_and_mark_intermittent(job_id):
229262
elif job_classifications[job] == 8:
230263
jobs_to_unclassify.append(job)
231264

232-
# TODO: consider job.result=(busted, exception)
233-
for job in jobs_to_classify:
234-
target_job = Job.objects.filter(
235-
id=job, result="testfailed", failure_classification_id__in=[1, 6]
236-
)
237-
if target_job:
238-
target_job.update(failure_classification_id=8)
239-
240-
for job in jobs_to_unclassify:
241-
target_job = Job.objects.filter(
242-
id=job, result="testfailed", failure_classification_id=8
243-
)
244-
if target_job:
245-
target_job.update(failure_classification_id=1)
246-
247-
return _check_and_mark_infra(current_job, distinct_job_ids, ids)
265+
to_classify, to_unclassify = _check_and_mark_infra(current_job, distinct_job_ids, ids)
266+
jobs_to_classify.extend(to_classify)
267+
jobs_to_unclassify.extend(to_unclassify)
268+
return classify(jobs_to_classify, jobs_to_unclassify)

0 commit comments

Comments
 (0)