Skip to content

Commit cf4a9af

Browse files
committed
[CI][Benchmarks] Limit dashboard data growth
Load and parse results only up to the set number of days old which is three times the defined archiving times. Archived runs older than 3 times the specified days are not included in the dashboard, ie. when archiving data older than 7 days, runs older than 21 days are not included.
1 parent 8f06a1d commit cf4a9af

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

devops/scripts/benchmarks/history.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def load_result(self, file_path: Path) -> BenchmarkRun:
3131
else:
3232
return None
3333

34-
def load(self, n: int):
34+
def load(self):
35+
"""
36+
Load benchmark runs from the results directory.
37+
This method loads files after the specified archiving criteria,
38+
sorts them by timestamp, and stores the results in self.runs.
39+
"""
3540
results_dir = Path(self.dir) / "results"
3641
if not results_dir.exists() or not results_dir.is_dir():
3742
log.warning(
@@ -42,20 +47,52 @@ def load(self, n: int):
4247
# Get all JSON files in the results directory
4348
benchmark_files = list(results_dir.glob("*.json"))
4449

45-
# Extract timestamp and sort files by it
50+
# Extract timestamp
4651
def extract_timestamp(file_path: Path) -> str:
4752
try:
4853
# Assumes results are stored as <name>_YYYYMMDD_HHMMSS.json
4954
ts = file_path.stem[-len("YYYYMMDD_HHMMSS") :]
5055
return ts if Validate.timestamp(ts) else ""
5156
except IndexError:
5257
return ""
53-
58+
59+
baseline_drop_after = options.archive_baseline_days * 3
60+
pr_drop_after = options.archive_pr_days * 3
61+
baseline_cutoff_date = datetime.now(timezone.utc) - timedelta(days=baseline_drop_after)
62+
log.debug(f"Baseline cutoff date: {baseline_cutoff_date}")
63+
pr_cutoff_date = datetime.now(timezone.utc) - timedelta(days=pr_drop_after)
64+
log.debug(f"PR cutoff date: {pr_cutoff_date}")
65+
66+
# Filter out files that exceed archiving criteria three times the specified days
67+
def is_file_too_old(file_path: Path) -> bool:
68+
try:
69+
if file_path.stem.startswith("Baseline_"):
70+
cutoff_date = baseline_cutoff_date
71+
else:
72+
cutoff_date = pr_cutoff_date
73+
74+
timestamp_str = extract_timestamp(file_path)
75+
if not timestamp_str:
76+
return False
77+
78+
file_timestamp = datetime.strptime(timestamp_str, "%Y%m%d_%H%M%S")
79+
# Add timezone info for proper comparison
80+
file_timestamp = file_timestamp.replace(tzinfo=timezone.utc)
81+
return file_timestamp < cutoff_date
82+
except Exception as e:
83+
log.warning(f"Error processing timestamp for {file_path.name}: {e}")
84+
return False
85+
86+
benchmark_files = [
87+
file for file in benchmark_files if not is_file_too_old(file)
88+
]
89+
90+
# Sort files by timestamp
5491
benchmark_files.sort(key=extract_timestamp, reverse=True)
5592

56-
# Load the first n benchmark files
93+
# Load benchmark files
5794
benchmark_runs = []
58-
for file_path in benchmark_files[:n]:
95+
for file_path in benchmark_files:
5996
benchmark_run = self.load_result(file_path)
6097
if benchmark_run:
6198
benchmark_runs.append(benchmark_run)

devops/scripts/benchmarks/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def main(directory, additional_env_vars, save_name, compare_names, filter):
293293
# limit how many files we load.
294294
# should this be configurable?
295295
log.info(f"Loading benchmark history from {results_dir}...")
296-
history.load(1000)
296+
history.load()
297297
log.info(f"Loaded {len(history.runs)} benchmark runs.")
298298

299299
if compare_names:

devops/scripts/benchmarks/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class Options:
9090
git_commit_override: str = None
9191
# Archiving settings
9292
# Archived runs are stored separately from the main dataset but are still accessible
93-
# via the HTML UI when "Include archived runs" is enabled
93+
# via the HTML UI when "Include archived runs" is enabled.
94+
# Archived runs older than 3 times the specified days are not included in the dashboard,
95+
# ie. when archiving data older than 7 days, runs older than 21 days are not included.
9496
archive_baseline_days: int = 30 # Archive Baseline_* runs after 30 days
9597
archive_pr_days: int = 7 # Archive other (PR/dev) runs after 7 days
9698

0 commit comments

Comments
 (0)