Merge lp:~hloeung/ubuntu-repository-cache/health-check-user-agent-uid into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 339
Merged at revision: 337
Proposed branch: lp:~hloeung/ubuntu-repository-cache/health-check-user-agent-uid
Merge into: lp:ubuntu-repository-cache
Diff against target: 49 lines (+8/-4)
2 files modified
files/health_check.py (+7/-3)
lib/ubuntu_repository_cache/tests/test_metadata_sync.py (+1/-1)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/health-check-user-agent-uid
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+403842@code.launchpad.net

Commit message

Add unique ID in health check requests to easily tie in apache2 logs with health check logs

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Haw Loeung (hloeung) wrote :

ubuntu@machine-2:~$ grep raaQyfOa /var/log/ubuntu-repository-cache/health-check.log2021-06-08 01:13:16 127.0.0.1 [raaQyfOa]: OK: #1: /ubuntu/dists/focal/InRelease (0.004)
2021-06-08 01:13:16 127.0.0.1 [raaQyfOa]: OK: #1: /ubuntu/pool/main/ (0.028)
2021-06-08 01:13:16 127.0.0.1 [raaQyfOa]: 200 OK (0.032)

ubuntu@machine-2:~$ grep raaQyfOa /var/log/apache2/archive.ubuntu.com-access.log
127.0.0.1 - - [08/Jun/2021:01:13:16 +0000] "HEAD /ubuntu/dists/focal/InRelease HTTP/1.1" 200 349 "-" "ubuntu-repository-cache/healthcheck (raaQyfOa)"
127.0.0.1 - - [08/Jun/2021:01:13:16 +0000] "HEAD /ubuntu/pool/main/ HTTP/1.1" 200 293 "-" "ubuntu-repository-cache/healthcheck (raaQyfOa)"
ubuntu@machine-2:~$

338. By Haw Loeung

Fix unit test, fallout from r334

Revision history for this message
Paul Collins (pjdc) :
review: Needs Fixing
339. By Haw Loeung

Avoid modifying the global, so create a copy of it per review

Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 337

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'files/health_check.py'
2--- files/health_check.py 2021-05-20 01:51:42 +0000
3+++ files/health_check.py 2021-06-08 01:28:00 +0000
4@@ -63,7 +63,7 @@
5 pass
6
7
8-def check_url(url):
9+def check_url(url, headers=CHECK_HEADERS):
10 start_time = time.time()
11
12 count = 0
13@@ -75,7 +75,7 @@
14 msg = ''
15 try:
16 check_url = urljoin(CHECK_HOST, url)
17- resp = requests.head(check_url, headers=CHECK_HEADERS, timeout=CHECK_TIMEOUT)
18+ resp = requests.head(check_url, headers=headers, timeout=CHECK_TIMEOUT)
19 status_code = resp.status_code
20 if resp.ok:
21 duration = time.time() - start_time_url
22@@ -158,10 +158,14 @@
23
24 start_time = time.time()
25
26+ headers = CHECK_HEADERS.copy()
27+ # We want to include the unique ID in the User-Agent header to
28+ # easily match apache2 logs with the health-check logs.
29+ headers['User-agent'] = headers['User-agent'] + ' ({})'.format(uid)
30 successes = {}
31 failures = {}
32 for url in CHECK_URLS:
33- res = check_url(url)
34+ res = check_url(url, headers)
35 if res[0] == 200:
36 successes[url] = res
37 else:
38
39=== modified file 'lib/ubuntu_repository_cache/tests/test_metadata_sync.py'
40--- lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2020-10-13 04:08:14 +0000
41+++ lib/ubuntu_repository_cache/tests/test_metadata_sync.py 2021-06-08 01:28:00 +0000
42@@ -192,7 +192,7 @@
43 'ubuntu-repository-cache-sync some_meta_var',
44 ],
45 ),
46- {},
47+ {'stdout': -3},
48 ]
49 ]
50

Subscribers

People subscribed via source and target branches