Merge ~sajoupa/apt-stresstest-charm:logging into apt-stresstest-charm:master

Proposed by Laurent Sesquès
Status: Merged
Approved by: Haw Loeung
Approved revision: b06a8fa8c581b57f304ace2d80362359d182629b
Merged at revision: 1ef78810095364cba108403d2db4772e608be795
Proposed branch: ~sajoupa/apt-stresstest-charm:logging
Merge into: apt-stresstest-charm:master
Diff against target: 78 lines (+18/-0)
1 file modified
files/test_apt_mirrors.py (+18/-0)
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+391981@code.launchpad.net

Commit message

Add basic logging - no logrotate for now

To post a comment you must log in.
Revision history for this message
Laurent Sesquès (sajoupa) wrote :

This will allow logging but lacks log rotation. Submitting the MP to record that code which I successfully used to troubleshoot an issue, but setting it to WIP because we need log rotation before merging.

Revision history for this message
Benjamin Allot (ballot) wrote :

LGTM so far

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

We can add logrotation later, LGTM.

review: Approve (+1)
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

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

Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

Change successfully merged at revision 1ef78810095364cba108403d2db4772e608be795

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/files/test_apt_mirrors.py b/files/test_apt_mirrors.py
2index 75d14fe..0cc583a 100755
3--- a/files/test_apt_mirrors.py
4+++ b/files/test_apt_mirrors.py
5@@ -20,12 +20,22 @@
6 import argparse
7 import datetime
8 import glob
9+import logging
10 import os
11 import socket
12 import subprocess
13 import sys
14 from yaml import safe_load
15
16+LOGFILE = '/var/log/apt-stresstest.log'
17+
18+file_handler = logging.FileHandler(LOGFILE)
19+file_handler.setLevel(logging.INFO)
20+basic_formatter = logging.Formatter('%(asctime)s - %(message)s')
21+file_handler.setFormatter(basic_formatter)
22+log = logging.getLogger('apt-stresstest')
23+log.setLevel(logging.INFO)
24+log.addHandler(file_handler)
25
26 class Timer(object):
27 def __init__(self):
28@@ -170,17 +180,21 @@ def output_results(result, verbose=False, send_to=None):
29
30 def run_tests(domain, ip, packages, args):
31
32+ log.info("Running apt update 1 and sending to telegraf")
33 output_results(render_influx("update_1", domain, ip,
34 apt_update(ip, timeout=args.update_timeout)),
35 verbose=args.verbose, send_to=args.send_to)
36+ log.info("Running apt update 2 and sending to telegraf")
37 output_results(render_influx("update_2", domain, ip,
38 apt_update(ip, timeout=args.update_timeout)),
39 verbose=args.verbose, send_to=args.send_to)
40 for index, package in enumerate(packages):
41+ log.info("Performing cached download of {} - {} and sending to telegraf".format(1 + index, package))
42 test_name = "cached_download_{}_{}".format(1 + index, package)
43 output_results(render_influx(test_name, domain, ip,
44 apt_download(package, ip, timeout=args.download_timeout)),
45 verbose=args.verbose, send_to=args.send_to)
46+ log.info("Performing uncached download of {} - {} and sending to telegraf".format(1 + index, package))
47 test_name = "uncached_download_{}_{}".format(1 + index, package)
48 output_results(render_influx(test_name, domain, ip,
49 apt_download(package, ip, no_cache=True, timeout=args.download_timeout)),
50@@ -234,6 +248,7 @@ def write_apt_config(domain, ip, series=None):
51
52
53 def main():
54+ log.info("Beginning apt-stresstest run...")
55 timer = Timer()
56 timer.start()
57 args = parse_args()
58@@ -245,17 +260,20 @@ def main():
59
60 for ip in ips:
61 write_apt_config(domain, ip, args.series)
62+ log.info("apt config written for {} - {}. Running tests now.".format(domain, ip))
63 run_tests(
64 domain=domain,
65 ip=ip,
66 packages=args.package.split(','),
67 args=args,
68 )
69+ log.info("Tests done, stopping timer.")
70 timer.stop()
71 output_results(render_influx("N/A", "N/A", "N/A", timer.time, "apt_transaction_total_duration_seconds"),
72 verbose=args.verbose, send_to=args.send_to)
73 output_results(render_influx("N/A", "N/A", "N/A", len(ips), "apt_mirror_units_count"),
74 verbose=args.verbose, send_to=args.send_to)
75+ log.info("Pushed global timer and units count to telegraf.")
76
77
78 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches