Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dmarticus
Copy link
Contributor

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.

Copy link

vercel bot commented Feb 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Feb 22, 2025 1:02am

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 in src/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

Comment on lines +124 to +130
callback?.({
statusCode: 200,
json: {
quotaLimited: ['feature_flags'],
featureFlags: { 'test-flag': true },
},
})
Copy link
Contributor

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.

Comment on lines +114 to +115
mockLogger = jest.spyOn(console, 'warn').mockImplementation()
instance = await createPosthog()
Copy link
Contributor

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

Comment on lines +107 to +110
enum QuotaLimitedResource {
FeatureFlags = 'feature_flags',
Recordings = 'recordings',
}
Copy link
Contributor

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
Copy link
Contributor

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

Suggested change
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

Copy link

Size Change: +3.72 kB (+0.11%)

Total Size: 3.32 MB

Filename Size Change
dist/array.full.es5.js 270 kB +376 B (+0.14%)
dist/array.full.js 373 kB +372 B (+0.1%)
dist/array.full.no-external.js 371 kB +372 B (+0.1%)
dist/array.js 184 kB +372 B (+0.2%)
dist/array.no-external.js 183 kB +372 B (+0.2%)
dist/main.js 185 kB +372 B (+0.2%)
dist/module.full.js 373 kB +372 B (+0.1%)
dist/module.full.no-external.js 371 kB +372 B (+0.1%)
dist/module.js 184 kB +372 B (+0.2%)
dist/module.no-external.js 183 kB +372 B (+0.2%)
ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 216 kB
dist/customizations.full.js 14 kB
dist/dead-clicks-autocapture.js 14.5 kB
dist/exception-autocapture.js 9.51 kB
dist/external-scripts-loader.js 2.64 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/surveys-preview.js 70 kB
dist/surveys.js 73.1 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant