Skip to content

Commit 6eb81ec

Browse files
committed
WIP feat: add metrics_report
1 parent 11af2b3 commit 6eb81ec

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from datetime import datetime, timedelta
2+
import os
3+
import jinja2
4+
5+
6+
def generate_metrics_report():
7+
templates_dir = os.path.join(
8+
os.path.dirname(os.path.abspath(__file__)), "..", "templates"
9+
)
10+
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_dir))
11+
template = jinja_env.get_template("metrics_report.txt.j2")
12+
13+
mock_data = {
14+
"start_datetime": (datetime.now() - timedelta(days=7)).strftime(
15+
"%Y-%m-%d %H:%M"
16+
),
17+
"end_datetime": datetime.now().strftime("%Y-%m-%d %H:%M"),
18+
"new_issue_incidents": 5,
19+
"total_incidents": 30,
20+
"n_incidents": {
21+
"builds": 2,
22+
"boots": 5,
23+
"tests": 23,
24+
},
25+
"total_labs": 2,
26+
"lab_maps": {
27+
"lab1": {
28+
"builds": 5,
29+
"boots": 2,
30+
"tests": 0,
31+
},
32+
"lab2": {
33+
"builds": 0,
34+
"boots": 0,
35+
"tests": 10,
36+
},
37+
},
38+
"lab_origins": {
39+
"lab1": "origin1",
40+
"lab2": "origin2",
41+
},
42+
"n_checkouts": 12,
43+
"n_builds": 40,
44+
"n_tests": 6000,
45+
"n_issues": 53,
46+
}
47+
48+
print("-----")
49+
print(template.render(**mock_data))
50+
print("-----")
51+
52+
return

backend/kernelCI_app/management/commands/notifications.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
from kernelCI_app.management.commands.helpers.common import (
2323
get_default_tree_recipients,
2424
)
25+
26+
from kernelCI_app.management.commands.helpers.metrics_report import (
27+
generate_metrics_report,
28+
)
2529
from kernelCI_app.management.commands.helpers.summary import (
2630
SIGNUP_FOLDER,
2731
PossibleReportOptions,
@@ -890,6 +894,7 @@ def add_arguments(self, parser):
890894
"fake_report",
891895
"test_report",
892896
"hardware_summary",
897+
"metrics_summary",
893898
],
894899
help="""Action to perform: new_issues, issue_report, summary, fake_report,
895900
test_report, or hardware_summary""",
@@ -1055,3 +1060,6 @@ def handle(self, *args, **options):
10551060
email_args=email_args,
10561061
hardware_origins=hardware_origins,
10571062
)
1063+
1064+
case "metrics_summary":
1065+
generate_metrics_report()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends "base.txt" %}
2+
{% block header %}{% endblock %}
3+
{% block content -%}
4+
Hello,
5+
{# The default interval should be 1 week #}
6+
Metrics summary from {{ start_datetime }} to {{ end_datetime }}:
7+
8+
{# Count of incidents where the related issue had no prior incident #}
9+
{{ new_issue_incidents }} new regressions (issues that had their first incident in the given interval).
10+
11+
12+
{{ total_incidents }} total incidents in this interval, being:
13+
{{ n_incidents["builds"] }} build incidents
14+
{{ n_incidents["boots"] }} boot incidents
15+
{{ n_incidents["tests"] }} test incidents
16+
17+
18+
There were {{ total_labs }} labs registered and testing as follows:
19+
{% for lab_key, lab_values in lab_maps.items() %} {{ lab_key }} ({{ lab_origins[lab_key] }}) - {{ lab_values["builds"] }} builds, {{ lab_values["boots"] }} boots, {{ lab_values["tests"] }} tests;
20+
{% endfor %}
21+
{# Simple counter for each table #}
22+
In total, there were:
23+
{{ n_checkouts }} new checkouts
24+
{{ n_builds }} new builds
25+
{{ n_tests }} new tests
26+
{{ total_incidents }} new incidents
27+
{{ n_issues }} new issues
28+
29+
{%- endblock -%}

0 commit comments

Comments
 (0)