Merge lp:~hloeung/ubuntu-repository-cache/health-check-logging-improvements into lp:ubuntu-repository-cache

Proposed by Haw Loeung
Status: Merged
Approved by: Colin Misare
Approved revision: 323
Merged at revision: 324
Proposed branch: lp:~hloeung/ubuntu-repository-cache/health-check-logging-improvements
Merge into: lp:ubuntu-repository-cache
Diff against target: 63 lines (+12/-5)
1 file modified
files/health_check.py (+12/-5)
To merge this branch: bzr merge lp:~hloeung/ubuntu-repository-cache/health-check-logging-improvements
Reviewer Review Type Date Requested Status
Colin Misare Approve
Canonical IS Reviewers Pending
Review via email: mp+399130@code.launchpad.net

Commit message

Log overrall check result and URLs for errors

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
Colin Misare (cmisare) wrote :

LGTM

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

Change successfully merged at revision 324

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-03-03 23:01:10 +0000
3+++ files/health_check.py 2021-03-03 23:09:02 +0000
4@@ -97,6 +97,8 @@
5 send_to_influx(render_influx(METRIC_NAME, 'status=DISABLED', 4.04))
6 return
7
8+ start_total = time.time()
9+
10 successes = {}
11 failures = {}
12 for url in CHECK_URLS:
13@@ -114,7 +116,7 @@
14 resp.raise_for_status()
15 except requests.exceptions.HTTPError as err:
16 duration = time.time() - start
17- logging.error('{} ({:.3f}s)'.format(err, duration))
18+ logging.error('ERROR: {}: {} ({:.3f}s)'.format(url, err, duration))
19 failures[url] = [status_code, duration, err]
20 except (
21 requests.exceptions.ConnectTimeout,
22@@ -122,18 +124,19 @@
23 requests.exceptions.Timeout,
24 ) as err:
25 duration = time.time() - start
26- logging.error('{} ({:.3f}s)'.format(err, duration))
27+ logging.error('ERROR: {}: {} ({:.3f}s)'.format(url, err, duration))
28 failures[url] = [0, duration, err]
29 except Exception as err:
30 duration = time.time() - start
31 # We don't want to show exactly what the error is, but we
32 # do want to log it.
33- logging.critical('{} ({:.3f}s)'.format(err, duration))
34+ logging.critical('ERROR: {}: {} ({:.3f}s)'.format(url, err, duration))
35 failures[url] = [0, duration, 'Unknown error']
36
37 metrics = []
38 if failures:
39- print('Status: 503 Service Unavailable')
40+ status = '503 Service Unavailable'
41+ print('Status: {}'.format(status))
42 print('Content-type: text/html\n')
43 for url, val in failures.items():
44 status_code = val[0]
45@@ -143,7 +146,8 @@
46 labels = 'url={},status=FAIL,status_code={}'.format(url, status_code)
47 metrics.append(render_influx(METRIC_NAME, labels, duration))
48 else:
49- print('Status: 200 OK')
50+ status = '200 OK'
51+ print('Status: {}'.format(status))
52 print('Content-type: text/html\n')
53
54 # Either way, output all successful checks.
55@@ -158,6 +162,9 @@
56 # request/connection on sending metrics to influx.
57 print('', flush=True)
58
59+ duration = time.time() - start_total
60+ logging.info('{} ({:.3f}s)'.format(status, duration))
61+
62 for metric in metrics:
63 send_to_influx(metric)
64

Subscribers

People subscribed via source and target branches