Skip to content

feat(preprod): Add Size Analysis detector#108208

Open
chromy wants to merge 1 commit intomasterfrom
chromy/2026-03-12-add-grouptype
Open

feat(preprod): Add Size Analysis detector#108208
chromy wants to merge 1 commit intomasterfrom
chromy/2026-03-12-add-grouptype

Conversation

@chromy
Copy link
Contributor

@chromy chromy commented Feb 13, 2026

Add PreprodSizeAnalysisGroupType (type_id=11003) with detector handler
and validators that integrate with the workflow engine to emit issues
when build size thresholds are exceeded.

  • PreprodSizeAnalysisDetectorHandler: evaluates DataPackets from size
    comparisons and produces IssueOccurrences
  • PreprodSizeAnalysisDetectorValidato validate detector creation via the API
  • Register the GroupType import in preprod/grouptype.py

PRs:

Design doc

@chromy chromy requested review from a team as code owners February 13, 2026 11:32
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 13, 2026
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/preprod/migrations/0027_size_analysis_subscription.py

for 0027_size_analysis_subscription in preprod

--
-- Create model SizeAnalysisSubscription
--
CREATE TABLE "sentry_sizeanalysissubscription" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "project_id" bigint NOT NULL);
ALTER TABLE "sentry_sizeanalysissubscription" ADD CONSTRAINT "sentry_sizeanalysiss_project_id_41e3355e_fk_sentry_pr" FOREIGN KEY ("project_id") REFERENCES "sentry_project" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "sentry_sizeanalysissubscription" VALIDATE CONSTRAINT "sentry_sizeanalysiss_project_id_41e3355e_fk_sentry_pr";
CREATE INDEX CONCURRENTLY "sentry_sizeanalysissubscription_project_id_41e3355e" ON "sentry_sizeanalysissubscription" ("project_id");

@chromy chromy force-pushed the chromy/2026-03-12-add-grouptype branch from affc2c2 to 258f072 Compare February 16, 2026 18:34
@chromy chromy marked this pull request as ready for review February 16, 2026 19:17
return self._extract_head(data_packet) - self._extract_base(data_packet)
case "relative_diff":
base = self._extract_base(data_packet)
return (self._extract_head(data_packet) - base) / base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The extract_value method can cause a ZeroDivisionError when calculating a relative_diff because it divides by base without checking if base is zero.
Severity: MEDIUM

Suggested Fix

Before performing the division in extract_value, check if base is 0. If it is, return a sensible default value, similar to the pattern used in src/sentry/preprod/vcs/status_checks/size/tasks.py which returns False in this scenario.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/preprod/size_analysis/grouptype.py#L127

Potential issue: In `PreprodSizeAnalysisDetectorHandler.extract_value()`, when
`threshold_type` is `"relative_diff"`, the code calculates a value by dividing by
`base`. However, the `_extract_base()` method does not prevent `base` from being `0`. If
a data packet results in a base size of 0, this will cause an unhandled
`ZeroDivisionError`, crashing the detector handler during evaluation. Similar code
elsewhere in the project explicitly checks for a zero base value, indicating this is a
known edge case that should be handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant