fix(API Usage): API usage notification emails fire at 90%/100% while org is far below plan limit - #8131
Conversation
…org is far below plan limit The Chargebee-sourced allowed_30d_api_calls limit could go stale without anyone noticing: OrganisationSubscriptionInformationCache.chargebee_updated_at was never populated, and a failed Chargebee sync was silently swallowed with no logging. Once the cache held a lower limit than the org's real plan, usage-alert emails were computed against the wrong denominator and fired even though real usage was well under the actual limit. This logs Chargebee sync failures, stamps chargebee_updated_at on a successful sync, and skips (with a warning log) sending a usage alert for Chargebee-billed organisations whose cache hasn't synced recently, instead of trusting a limit that may be wrong. Closes Flagsmith#7976
|
@bardock-2393 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughChargebee subscription metadata failures now emit structured warnings while returning no metadata. Successful cache synchronisation records Estimated code review effort: 3 (Moderate) | ~25 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3cac4f94-c6da-4ab8-b683-222787c7d99d
📒 Files selected for processing (8)
api/organisations/chargebee/chargebee.pyapi/organisations/constants.pyapi/organisations/subscription_info_cache.pyapi/organisations/task_helpers.pyapi/tests/unit/organisations/chargebee/test_unit_chargebee_chargebee.pyapi/tests/unit/organisations/test_unit_organisations_subscription_info_cache.pyapi/tests/unit/organisations/test_unit_organisations_tasks.pydocs/docs/deployment-self-hosting/observability/_events-catalogue.md
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
OrganisationSubscriptionInformationCache.allowed_30d_api_callscan go stale without anyone noticing:chargebee_updated_atwas declared on the model but never populated, and a failed Chargebee sync inget_subscription_metadata_from_idwas silently swallowed with no logging. Once the cache holds a lower limit than the org's real plan, usage-alert emails get computed against the wrong denominator and fire even though real usage is well under the actual limit.chargebee_updated_atwhen a Chargebee sync succeeds.Contributes to #7976
Review effort: 2/5
How did you test this code?
Added unit tests covering: never-synced cache, stale cache, and fresh cache (regression) for
handle_api_usage_notification_for_organisation; the Chargebee sync-failure log; and thechargebee_updated_atstamping inupdate_caches. Ran the full affected test files (test_unit_organisations_tasks.py,test_unit_organisations_subscription_info_cache.py,tests/unit/organisations/chargebee/) locally against Postgres — all pass (91 tests). Also ranmypyandruffon all changed files, and the repo's pre-commit/pre-push hooks (includinggenerate-docsandapi-typecheck).