-
Notifications
You must be signed in to change notification settings - Fork 0
feat(perf): versioned report envelope around the baseline aggregation (#951 increment 4) #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
1
commit into
feat/perf-baseline-stats-20260901
Choose a base branch
from
feat/perf-baseline-report-envelope-20260902
base: feat/perf-baseline-stats-20260901
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """Versioned report envelope for the measured baseline (issue #951). | ||
|
|
||
| :mod:`app.perf.baseline_stats` produces the per-path distribution summary | ||
| from repeated baseline runs. This module wraps that raw statistics block in | ||
| a buyer-facing envelope: a stable schema fingerprint of the workload it | ||
| measured, a generation timestamp, a contract version, and a plain-language | ||
| summary an engineer can read without opening the JSON. | ||
|
|
||
| The envelope is additive -- the full :func:`aggregate_baseline` output is | ||
| preserved verbatim under ``statistics`` -- so a downstream consumer can | ||
| ignore the envelope entirely. | ||
|
|
||
| Like everything under :mod:`app.perf`, this records observations only. It | ||
| carries **no latency, throughput, or memory threshold** and makes no | ||
| pass/fail judgement; capacity targets are set from measured baseline runs | ||
| and never invented here. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| import json | ||
| from datetime import datetime, timezone | ||
| from typing import Any | ||
|
|
||
| from app.perf.baseline_stats import aggregate_baseline | ||
| from app.perf.workload_profiles import generate_workload_snapshot | ||
|
|
||
| #: Report envelope contract version. Distinct from the statistics block's own | ||
| #: fields; bump when the envelope shape changes. | ||
| REPORT_VERSION = "1" | ||
|
|
||
|
|
||
| def _schema_fingerprint(snapshot: dict[str, Any] | None) -> str: | ||
| """Return a stable ``"sha256:"``-prefixed fingerprint of a snapshot. | ||
|
|
||
| The snapshot is serialized with sorted keys and a string fallback for | ||
| non-JSON values, so the same schema always yields the same fingerprint | ||
| regardless of dict ordering. This matches | ||
| ``app.spec.normalization_report.schema_fingerprint``; the two should be | ||
| unified into one shared helper once both land on ``main``. | ||
| """ | ||
| canonical = json.dumps( | ||
| snapshot or {}, sort_keys=True, default=str, separators=(",", ":") | ||
| ) | ||
| return "sha256:" + hashlib.sha256(canonical.encode("utf-8")).hexdigest() | ||
|
|
||
|
|
||
| def _summarize(statistics: dict[str, Any]) -> dict[str, Any]: | ||
| """Build the plain-language summary block from an ``aggregate_baseline`` result. | ||
|
|
||
| Picks the path with the largest 95th-percentile wall time as the one an | ||
| engineer should look at first. Reports names and counts only -- never a | ||
| duration value, so the summary carries no implied threshold. | ||
| """ | ||
| paths: dict[str, Any] = statistics.get("paths", {}) | ||
| path_names = sorted(paths) | ||
| if path_names: | ||
| slowest = max( | ||
| path_names, key=lambda name: paths[name]["wall_seconds"]["p95"] | ||
| ) | ||
| else: | ||
| slowest = "" | ||
|
|
||
| profile = statistics.get("profile", "?") | ||
| repeat = statistics.get("repeat", 0) | ||
| if not path_names: | ||
| headline = f"{profile} profile: no measured paths." | ||
| else: | ||
| headline = ( | ||
| f"{profile} profile, {len(path_names)} measured paths over " | ||
| f"{repeat} run(s); slowest by wall-time 95th percentile is " | ||
| f"{slowest}." | ||
| ) | ||
| return { | ||
| "headline": headline, | ||
| "path_count": len(path_names), | ||
| "slowest_path_by_wall_p95": slowest, | ||
| } | ||
|
|
||
|
|
||
| def build_baseline_report( | ||
| profile_name: str, *, repeat: int, seed: int | None = None | ||
| ) -> dict[str, Any]: | ||
| """Run the repeat-baseline aggregation and wrap it in a versioned envelope. | ||
|
|
||
| Args: | ||
| profile_name: One of | ||
| :func:`app.perf.workload_profiles.list_profiles`. | ||
| repeat: Number of baseline runs to aggregate (forwarded to | ||
| :func:`app.perf.baseline_stats.aggregate_baseline`; must be >= 1). | ||
| seed: Optional PRNG seed forwarded to both the aggregation and the | ||
| fingerprinted workload snapshot, so the fingerprint identifies | ||
| exactly the schema that was measured. | ||
|
|
||
| Returns: | ||
| A dict with: | ||
|
|
||
| ``report_version`` | ||
| :data:`REPORT_VERSION`. | ||
| ``generated_at`` | ||
| UTC ISO-8601 timestamp of this envelope. | ||
| ``schema_fingerprint`` | ||
| ``"sha256:"``-prefixed fingerprint of the generated workload | ||
| snapshot that was measured. | ||
| ``summary`` | ||
| ``{headline, path_count, slowest_path_by_wall_p95}`` -- names and | ||
| counts only, no duration values. | ||
| ``statistics`` | ||
| The full :func:`aggregate_baseline` output, unmodified. | ||
|
|
||
| The report contains only observations; it has no thresholds and no | ||
| verdict. | ||
|
|
||
| Raises: | ||
| ValueError: Propagated from :func:`aggregate_baseline` if ``repeat`` | ||
| is less than 1. | ||
| KeyError: If ``profile_name`` is not a known profile. | ||
| """ | ||
| statistics = aggregate_baseline(profile_name, repeat=repeat, seed=seed) | ||
| snapshot = generate_workload_snapshot(profile_name, seed=seed) | ||
| return { | ||
| "report_version": REPORT_VERSION, | ||
| "generated_at": datetime.now(timezone.utc).isoformat(), | ||
| "schema_fingerprint": _schema_fingerprint(snapshot), | ||
| "summary": _summarize(statistics), | ||
| "statistics": statistics, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Tests for :mod:`app.perf.baseline_report`. | ||
|
|
||
| The envelope must wrap the raw statistics additively, fingerprint the exact | ||
| workload it measured, pick a real slowest path, stay deterministic under a | ||
| fixed seed, and carry no invented performance threshold. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from app.perf.baseline_report import REPORT_VERSION, build_baseline_report | ||
|
|
||
| _EXPECTED_PATHS = { | ||
| "canonical_hash", | ||
| "json_round_trip", | ||
| "schema_self_diff", | ||
| "ddl_export_postgresql", | ||
| "ddl_export_snowflake", | ||
| "data_dictionary_markdown", | ||
| } | ||
|
|
||
|
|
||
| def test_report_has_the_full_envelope_and_preserves_statistics() -> None: | ||
| report = build_baseline_report("small", repeat=2) | ||
| assert report["report_version"] == REPORT_VERSION | ||
| assert set(report) == { | ||
| "report_version", | ||
| "generated_at", | ||
| "schema_fingerprint", | ||
| "summary", | ||
| "statistics", | ||
| } | ||
| assert set(report["statistics"]["paths"]) == _EXPECTED_PATHS | ||
| assert report["statistics"]["repeat"] == 2 | ||
|
|
||
|
|
||
| def test_schema_fingerprint_is_sha256_prefixed_and_seed_stable() -> None: | ||
| a = build_baseline_report("small", repeat=1, seed=11) | ||
| b = build_baseline_report("small", repeat=1, seed=11) | ||
| assert a["schema_fingerprint"].startswith("sha256:") | ||
| assert a["schema_fingerprint"] == b["schema_fingerprint"] | ||
|
|
||
|
|
||
| def test_different_seeds_fingerprint_differently() -> None: | ||
| a = build_baseline_report("small", repeat=1, seed=1) | ||
| b = build_baseline_report("small", repeat=1, seed=2) | ||
| assert a["schema_fingerprint"] != b["schema_fingerprint"] | ||
|
|
||
|
|
||
| def test_summary_names_a_real_slowest_path() -> None: | ||
| report = build_baseline_report("small", repeat=2) | ||
| summary = report["summary"] | ||
| assert summary["path_count"] == 6 | ||
| assert summary["slowest_path_by_wall_p95"] in _EXPECTED_PATHS | ||
| assert "small" in summary["headline"] | ||
|
|
||
|
|
||
| def test_generated_at_is_timezone_aware() -> None: | ||
| report = build_baseline_report("small", repeat=1) | ||
| assert datetime.fromisoformat(report["generated_at"]).tzinfo is not None | ||
|
|
||
|
|
||
| def test_repeat_below_one_propagates_value_error() -> None: | ||
| with pytest.raises(ValueError): | ||
| build_baseline_report("small", repeat=0) | ||
|
|
||
|
|
||
| def test_unknown_profile_raises_key_error() -> None: | ||
| with pytest.raises(KeyError): | ||
| build_baseline_report("enterprise", repeat=1) | ||
|
|
||
|
|
||
| def test_module_states_targets_are_measured_and_invents_no_threshold() -> None: | ||
| raw = Path("app/perf/baseline_report.py").read_text(encoding="utf-8").lower() | ||
| prose = re.sub(r"\s+", " ", raw) | ||
| assert "measured baseline runs and never invented" in prose | ||
| assert "no latency, throughput, or memory threshold" in prose | ||
| assert "makes no pass/fail judgement" in prose | ||
| assert re.search(r"\b\d+(\.\d+)?\s*(ms|milliseconds|seconds)\b", raw) is None | ||
| assert re.search(r"p9[59]\s*[<>=:]", raw) is None | ||
| assert re.search(r"\b\d+\s*(rps|qps|req/s)\b", raw) is None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Research grounding remains incomplete
This substantive performance increment adds no redistributable paper, linked citation, or research summary. The repository’s research-grounding requirement needs follow-up.
Was this helpful? React with 👍 or 👎 to provide feedback.