Skip to content

Commit 158ce66

Browse files
committed
WIP feat: add metrics_report
1 parent 8e6328c commit 158ce66

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from datetime import datetime, timedelta, timezone
2+
from kernelCI_app.management.commands.helpers.common import setup_jinja_template
3+
4+
5+
def generate_metrics_report() -> None:
6+
template = setup_jinja_template("metrics_report.txt.j2")
7+
8+
mock_data = {
9+
"start_datetime": (datetime.now(timezone.utc) - timedelta(days=7)).strftime(
10+
"%Y-%m-%d %H:%M %Z"
11+
),
12+
"end_datetime": datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M %Z"),
13+
"build_incidents_by_origin": {
14+
"origin1": {
15+
"total": 30,
16+
"new_regressions": 5,
17+
},
18+
"origin2": {
19+
"total": 500,
20+
"new_regressions": 253,
21+
},
22+
},
23+
"lab_maps": {
24+
"lab1": {
25+
"builds": 5,
26+
"boots": 2,
27+
"tests": 0,
28+
},
29+
"lab2": {
30+
"builds": 0,
31+
"boots": 4,
32+
"tests": 10,
33+
},
34+
},
35+
"lab_origins": {
36+
"lab1": "origin1",
37+
"lab2": "origin2",
38+
},
39+
"n_checkouts": 12,
40+
"n_builds": 40,
41+
"n_tests": 6000,
42+
"n_issues": 53,
43+
"n_incidents": 530,
44+
}
45+
46+
print(template.render(**mock_data))
47+
48+
return

backend/kernelCI_app/management/commands/notifications.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
get_default_tree_recipients,
2222
setup_jinja_template,
2323
)
24+
25+
from kernelCI_app.management.commands.helpers.metrics_report import (
26+
generate_metrics_report,
27+
)
2428
from kernelCI_app.management.commands.helpers.summary import (
2529
SIGNUP_FOLDER,
2630
PossibleReportOptions,
@@ -1050,3 +1054,6 @@ def handle(self, *args, **options):
10501054
email_args=email_args,
10511055
hardware_origins=hardware_origins,
10521056
)
1057+
1058+
case "metrics_summary":
1059+
generate_metrics_report()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{% extends "base.txt" %}
2+
{% block header %}{% endblock %}
3+
{% block content -%}
4+
KernelCI Metrics Summary
5+
========================
6+
Period: {{ start_datetime }} to {{ end_datetime }}
7+
8+
9+
ACTIVITY
10+
--------
11+
{{ "{:>6}".format(n_issues) }} issues
12+
{{ "{:>6}".format(n_incidents) }} incidents
13+
{{ "{:>6}".format(n_checkouts) }} checkouts
14+
{{ "{:>6}".format(n_builds) }} builds
15+
{{ "{:>6}".format(n_tests) }} tests
16+
17+
18+
REGRESSIONS
19+
-----------
20+
Incidents are occurrences of an issue.
21+
New regressions are the first incident of an issue.
22+
Only build issues considered.
23+
24+
Origin Total Incidents New Regressions
25+
──────────────────────────────────────────────
26+
{% for origin, data in build_incidents_by_origin.items() | sort -%}
27+
{{ "{:<12}".format(origin) -}}
28+
{{ "{:<19}".format(data.total) -}}
29+
{{ data.new_regressions }}
30+
{% endfor %}
31+
32+
LAB ACTIVITY
33+
------------
34+
There were {{ lab_maps | length }} labs registered. Incidents reported per lab:
35+
36+
Lab (Origin) Builds Boots Tests
37+
─────────────────────────────────────────────
38+
{% for lab_key, lab_values in lab_maps.items() | sort -%}
39+
{{ "{:<20}".format(lab_key + " (" + lab_origins[lab_key] + ")") -}}
40+
{{ "{:<10}".format(lab_values["builds"]) -}}
41+
{{ "{:<10}".format(lab_values["boots"]) -}}
42+
{{ lab_values["tests"] }}
43+
{% endfor -%}
44+
─────────────────────────────────────────────
45+
{{ "{:<20}".format("Total") -}}
46+
{{ "{:<10}".format(lab_maps.values() | map(attribute='builds') | sum) -}}
47+
{{ "{:<10}".format(lab_maps.values() | map(attribute='boots') | sum) -}}
48+
{{ lab_maps.values() | map(attribute='tests') | sum }}
49+
50+
{% endblock -%}

0 commit comments

Comments
 (0)