feat: Exclude verified Edge Proxy requests from API usage tracking - #8407
gagantrivedi wants to merge 6 commits into
Conversation
Detects the edge_proxy app and mounts its two URL trees: proxy key management for organisation admins, and the environment inventory that Edge Proxy instances poll. The feature is for private cloud only. SaaS images ship the private wheel, so the mount is gated on is_saas() at runtime rather than on the app being absent; the app's own views carry a matching permission as defence in depth.
An Edge Proxy sends X-Proxy-Key on its environment-document fetches and reports the requests it serves through its own usage endpoint, so counting its fetches here would double-count. The private edge_proxy app's is_edge_proxy_request() decides the exemption — it verifies the key and that its grants cover the presented environment, so a spoofed header never dodges metering. Wired only on non-SaaS deployments with the edge_proxy app installed; requires the flagsmith-private release that ships is_edge_proxy_request (bump the lock before merge).
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueNo actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR excludes only verified Edge Proxy requests from API usage tracking while retaining tracking when verification is unavailable; no actionable merge-blocking risk remains after normal checks and review. 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 |
|
Companion PRs for Flagsmith/flagsmith-private#256:
Merge/deploy order: #282 and 8407 (with the flagsmith-private pin bump) before any proxy build with #19 is deployed, else document polls double-count during the overlap. |
Docker builds report
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8407 +/- ##
=======================================
Coverage 98.81% 98.81%
=======================================
Files 1621 1621
Lines 66102 66147 +45
=======================================
+ Hits 65318 65363 +45
Misses 784 784 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ oss · depot-ubuntu-latest-arm-16 — run #19949 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
🗂️ Previous results✅ oss · depot-ubuntu-latest-16 — run #19949 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
|
Core's lock pins a flagsmith-private wheel that does not ship the helper yet, so a hard import broke every request in CI. Feature-detect instead: on an older wheel the proxy's fetches are simply counted as before, and the exclusion activates when the pin catches up.
Follows the rename in the edge_proxy app; the getattr feature detection keeps an older wheel degrading to counting as before.
4330617 to
2b4b6f4
Compare
Changes
Contributes to Flagsmith/flagsmith-private#256
An Edge Proxy reports the requests it serves through its own usage endpoint, so counting its
/environment-document/fetches here would double-count.APIUsageMiddlewarenow skips a request when the privateedge_proxyapp verifies it as the proxy's own —is_edge_proxy_request()checks theX-Proxy-Keyvalue and that the key's grants cover the presented environment. Bare header presence is never trusted, so the header can't be spoofed to dodge metering.Wired only on non-SaaS deployments with the
edge_proxyapp installed; SaaS behaviour is untouched.Stacked on #8305. Before merge: bump the
flagsmith-privatepin to the release that shipsis_edge_proxy_request.How did you test this code?
19 middleware unit tests: verifier wired only when installed + non-SaaS; verified requests untracked, unverified tracked; a proxy header with no verifier available still tracked (spoof regression); existing tracking cases unchanged. The verifier itself is tested against a real database in flagsmith-private.