Merge ~andersson123/autopkgtest-cloud:fix-update-github-jobs into autopkgtest-cloud:master

Proposed by Tim Andersson
Status: Merged
Merged at revision: b8547f4cd2261af7be6a07e37381417dc38a0a8b
Proposed branch: ~andersson123/autopkgtest-cloud:fix-update-github-jobs
Merge into: autopkgtest-cloud:master
Diff against target: 76 lines (+25/-2)
2 files modified
charms/focal/autopkgtest-web/units/update-github-jobs.service (+1/-1)
charms/focal/autopkgtest-web/webcontrol/update-github-jobs (+24/-1)
Reviewer Review Type Date Requested Status
Skia Approve
Paride Legovini Approve
Review via email: mp+459166@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Andersson (andersson123) wrote :

Need to squash and clean up commits and also remove TimeoutStartSec from service file, include time diff in commit and run linting stuff

Revision history for this message
Tim Andersson (andersson123) wrote :

I’ve made some modifications to the script which are in the MP.

I fixed an issue I found before in a previous MP, incorrect urls getting passed to update-github-jobs, and I’ve made the script a bit faster too.

with my changes:

real 1m57.851s
user 0m51.147s
sys 0m2.708s

I was running the one in master, trying to get a total time, but I got bored after a while….

KeyboardInterrupt

real 115m0.538s
user 0m19.061s
sys 0m3.917s

….

lol

Revision history for this message
Skia (hyask) wrote :

I don't really know that code or its purpose, but I've put you an inline comment anyway.

Revision history for this message
Skia (hyask) :
review: Needs Fixing
Revision history for this message
Paride Legovini (paride) wrote :

Some inline questions / comments.

review: Needs Information
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Paride Legovini (paride) :
Revision history for this message
Paride Legovini (paride) :
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Paride Legovini (paride) :
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Paride Legovini (paride) wrote :

As discussed, the logic is OK, but let's implement the time difference check as Skia suggested.

We can't rely on the object metadata to get its timestamp, as we're accessing it using url calls, not swiftclient or similar.

It's still a bit a mystery why the structure of the answers changed as some point, so we need to change the URLs, but let's accept how things are (no need to dig).

On the timeout: let's run the script manually, check how long it takes, and set the timeout to a few times that time (we can be generous, it's mostly to avoid the "stuck forever" case).

Revision history for this message
Tim Andersson (andersson123) wrote :

Amended, please re-review! I'm just going to double check I haven't broken anything, but I doubt I have.

Revision history for this message
Tim Andersson (andersson123) wrote :

Doesn't look like my latest changes have caused any breaking, awesome

Revision history for this message
Tim Andersson (andersson123) wrote :

CI seems to be unhappy, looking...

Revision history for this message
Tim Andersson (andersson123) wrote :

ah, black error, fixing

Revision history for this message
Tim Andersson (andersson123) wrote :

Amended, please re-review

Revision history for this message
Paride Legovini (paride) wrote :

A couple of minor review comments, but looks good in general.

review: Needs Fixing
Revision history for this message
Tim Andersson (andersson123) wrote :

Preserving your comment here paride as I'm about to push:

>>> Should log something here about the job being skipped?

I originally did that in earlier versions of my changes, but so many jobs get skipped that the logs get spammed an insane amount, so I decided against it. Let me know if that's all good with you!

Revision history for this message
Tim Andersson (andersson123) wrote :

Amended, please re-review! :D

Revision history for this message
Paride Legovini (paride) wrote :

I suspected log spam could be an issue.

One last inline question...

review: Needs Information
Revision history for this message
Paride Legovini (paride) wrote :

CI passed, this LGTM, but please check my previous comment on the possible need for an abs() when computing the time difference. I don't think it's needed; if you agree go ahead and merge.

review: Approve
Revision history for this message
Tim Andersson (andersson123) wrote :

Amended, please re-review

Revision history for this message
Skia (hyask) :
Revision history for this message
Tim Andersson (andersson123) :
Revision history for this message
Tim Andersson (andersson123) wrote :

Amended, please re-review

Revision history for this message
Skia (hyask) wrote :

Great, thanks!

review: Approve
Revision history for this message
Tim Andersson (andersson123) wrote :

I'll wait for CI to pass (or tempfail) and then I'll merge this.

Revision history for this message
Tim Andersson (andersson123) wrote :

NOICE! a pass

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/units/update-github-jobs.service b/charms/focal/autopkgtest-web/units/update-github-jobs.service
2index a52bac5..bf71e43 100644
3--- a/charms/focal/autopkgtest-web/units/update-github-jobs.service
4+++ b/charms/focal/autopkgtest-web/units/update-github-jobs.service
5@@ -5,6 +5,6 @@ Description=Update GitHub job status
6 Type=oneshot
7 User=www-data
8 Group=www-data
9-TimeoutStartSec=1m
10+TimeoutStartSec=10m
11 EnvironmentFile=/etc/environment.d/*.conf
12 ExecStart=/home/ubuntu/webcontrol/update-github-jobs
13diff --git a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
14index 6362803..83ee598 100755
15--- a/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
16+++ b/charms/focal/autopkgtest-web/webcontrol/update-github-jobs
17@@ -1,6 +1,7 @@
18 #!/usr/bin/python3
19
20 import configparser
21+import datetime
22 import io
23 import json
24 import logging
25@@ -15,6 +16,7 @@ from urllib.error import HTTPError
26 from request.submit import Submit
27
28 PENDING_DIR = "/run/autopkgtest_webcontrol/github-pending"
29+MAX_DAYS_DIFF = 15
30 swift_url = None
31 external_url = None
32
33@@ -23,7 +25,7 @@ def result_matches_job(result_url, params):
34 # download result.tar and get exit code and testinfo
35 for _ in range(5):
36 try:
37- with urllib.request.urlopen(result_url + "/result.tar") as f:
38+ with urllib.request.urlopen(result_url) as f:
39 tar_bytes = io.BytesIO(f.read())
40 break
41 except IOError as e:
42@@ -96,6 +98,17 @@ def finish_job(jobfile, params, code, log_url):
43 os.unlink(jobfile)
44
45
46+def check_time_diff(object_time, job_time):
47+ splitted_url = object_time.split("/")
48+ # date and time of object embedded in swift object path
49+ timestamp = splitted_url[4]
50+ # last part of the timestamp is a storage ID which we don't need
51+ timestamp = "_".join(timestamp.split("_")[0:2])
52+ timestamp = datetime.datetime.strptime(timestamp, "%Y%m%d_%H%M%S")
53+ job_timestamp = datetime.datetime.fromtimestamp(job_time)
54+ return abs(timestamp - job_timestamp)
55+
56+
57 def process_job(jobfile):
58 try:
59 with open(jobfile) as f:
60@@ -137,6 +150,16 @@ def process_job(jobfile):
61 result_url = os.path.join(
62 container_url, result.strip().decode()
63 )
64+ # We don't want to check the urls that aren't for result.tar
65+ if "result.tar" not in result_url:
66+ continue
67+ # We check the swift object and the github jobfile has a time
68+ # difference of less than 15 days - otherwise we're checking
69+ # swift objects from years ago and this script is super slow.
70+ if check_time_diff(
71+ result.strip().decode(), mtime
72+ ) > datetime.timedelta(days=MAX_DAYS_DIFF):
73+ continue
74 logging.debug(
75 "checking result %s for job %s",
76 result_url,

Subscribers

People subscribed via source and target branches