Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion result_server/tests/test_results_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_existing_columns_unchanged(self, flask_app, tmp_dir):
{"label": "FOM", "key": "fom", "tooltip": "Figure of Merit - Benchmark performance metric value with its unit when available"},
{"label": "FOM version", "key": "fom_version", "tooltip": "Version identifier for the FOM measurement section - helps identify which code region was measured when users modify the timing boundaries"},
{"label": "SYSTEM", "key": "system", "tooltip": "Computing system name"},
{"label": "Activity", "key": "activity_context", "tooltip": "Public activity or budget allocation context recorded with the benchmark run"},
{"label": "Activity / Allocation", "key": "activity_context", "tooltip": "Public activity or budget allocation context recorded with the benchmark run"},
{"label": "Nodes", "key": "nodes"},
{"label": "P/N", "key": "numproc_node", "tooltip": "Number of processes per node"},
{"label": "T/P", "key": "nthreads", "tooltip": "Number of threads per process"},
Expand Down Expand Up @@ -397,6 +397,36 @@ def test_activity_context_falls_back_to_trigger_run_variables(self, flask_app, t
assert row["activity_context"]["headline"] == "ActivityAlpha"
assert row["activity_context"]["subline"] == "allocation project00020"

def test_activity_context_falls_back_to_portal_profile_context(self, flask_app, tmp_dir):
uid = str(uuid.uuid4())
filename = f"result_20250101_120000_{uid}.json"
_write_json(tmp_dir, filename, {
"code": "demoapp",
"system": "DemoSystem",
"FOM": 1.0,
"pipeline_id": "12345",
})
trigger_runs_by_pipeline = {
"12345": {
"payload_json": {
"activity": "ActivityBeta",
"allocation_project_id": "project00030",
"payload": {"variables": {}},
}
}
}

with flask_app.test_request_context():
row = build_result_table_row(
filename,
load_result_json(filename, tmp_dir),
[],
trigger_runs_by_pipeline,
)

assert row["activity_context"]["headline"] == "ActivityBeta"
assert row["activity_context"]["subline"] == "allocation project00030"

def test_profile_summary_is_built_from_profile_data(self, flask_app, tmp_dir):
uid = str(uuid.uuid4())
_write_json(tmp_dir, f"result_20250101_120000_{uid}.json", {
Expand Down
30 changes: 30 additions & 0 deletions result_server/tests/test_trigger_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,36 @@ def test_summarize_trigger_run_extracts_payload_context():
assert summary["reason_label"] == "cron 0 14 * * * / 2026-08-07T14:00+09:00"


def test_summarize_trigger_run_uses_profile_context_snapshot():
run = {
"id": 4,
"trigger_id": "demoapp-demosystem-1400",
"trigger_type": "scheduled",
"status": "submitted",
"dry_run": False,
"reason": "cron:0 14 * * *@2026-08-07T14:00+09:00",
"payload_json": {
"activity": "ActivityBeta",
"allocation_project_id": "project00030",
"payload": {
"ref": "develop",
"variables": {
"code": "demoapp",
"system": "DemoSystem",
},
},
},
"errors": [],
"actor": "trigger_runner",
"created_at": "2026-08-07T05:00:00Z",
}

summary = summarize_trigger_run(run)

assert summary["activity"] == "ActivityBeta"
assert summary["allocation_project_id"] == "project00030"


def test_build_trigger_result_links_matches_direct_trigger_metadata(tmp_path):
result_file = tmp_path / "result_20260807_140000_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee.json"
result_file.write_text(
Expand Down
2 changes: 2 additions & 0 deletions result_server/trigger_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def _build_trigger_plan(
"api_url": plan.api_url,
"gitlab_target": gitlab_target.id if gitlab_target else trigger.get("gitlab_target", ""),
"gitlab_project": gitlab_target.repo if gitlab_target else "",
"activity": str(profile.get("activity", "")) if profile else "",
"allocation_project_id": profile_result.allocation_project_id,
"payload": plan_payload,
}
errors = list(profile_result.errors) + target_errors + plan.errors
Expand Down
19 changes: 12 additions & 7 deletions result_server/utils/result_table_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ def _build_activity_context(result_data, trigger_runs_by_pipeline=None):
if (not activity or not allocation_project_id) and trigger_runs_by_pipeline:
for pipeline_id in _result_pipeline_ids(result_data):
run = trigger_runs_by_pipeline.get(pipeline_id)
variables = _trigger_run_variables(run)
variables = _trigger_run_activity_context(run)
if not activity:
activity = variables.get("BK_EXECUTION_ACTIVITY", "")
activity = variables.get("activity", "")
if not allocation_project_id:
allocation_project_id = variables.get("BK_ALLOCATION_PROJECT_ID", "")
allocation_project_id = variables.get("allocation_project_id", "")
if activity and allocation_project_id:
break

Expand Down Expand Up @@ -178,16 +178,21 @@ def _extract_result_allocation_project_id(result_data):
)


def _trigger_run_variables(run):
def _trigger_run_activity_context(run):
if not isinstance(run, dict):
return {}
payload = run.get("payload_json") if isinstance(run.get("payload_json"), dict) else {}
plan_payload = payload.get("payload") if isinstance(payload.get("payload"), dict) else {}
variables = plan_payload.get("variables") if isinstance(plan_payload.get("variables"), dict) else {}
return {
str(key): str(value).strip()
for key, value in variables.items()
if value not in (None, "")
"activity": _first_text(
variables.get("BK_EXECUTION_ACTIVITY"),
payload.get("activity"),
),
"allocation_project_id": _first_text(
variables.get("BK_ALLOCATION_PROJECT_ID"),
payload.get("allocation_project_id"),
),
}


Expand Down
2 changes: 1 addition & 1 deletion result_server/utils/results_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{"label": "FOM", "key": "fom", "tooltip": "Figure of Merit - Benchmark performance metric value with its unit when available"},
{"label": "FOM version", "key": "fom_version", "tooltip": "Version identifier for the FOM measurement section - helps identify which code region was measured when users modify the timing boundaries"},
{"label": "SYSTEM", "key": "system", "tooltip": "Computing system name"},
{"label": "Activity", "key": "activity_context", "tooltip": "Public activity or budget allocation context recorded with the benchmark run"},
{"label": "Activity / Allocation", "key": "activity_context", "tooltip": "Public activity or budget allocation context recorded with the benchmark run"},
{"label": "Nodes", "key": "nodes"},
{"label": "P/N", "key": "numproc_node", "tooltip": "Number of processes per node"},
{"label": "T/P", "key": "nthreads", "tooltip": "Number of threads per process"},
Expand Down
4 changes: 2 additions & 2 deletions result_server/utils/trigger_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def summarize_trigger_run(run: dict[str, Any]) -> dict[str, Any]:
"target_ref": plan_payload.get("ref") or "-",
"code": variables.get("code") or "-",
"system": variables.get("system") or "-",
"activity": variables.get("BK_EXECUTION_ACTIVITY") or "-",
"allocation_project_id": variables.get("BK_ALLOCATION_PROJECT_ID") or "-",
"activity": variables.get("BK_EXECUTION_ACTIVITY") or payload.get("activity") or "-",
"allocation_project_id": variables.get("BK_ALLOCATION_PROJECT_ID") or payload.get("allocation_project_id") or "-",
"result_server": variables.get("RESULT_SERVER") or "-",
"pipeline_id": _trigger_run_pipeline_ids(run)[0] if _trigger_run_pipeline_ids(run) else "-",
"errors": errors,
Expand Down
Loading