-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat(feature-flags): support quota limiting for feature flags #1758
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements quota limiting support for feature flags in the PostHog JavaScript SDK, handling cases where users exceed their feature flag usage limits.
- Added
QuotaLimitedResource
enum insrc/posthog-featureflags.ts
to identify quota-limited resources - Added quota limit check in
/decide
endpoint response handling to prevent flag processing when limits are exceeded - Added warning message directing users to documentation when feature flag quota is exceeded
- Added comprehensive test suite in
src/__tests__/posthog-core.loaded.test.ts
covering quota limiting scenarios - Implemented graceful degradation by preserving existing flag states when quota is exceeded
2 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
callback?.({ | ||
statusCode: 200, | ||
json: { | ||
quotaLimited: ['feature_flags'], | ||
featureFlags: { 'test-flag': true }, | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Response mock uses 'statusCode' but earlier mock uses 'status'. Inconsistent response structure could cause issues.
mockLogger = jest.spyOn(console, 'warn').mockImplementation() | ||
instance = await createPosthog() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Console warning spy is created but no tests verify warning messages for quota limiting
enum QuotaLimitedResource { | ||
FeatureFlags = 'feature_flags', | ||
Recordings = 'recordings', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider making this enum exported since it may be useful for other parts of the codebase that need to handle quota limiting
@@ -302,6 +307,15 @@ export class PostHogFeatureFlags { | |||
} | |||
|
|||
this._flagsLoadedFromRemote = !errorsLoading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Setting _flagsLoadedFromRemote before checking quota could be misleading since flags aren't actually loaded when quota is exceeded
this._flagsLoadedFromRemote = !errorsLoading | |
if (response.json && response.json.quotaLimited?.includes(QuotaLimitedResource.FeatureFlags)) { | |
// log a warning and then early return | |
logger.warn( | |
'You have hit your feature flags quota limit, and will not be able to load feature flags until the quota is reset. Please visit https://posthog.com/docs/billing/limits-alerts to learn more.' | |
) | |
return | |
} | |
this._flagsLoadedFromRemote = !errorsLoading |
Size Change: +3.72 kB (+0.11%) Total Size: 3.32 MB
ℹ️ View Unchanged
|
with PostHog/posthog#28564, we now start to respond different with the /decide and /local_evaluation APIs if users have gone over their quota limit. Now we need to change the SDKs to handle these new responses.