Merge ~andersson123/qa-jenkins-jobs:daily_image_kpi into qa-jenkins-jobs:master

Proposed by Tim Andersson
Status: Needs review
Proposed branch: ~andersson123/qa-jenkins-jobs:daily_image_kpi
Merge into: qa-jenkins-jobs:master
Diff against target: 102 lines (+89/-0)
2 files modified
jobs/daily_image_age/jobs.yaml (+40/-0)
scripts/daily_image_age/daily_image_age_metrics (+49/-0)
Reviewer Review Type Date Requested Status
Brian Murray Pending
Review via email: mp+447193@code.launchpad.net
To post a comment you must log in.
80dbcf8... by Tim Andersson

idk

Unmerged commits

80dbcf8... by Tim Andersson

idk

f6d8ff6... by Tim Andersson

feat: Add script and job for gathering metrics on daily image age

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jobs/daily_image_age/jobs.yaml b/jobs/daily_image_age/jobs.yaml
2new file mode 100644
3index 0000000..8983e50
4--- /dev/null
5+++ b/jobs/daily_image_age/jobs.yaml
6@@ -0,0 +1,40 @@
7+# vim: sw=4 ts=4 et
8+
9+# QA Jenkins Jobs
10+# Copyright 2016 Canonical Ltd.
11+
12+# This program is free software: you can redistribute it and/or modify it
13+# under the terms of the GNU General Public License version 3, as published
14+# by the Free Software Foundation.
15+
16+# This program is distributed in the hope that it will be useful, but
17+# WITHOUT ANY WARRANTY; without even the implied warranties of
18+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
19+# PURPOSE. See the GNU General Public License for more details.
20+
21+# You should have received a copy of the GNU General Public License along
22+# with this program. If not, see <http://www.gnu.org/licenses/>.
23+
24+- job:
25+ name: daily-image-kpi-metric-gatherer
26+ description: |
27+ Runs a script hourly which checks the age of all the daily images
28+ at cdimage.ubuntu.com and exposes this data to grafana for a
29+ KPI board.
30+ node: 'venonat'
31+ triggers:
32+ - timed: '@hourly'
33+ builders:
34+ - clear-artifacts:
35+ - shell: |
36+ #!/bin/bash
37+ set -ex
38+ export http_proxy="http://squid.internal:3128"
39+ export https_proxy="http://squid.internal:3128"
40+ export no_proxy=launchpad.net
41+
42+ # Perhaps there should be a mechanism which makes sure only venonat can trigger this
43+ # I guess it's part of grafana?
44+ git clone https://git.launchpad.net/qa-jenkins-jobs
45+ cd qa-jenkins-jobs
46+ ./scripts/daily_image_age/daily_image_age_metrics
47\ No newline at end of file
48diff --git a/scripts/daily_image_age/daily_image_age_metrics b/scripts/daily_image_age/daily_image_age_metrics
49new file mode 100755
50index 0000000..be2defa
51--- /dev/null
52+++ b/scripts/daily_image_age/daily_image_age_metrics
53@@ -0,0 +1,49 @@
54+#!/usr/bin/python3
55+
56+import requests
57+import datetime
58+import time
59+import json
60+
61+CD_IMAGE_URL = "https://cdimage.ubuntu.com/"
62+
63+dirs = [
64+ ["daily-canary"],
65+ ["daily-legacy"],
66+ ["daily-live"],
67+ ["daily-preinstalled"],
68+ ["edubuntu", "daily-live"],
69+ ["kubuntu", "daily-live"],
70+ ["lubuntu", "daily-live"],
71+ ["ubuntu-mate", "daily-live"],
72+ ["ubuntu-unity", "daily-live"],
73+ ["ubuntucinnamon", "daily-live"],
74+ ["xubuntu", "daily-live"]
75+]
76+
77+seconds_in_day = 86400
78+ages = {}
79+
80+for d in dirs:
81+ url = CD_IMAGE_URL + "/".join(d) + "/"
82+ ages["/".join(d)] = {}
83+ index_html = requests.get(url).content.decode("utf-8").splitlines()
84+ contents = ""
85+ for l in index_html:
86+ if '''<img src="/icons/folder.gif" alt="[DIR]"> <a href="current/">current/</a>''' in l:
87+ contents = l
88+ epoch_time_of_image = contents[contents.find("</a>")+4:]
89+ ep = epoch_time_of_image.split(" ")
90+ date_of_iso = [int(i) for i in ep[16].split("-")]
91+ time_of_iso = [int(i) for i in ep[17].split(":")]
92+ epoch_time_of_image = datetime.datetime(date_of_iso[0],
93+ date_of_iso[1],
94+ date_of_iso[2],
95+ time_of_iso[0],
96+ time_of_iso[1]).timestamp()
97+ age_in_days = (time.time() - epoch_time_of_image) / seconds_in_day
98+ ages["/".join(d)]["up-to-date"] = (age_in_days < 1)
99+ ages["/".join(d)]["age"] = age_in_days
100+
101+print(json.dumps(ages, indent=4))
102+# need to now expose this data to grafana

Subscribers

People subscribed via source and target branches

to all changes: