Skip to content

Commit 917fb5f

Browse files
committed
fix(metrics): stabilize query cache and add weekly warm cron
* Use fixed UTC date bounds for metrics intervals so cache keys stay stable across the week * Expose created_at on the API * Align the dashboard with the email window, and warm the cache after the Saturday metrics email. Closes #1940 Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi> fix: change seeds to include older timestamp Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent d5da7c4 commit 917fb5f

21 files changed

Lines changed: 334 additions & 161 deletions

File tree

backend/kernelCI/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def get_json_env_var(name, default):
227227
"--monitoring-id=delete_unused_hardware_status",
228228
],
229229
),
230+
(
231+
"10 0 * * 6",
232+
"kernelCI_app.queries.notifications.warm_metrics_cache",
233+
),
230234
(
231235
"0 0 * * 6",
232236
"django.core.management.call_command",

backend/kernelCI_app/constants/localization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ class DocStrings:
7171
)
7272
DEFAULT_INTERVAL_DESCRIPTION = "Interval in days for the listing"
7373
METRICS_START_DAYS_AGO_DESCRIPTION = (
74-
"Number of days ago that marks the start of the metrics interval"
74+
"Inclusive UTC day offset for the start of a [start, end) metrics interval"
7575
)
7676
METRICS_END_DAYS_AGO_DESCRIPTION = (
77-
"Number of days ago that marks the end of the metrics interval"
77+
"Exclusive UTC day offset for the end of a [start, end) metrics interval"
7878
)
7979
DEFAULT_LISTING_STARTING_DATE_DESCRIPTION = (
8080
"Starting date to calculate the search interval."

backend/kernelCI_app/management/commands/notifications.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import sys
33
from collections import defaultdict
4-
from datetime import datetime, timedelta, timezone
4+
from datetime import datetime, time, timedelta, timezone
55
from email.utils import make_msgid
66
from types import SimpleNamespace
77
from typing import Optional
@@ -38,6 +38,7 @@
3838
from kernelCI_app.queries.notifications import (
3939
get_checkout_summary_data,
4040
get_metrics_data,
41+
interval_params,
4142
kcidb_build_incidents,
4243
kcidb_issue_details,
4344
kcidb_last_build_without_issue,
@@ -847,8 +848,14 @@ def generate_metrics_report(
847848
return
848849

849850
now = datetime.now(timezone.utc)
850-
start_datetime = now - timedelta(days=start_days_ago)
851-
end_datetime = now - timedelta(days=end_days_ago)
851+
bounds = interval_params(start_days_ago, end_days_ago)
852+
start_datetime = datetime.fromisoformat(bounds["start_date"])
853+
exclusive_end = datetime.fromisoformat(bounds["end_date"])
854+
end_datetime = datetime.combine(
855+
exclusive_end.date() - timedelta(days=1),
856+
time.max,
857+
tzinfo=timezone.utc,
858+
)
852859

853860
data: MetricsReportData = get_metrics_data(
854861
start_days_ago=start_days_ago,

0 commit comments

Comments
 (0)