Skip to content

feat: Exclude verified Edge Proxy requests from API usage tracking - #8407

Draft
gagantrivedi wants to merge 3 commits into
feat/edge-proxy-app-wiringfrom
feat/untrack-edge-proxy-requests
Draft

feat: Exclude verified Edge Proxy requests from API usage tracking#8407
gagantrivedi wants to merge 3 commits into
feat/edge-proxy-app-wiringfrom
feat/untrack-edge-proxy-requests

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

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. APIUsageMiddleware now skips a request when the private edge_proxy app verifies it as the proxy's own — is_edge_proxy_request() checks the X-Proxy-Key value 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_proxy app installed; SaaS behaviour is untouched.

Stacked on #8305. Before merge: bump the flagsmith-private pin to the release that ships is_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.

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).
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 29, 2026 10:33am
flagsmith-frontend-preview Ignored Ignored Preview Aug 29, 2026 10:33am
flagsmith-frontend-staging Ignored Ignored Preview Aug 29, 2026 10:33am

Request Review

@github-actions github-actions Bot added the api Issue related to the REST API label Aug 29, 2026
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0a1d1ca5-7f63-4f40-831c-77081dc20b94

📥 Commits

Reviewing files that changed from the base of the PR and between 4330617 and b0a2a51.

📒 Files selected for processing (2)
  • api/app_analytics/middleware.py
  • api/tests/unit/app_analytics/test_middleware.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

APIUsageMiddleware conditionally wires is_edge_proxy_request for non-SaaS deployments with Edge Proxy installed. It skips usage tracking for verified Edge Proxy requests with an X-Environment-Key header. Tests cover deployment wiring, verified and unverified requests, and tracking when the verifier is not wired.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to b0a2a

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the feature New feature or request label Aug 29, 2026
@gagantrivedi

Copy link
Copy Markdown
Member Author

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.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Aug 29, 2026
@gagantrivedi
gagantrivedi marked this pull request as ready for review August 29, 2026 10:23
@gagantrivedi
gagantrivedi requested a review from a team as a code owner August 29, 2026 10:23
@gagantrivedi
gagantrivedi requested review from matthewelwell and removed request for a team August 29, 2026 10:23
@github-actions github-actions Bot removed the feature New feature or request label Aug 29, 2026
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-8407 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-8407 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8407 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-8407 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8407 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8407 Finished ✅ Results

@github-actions github-actions Bot added the feature New feature or request label Aug 29, 2026
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (4330617) to head (93225c5).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           feat/edge-proxy-app-wiring    #8407   +/-   ##
===========================================================
  Coverage                       98.81%   98.81%           
===========================================================
  Files                            1621     1621           
  Lines                           66103    66147   +44     
===========================================================
+ Hits                            65319    65363   +44     
  Misses                            784      784           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor
✅ oss · depot-ubuntu-latest-arm-16 — run #19949 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.1 seconds
commit  b0a2a51
info  🔄 Run: #19949 (attempt 1)

🗂️ Previous results
✅ oss · depot-ubuntu-latest-16 — run #19949 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.6 seconds
commit  b0a2a51
info  🔄 Run: #19949 (attempt 1)

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.
@gagantrivedi
gagantrivedi marked this pull request as draft August 29, 2026 10:32
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant