Skip to content

feat(preprod): Add SizeAnalysisSubscription as a DataSource#108172

Draft
chromy wants to merge 2 commits intomasterfrom
chromy/2026-03-12-add-sub
Draft

feat(preprod): Add SizeAnalysisSubscription as a DataSource#108172
chromy wants to merge 2 commits intomasterfrom
chromy/2026-03-12-add-sub

Conversation

@chromy
Copy link
Contributor

@chromy chromy commented Feb 12, 2026

Add SizeAnalysisSubscription model as a DataSource for size monitors. Since we're pushing
size data from the monolith we know when we need to evaluate detectors and so can avoid
polling - however this means we also need our own subscription type rather than re-using
QuerySubscription.

PRs:

@chromy chromy requested a review from a team as a code owner February 12, 2026 20:58
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 12, 2026
@chromy chromy changed the title feat(preprod): Add monitor detector feat(preprod): Add size monitor models Feb 12, 2026
@chromy chromy changed the title feat(preprod): Add size monitor models feat(preprod): Add size monitor model Feb 12, 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");

Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.



@data_source_type_registry.register(DATA_SOURCE_SIZE_ANALYSIS)
class SizeAnalysisDataSourceHandler(DataSourceTypeHandler["SizeAnalysisSubscription"]):
Copy link
Contributor

Choose a reason for hiding this comment

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

is there not some other models file for subscription / data source handlers that this should live in instead?

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Could you explain how data is coming in here? Is this doing something similar to metric alerts, where a query is running in snuba on a regular schedule and you're then processing the results?

@chromy chromy force-pushed the chromy/2026-03-12-add-sub branch from 944f145 to e5b8172 Compare February 13, 2026 10:51
@chromy
Copy link
Contributor Author

chromy commented Feb 13, 2026

Could you explain how data is coming in here? Is this doing something similar to metric alerts, where a query is running in snuba on a regular schedule and you're then processing the results?

@wedamija Sorry! Yeah was not the best description. No, the idea was that compare_preprod_artifact_size_analysis would call through to process_data_packet on each new data point. I wrote a bit more here: https://www.notion.so/sentry/Size-Monitors-3068b10e4b5d805ca57de084d1b4eba6

Comment on lines +812 to +815
class SizeAnalysisSubscription(DefaultFieldsModel):
__relocation_scope__ = RelocationScope.Excluded

project = FlexibleForeignKey("sentry.Project")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to add any more to this model or is it just for the data source relationship?

If it's just for the data source, we could also omit this class if you wanted. Since the relationship is based on the project_id, we could just directly lookup the detectors w/o a data source and reduce the number of rows needed in the DB for these detectors. The only benefit for this relationship is some added caching layers for looking up detectors (it's only a 3min TTL, so probably wouldn't help too much for these detectors).

if you wanted to omit this class / the data source entirely, you could just create the Detector model, select the detectors by type + project_id, and then run process_detectors instead of process_data_packet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we can get away without even better! I'll draft this one and go straight for #108208

@chromy chromy marked this pull request as draft February 16, 2026 19:17
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.

4 participants