Skip to content

ref(billing): Add quota_config_mapping for proto/sentry QuotaConfig conversion#119133

Merged
volokluev merged 6 commits into
masterfrom
volo/quota-config-mapping
Jul 7, 2026
Merged

ref(billing): Add quota_config_mapping for proto/sentry QuotaConfig conversion#119133
volokluev merged 6 commits into
masterfrom
volo/quota-config-mapping

Conversation

@volokluev

Copy link
Copy Markdown
Member

Summary

  • Adds sentry_to_proto_quota_config() and proto_to_sentry_quota_config() conversion utilities in sentry/billing/platform/services/quota_config_mapping.py
  • These are analogous to the existing category_mapping.py but operate at the QuotaConfig level
  • Needed by getsentry to migrate QuotasService and ContractBudgetEnforcer from dataclass prototypes to protobufs

Test plan

  • Conversions exercised through getsentry service tests (28 pass) and quota_exceeded task tests (32 pass)
  • prek lint and mypy pass

…onversion

Add conversion utilities between proto QuotaConfig and sentry QuotaConfig
to support migrating billing platform services from dataclass prototypes
to protobufs.
@volokluev volokluev requested a review from a team as a code owner July 7, 2026 17:46
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 7, 2026
Comment thread src/sentry/billing/platform/services/quota_config_mapping.py Outdated
Comment thread src/sentry/billing/platform/services/quota_config_mapping.py Outdated
…fig mapping

DataCategory() and QuotaScope() raise ValueError for unmapped proto enum
values that don't correspond to valid sentry enum members. Catch these
errors gracefully: skip unknown categories and fall back to
ORGANIZATION scope, logging warnings for observability.

Co-Authored-By: Claude Opus 4.6 <noreply@example.com>
else QuotaScope.ORGANIZATION
)
except ValueError:
logger.warning(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

should log an exception

@volokluev volokluev left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add some tests

@volokluev volokluev marked this pull request as draft July 7, 2026 18:02

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f1a1a04. Configure here.


return QuotaConfig(
id=proto_quota.id or None,
categories=categories,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dropped categories widen quota scope

Medium Severity

In proto_to_sentry_quota_config, proto categories that fail DataCategory construction are skipped. If every category is skipped, the resulting QuotaConfig has an empty category set, which Sentry treats as applying the quota to all data—not a category-specific quota—so enforcement can broaden incorrectly.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f1a1a04. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ba82e25 — proto_to_sentry_quota_config now returns None when the proto had categories but all were unmapped, preventing the empty category set from broadening the quota to all data.

— Claude Code

volokluev and others added 2 commits July 7, 2026 18:09
Address Cursor Bugbot feedback: if a proto QuotaConfig had categories
but all were unmapped, the resulting empty category set would broaden
the quota to apply to all data. Now returns None in that case.

Also adds comprehensive tests for both conversion directions.

Co-Authored-By: Claude Opus 4.6 <noreply@example.com>
Cast raw int values to proper proto ValueType types to satisfy mypy.

Co-Authored-By: Claude Opus 4.6 <noreply@example.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you intentionally place this module at the top of services/?
Did you have services/quotas/ in mind?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

volokluev added 2 commits July 7, 2026 21:58
Relocate quota_config_mapping.py and its tests into a new
quota/ package under services/ for better organization.
@volokluev volokluev marked this pull request as ready for review July 7, 2026 22:02
Comment thread src/sentry/billing/platform/services/quota/quota_config_mapping.py
@volokluev volokluev merged commit 494e536 into master Jul 7, 2026
65 checks passed
@volokluev volokluev deleted the volo/quota-config-mapping branch July 7, 2026 22:15
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.

3 participants