Skip to content

Commit b62e8f9

Browse files
committed
Add post log parser to look for repeated test runs and annotate as intermittent.
1 parent a0ec076 commit b62e8f9

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from treeherder.model.models import Group, GroupStatus, Job
2+
3+
def check_and_mark_intermittent(job_id):
4+
current_job = Job.objects.get(id=job_id)
5+
6+
if current_job.job_type.name.endswith("-cf"):
7+
jtname = [current_job.job_type.name, current_job.job_type.name.strip("-cf")]
8+
else:
9+
jtname = [current_job.job_type.name, f"{current_job.job_type.name}-cf"]
10+
11+
all_groups = Group.objects.filter(
12+
job_logs__job__push__id=current_job.push.id,
13+
job_logs__job__job_type__name__in=jtname,
14+
group_result__status__in=[GroupStatus.OK, GroupStatus.ERROR],
15+
).values(
16+
"name",
17+
"job_logs__job__id",
18+
"group_result__status",
19+
)
20+
21+
groups = {}
22+
jobs = {}
23+
for item in all_groups:
24+
if item["name"] not in groups:
25+
groups[item["name"]] = {}
26+
if item["job_logs__job__id"] not in groups[item["name"]]:
27+
groups[item["name"]][item["job_logs__job__id"]] = item["group_result__status"]
28+
29+
if item["job_logs__job__id"] not in jobs:
30+
jobs[item["job_logs__job__id"]] = {}
31+
if item["name"] not in jobs[item["job_logs__job__id"]]:
32+
jobs[item["job_logs__job__id"]][item["name"]] = item["group_result__status"]
33+
34+
if len(jobs.keys()) <= 1:
35+
# zero jobs == no groups reported (i.e. marionette)
36+
# 1 job == no additional data
37+
return
38+
39+
for job in jobs.keys():
40+
# for each similar task.label, ensure all groups have >=50% pass rate, if so flag failing
41+
# job as intermittent. for non test failures, ensure all groups are green
42+
all_green = True
43+
failed_groups = [g for g in jobs[job] if int(jobs[job][g]) == GroupStatus.ERROR]
44+
for group in failed_groups:
45+
all_status = [groups[group][j] for j in groups[group]]
46+
pass_rate = len([s for s in all_status if s == GroupStatus.OK]) / len(all_status)
47+
if pass_rate < 0.5:
48+
all_green = False
49+
break
50+
51+
target_job = Job.objects.filter(id=job)
52+
53+
if all_green and target_job[0].result != "success":
54+
target_job.update(failure_classification_id=4)

treeherder/log_parser/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from treeherder.workers.task import retryable_task
1515

1616
from . import failureline
17+
from . import intermittents
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -81,7 +82,8 @@ def store_failure_lines(job_log):
8182
errorsummary file."""
8283
logger.info("Running store_failure_lines for job %s", job_log.job.id)
8384
failureline.store_failure_lines(job_log)
84-
85+
logger.info("Running check_and_mark_intermittent for job %s", job_log.job.id)
86+
intermittents.check_and_mark_intermittent(job_log.job.id)
8587

8688
def post_log_artifacts(job_log):
8789
"""Post a list of artifacts to a job."""

0 commit comments

Comments
 (0)