Skip to content

Commit 9bcd6a4

Browse files
committed
Record all calls to retry to track spurious failures
1 parent dfe4508 commit 9bcd6a4

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

cfg.sample.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Priority values above max_priority will be refused.
22
max_priority = 9001
33

4+
# How long to keep the retry log
5+
# Should be a negative interval of time recognized by SQLite3.
6+
retry_log_expire = '-42 days'
7+
48
[github]
59

610
# Information for securely interacting with GitHub. These are found/generated

homu/html/queue.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h1>Homu queue - {% if repo_url %}<a href="{{repo_url}}" target="_blank">{{repo_
116116
</tbody>
117117
</table>
118118

119+
<p><a href="../retry_log/{{repo_label}}">Open retry log</a></p>
120+
119121
<script src="../assets/jquery.min.js"></script>
120122
<script src="../assets/jquery.dataTables.min.js"></script>
121123

homu/html/retry_log.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Homu retry log {{repo_label}}</title>
6+
<style>
7+
* { font-family: sans-serif; }
8+
h1 { font-size: 20px; }
9+
h2 { font-size: 16px; }
10+
p { font-size: 15px; }
11+
pre { margin: 0; }
12+
13+
table { border-collapse: collapse; }
14+
td, th { border: 2px solid white; padding: 5px; font-size: 13px; vertical-align: top; }
15+
tr:nth-child(even) { background: #ddd; }
16+
</style>
17+
</head>
18+
<body>
19+
<h1>Homu retry log - <a href="{{repo_url}}" target="_blank">{{repo_label}}</a></h1>
20+
21+
<table id="results">
22+
<thead>
23+
<tr>
24+
<th>Time (UTC)</th>
25+
<th>PR</th>
26+
<th>Message</th>
27+
</tr>
28+
</thead>
29+
30+
<tbody>
31+
{% for log in logs %}
32+
<tr>
33+
<td>{{log.time}}</td>
34+
<td><a href="{{log.src}}">{{log.num}}</a></td>
35+
<td><pre>{{log.msg}}</pre></td>
36+
</tr>
37+
{% endfor %}
38+
</tbody>
39+
</table>
40+
41+
</body>
42+
</html>

homu/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ def timed_out(self):
382382
self.add_comment(comments.TimedOut())
383383
self.change_labels(LabelEvent.TIMED_OUT)
384384

385+
def record_retry_log(self, src, body):
386+
# destroy ancient records
387+
db_query(
388+
self.db,
389+
"DELETE FROM retry_log WHERE repo = ? AND time < date('now', ?)",
390+
[self.repo_label, global_cfg.get('retry_log_expire', '-42 days')],
391+
)
392+
db_query(
393+
self.db,
394+
'INSERT INTO retry_log (repo, num, src, msg) VALUES (?, ?, ?, ?)',
395+
[self.repo_label, self.num, src, body],
396+
)
385397

386398
def sha_cmp(short, full):
387399
return len(short) >= 4 and short == full[:len(short)]
@@ -625,6 +637,7 @@ def parse_commands(body, username, repo_label, repo_cfg, state, my_username,
625637
state.set_status('')
626638
if realtime:
627639
event = LabelEvent.TRY if state.try_ else LabelEvent.APPROVED
640+
state.record_retry_log(command_src, body)
628641
state.change_labels(event)
629642

630643
elif word in ['try', 'try-'] and realtime:
@@ -1641,6 +1654,17 @@ def main():
16411654
UNIQUE (repo)
16421655
)''')
16431656

1657+
db_query(db, '''CREATE TABLE IF NOT EXISTS retry_log (
1658+
repo TEXT NOT NULL,
1659+
num INTEGER NOT NULL,
1660+
time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
1661+
src TEXT NOT NULL,
1662+
msg TEXT NOT NULL
1663+
)''')
1664+
db_query(db, '''
1665+
CREATE INDEX IF NOT EXISTS retry_log_time_index ON retry_log (repo, time DESC)
1666+
''')
1667+
16441668
# manual DB migration :/
16451669
try:
16461670
db_query(db, 'SELECT treeclosed_src FROM repos LIMIT 0')

homu/server.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,33 @@ def queue(repo_label):
179179
multiple=multiple,
180180
)
181181

182+
@get('/retry_log/<repo_label:path>')
183+
def retry_log(repo_label):
184+
logger = g.logger.getChild('retry_log')
185+
186+
lazy_debug(logger, lambda: 'repo_label: {}'.format(repo_label))
187+
188+
repo_url = 'https://github.com/{}/{}'.format(
189+
g.cfg['repo'][repo_label]['owner'],
190+
g.cfg['repo'][repo_label]['name'],
191+
)
192+
193+
db_query(
194+
g.db,
195+
'SELECT num, time, src, msg FROM retry_log WHERE repo = ? ORDER BY time DESC',
196+
[repo_label],
197+
)
198+
logs = [
199+
{'num': num, 'time': time, 'src': src, 'msg': msg}
200+
for num, time, src, msg in g.db.fetchall()
201+
]
202+
203+
return g.tpls['retry_log'].render(
204+
repo_url=repo_url,
205+
repo_label=repo_label,
206+
logs=logs,
207+
)
208+
182209

183210
@get('/callback')
184211
def callback():
@@ -903,6 +930,7 @@ def start(cfg, states, queue_handler, repo_cfgs, repos, logger,
903930
tpls['index'] = env.get_template('index.html')
904931
tpls['queue'] = env.get_template('queue.html')
905932
tpls['build_res'] = env.get_template('build_res.html')
933+
tpls['retry_log'] = env.get_template('retry_log.html')
906934

907935
g.cfg = cfg
908936
g.states = states

0 commit comments

Comments
 (0)