-
Notifications
You must be signed in to change notification settings - Fork 25
Add PR review performance telemetry and dashboards #807
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
dayland
wants to merge
5
commits into
main
Choose a base branch
from
perf-eval-engine-metrics
base: main
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd7f347
Add PR review performance telemetry
dayland-ms c0eabd1
Propose PR #807 conflict resolution on the dedicated runner (#808)
gggdttt 9b4a9dc
Record resolved main ancestry
f67e20e
Merge origin/main into perf-eval-engine-metrics
1472fb8
Keep PR review diagnostics in raw artifacts
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
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
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,127 @@ | ||
| import json | ||
| from pathlib import Path | ||
| from typing import Annotated, Literal | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator | ||
|
|
||
| from bcbench.exceptions import AgentError | ||
| from bcbench.types import AgentMetrics | ||
|
|
||
| FILTER_REPORT_FILE_NAME = "_filter-report.json" | ||
| RUN_METRICS_FILE_NAME = "_run-metrics.json" | ||
| _KNOWLEDGE_LAYERS = {"microsoft", "community", "custom"} | ||
| _NonNegativeInt = Annotated[int, Field(ge=0)] | ||
| _NonNegativeFloat = Annotated[float, Field(ge=0)] | ||
|
|
||
|
|
||
| class _FilterRemoval(BaseModel): | ||
| model_config = ConfigDict(extra="ignore", frozen=True) | ||
|
|
||
| kind: Literal["knowledge", "skill"] | ||
|
|
||
|
|
||
| class _FilterReport(BaseModel): | ||
| model_config = ConfigDict(extra="ignore", frozen=True) | ||
|
|
||
| removed: list[_FilterRemoval] | ||
|
|
||
|
|
||
| class _RunMetrics(BaseModel): | ||
| model_config = ConfigDict(extra="forbid", frozen=True, strict=True) | ||
|
|
||
| schema_version: Literal[1] | ||
| metrics_source: Literal["copilot-cli-otel", "not-applicable"] | ||
| cli_version: str | None | ||
| wall_time_seconds: _NonNegativeFloat | None | ||
| prompt_tokens: _NonNegativeInt | None | ||
| cached_tokens: _NonNegativeInt | None | ||
| cache_creation_tokens: _NonNegativeInt | None | ||
| completion_tokens: _NonNegativeInt | None | ||
| reasoning_tokens: _NonNegativeInt | None | ||
| total_tokens: _NonNegativeInt | None | ||
| api_calls: _NonNegativeInt | None | ||
| failed_api_calls: _NonNegativeInt | None | ||
| usage_api_calls: _NonNegativeInt | None | ||
| ai_credits: _NonNegativeFloat | None | ||
| premium_requests: _NonNegativeFloat | None | ||
| models: list[str] | ||
| usage_complete: bool | ||
| malformed_records: _NonNegativeInt | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_not_applicable_shape(self) -> "_RunMetrics": | ||
| if self.metrics_source != "not-applicable": | ||
| return self | ||
| expected = { | ||
| "cli_version": None, | ||
| "wall_time_seconds": 0, | ||
| "prompt_tokens": 0, | ||
| "cached_tokens": 0, | ||
| "cache_creation_tokens": 0, | ||
| "completion_tokens": 0, | ||
| "reasoning_tokens": None, | ||
| "total_tokens": 0, | ||
| "api_calls": 0, | ||
| "failed_api_calls": 0, | ||
| "usage_api_calls": 0, | ||
| "ai_credits": 0.0, | ||
| "premium_requests": None, | ||
| "models": [], | ||
| "usage_complete": True, | ||
| "malformed_records": 0, | ||
| } | ||
| invalid = [name for name, value in expected.items() if getattr(self, name) != value] | ||
| if invalid: | ||
| raise ValueError(f"not-applicable metrics have invalid fields: {', '.join(invalid)}") | ||
| return self | ||
|
|
||
|
|
||
| def _load_run_metrics(path: Path) -> _RunMetrics: | ||
| if not path.exists(): | ||
| raise AgentError(f"Engine run metrics artifact not found at {path}.") | ||
| try: | ||
| payload = json.loads(path.read_text(encoding="utf-8-sig")) | ||
| except (json.JSONDecodeError, OSError) as exc: | ||
| raise AgentError(f"Could not read engine run metrics artifact {path}: {exc}") from exc | ||
| try: | ||
| return _RunMetrics.model_validate(payload) | ||
| except ValidationError as exc: | ||
| raise AgentError(f"Engine run metrics artifact {path} does not satisfy schema version 1: {exc}") from exc | ||
|
|
||
|
|
||
| def _load_filter_report(path: Path) -> _FilterReport: | ||
| if not path.exists(): | ||
| raise AgentError(f"BCQuality filter report not found at {path}.") | ||
| try: | ||
| payload = json.loads(path.read_text(encoding="utf-8-sig")) | ||
| except (json.JSONDecodeError, OSError) as exc: | ||
| raise AgentError(f"Could not read BCQuality filter report {path}: {exc}") from exc | ||
| try: | ||
| return _FilterReport.model_validate(payload) | ||
| except ValidationError as exc: | ||
| raise AgentError(f"BCQuality filter report {path} has an invalid shape: {exc}") from exc | ||
|
|
||
|
|
||
| def _count_available_knowledge(bcquality_root: Path) -> int: | ||
| def is_knowledge_file(path: Path) -> bool: | ||
| parts = path.relative_to(bcquality_root).parts | ||
| return len(parts) >= 3 and parts[0].lower() in _KNOWLEDGE_LAYERS and parts[1].lower() == "knowledge" | ||
|
|
||
| return sum(1 for path in bcquality_root.rglob("*.md") if path.is_file() and is_knowledge_file(path)) | ||
|
|
||
|
|
||
| def build_pr_review_metrics(output_dir: Path, bcquality_root: Path, execution_time: float) -> AgentMetrics: | ||
| run = _load_run_metrics(output_dir / RUN_METRICS_FILE_NAME) | ||
| report = _load_filter_report(bcquality_root / FILTER_REPORT_FILE_NAME) | ||
| usage_values_available = run.malformed_records == 0 | ||
| token_values_available = usage_values_available and run.usage_complete | ||
| return AgentMetrics( | ||
| execution_time=execution_time, | ||
| prompt_tokens=run.prompt_tokens if token_values_available else None, | ||
| completion_tokens=run.completion_tokens if token_values_available else None, | ||
| total_tokens=run.total_tokens if token_values_available else None, | ||
| api_calls=run.api_calls if usage_values_available else None, | ||
| ai_credits=run.ai_credits if usage_values_available else None, | ||
| knowledge_files=_count_available_knowledge(bcquality_root), | ||
| knowledge_pruned=sum(1 for item in report.removed if item.kind == "knowledge"), | ||
| ) |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Changed by mistake?
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.
This is intentional.
@github/copilot@1.0.80is not published to npm, so a clean install fails withE404/ETARGET. Version1.0.79is published and is the version used to validate the structured telemetry contract. The PR description now records the reason for the pin.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.
I can find the
@github/copilot@1.0.80on npm.If you are searching for it on your local machine, it will probably fail because network restrictions on our local dev machine