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

Subscribers

People subscribed via source and target branches

to all changes: