-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(preprod): expose status check data through build details API #104085
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| from sentry.preprod.build_distribution_utils import is_installable_artifact | ||
| from sentry.preprod.models import PreprodArtifact, PreprodArtifactSizeMetrics | ||
| from sentry.preprod.vcs.status_checks.size.tasks import StatusCheckErrorType | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -52,6 +53,32 @@ class BuildDetailsVcsInfo(BaseModel): | |
| pr_number: int | None = None | ||
|
|
||
|
|
||
| class StatusCheckResultSuccess(BaseModel): | ||
| """Result of a successfully posted status check.""" | ||
|
|
||
| success: Literal[True] = True | ||
| check_id: str | None = None | ||
|
|
||
|
|
||
| class StatusCheckResultFailure(BaseModel): | ||
| """Result of a failed status check post.""" | ||
|
|
||
| success: Literal[False] = False | ||
| error_type: StatusCheckErrorType | None = None | ||
|
|
||
|
|
||
| StatusCheckResult = Annotated[ | ||
| StatusCheckResultSuccess | StatusCheckResultFailure, | ||
| Field(discriminator="success"), | ||
| ] | ||
|
|
||
|
|
||
| class PostedStatusChecks(BaseModel): | ||
| """Status checks that have been posted to the VCS provider.""" | ||
|
|
||
| size: StatusCheckResult | None = None | ||
|
|
||
|
|
||
| class SizeInfoSizeMetric(BaseModel): | ||
| metrics_artifact_type: PreprodArtifactSizeMetrics.MetricsArtifactType | ||
| install_size_bytes: int | ||
|
|
@@ -101,6 +128,7 @@ class BuildDetailsApiResponse(BaseModel): | |
| app_info: BuildDetailsAppInfo | ||
| vcs_info: BuildDetailsVcsInfo | ||
| size_info: SizeInfo | None = None | ||
| posted_status_checks: PostedStatusChecks | None = None | ||
|
|
||
|
|
||
| def platform_from_artifact_type(artifact_type: PreprodArtifact.ArtifactType) -> Platform: | ||
|
|
@@ -237,10 +265,41 @@ def transform_preprod_artifact_to_build_details( | |
| pr_number=(artifact.commit_comparison.pr_number if artifact.commit_comparison else None), | ||
| ) | ||
|
|
||
| posted_status_checks = None | ||
| if artifact.extras and "posted_status_checks" in artifact.extras: | ||
| raw_checks = artifact.extras["posted_status_checks"] | ||
| size_check: StatusCheckResult | None = None | ||
|
|
||
| if isinstance(raw_checks, dict) and "size" in raw_checks: | ||
| raw_size = raw_checks["size"] | ||
| if isinstance(raw_size, dict): | ||
| if raw_size.get("success"): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Truthiness check mishandles non-boolean success valuesThe |
||
| check_id = raw_size.get("check_id") | ||
| size_check = StatusCheckResultSuccess(check_id=check_id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unvalidated check_id causes Pydantic validation crashThe |
||
| else: | ||
| error_type: StatusCheckErrorType | None = None | ||
| error_type_str = raw_size.get("error_type") | ||
| if error_type_str: | ||
| try: | ||
| error_type = StatusCheckErrorType(error_type_str) | ||
| except ValueError: | ||
| logger.warning( | ||
| "preprod.build_details.invalid_error_type", | ||
| extra={ | ||
| "artifact_id": artifact.id, | ||
| "error_type": error_type_str, | ||
| }, | ||
| ) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| size_check = StatusCheckResultFailure(error_type=error_type) | ||
|
|
||
| if size_check is not None: | ||
| posted_status_checks = PostedStatusChecks(size=size_check) | ||
|
|
||
| return BuildDetailsApiResponse( | ||
| id=artifact.id, | ||
| state=artifact.state, | ||
| app_info=app_info, | ||
| vcs_info=vcs_info, | ||
| size_info=size_info, | ||
| posted_status_checks=posted_status_checks, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.