Skip to content

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

Open
gagantrivedi wants to merge 7 commits into
mainfrom
feat/untrack-edge-proxy-requests
Open

gagantrivedi wants to merge 7 commits into
mainfrom
feat/untrack-edge-proxy-requests

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

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 skips a request when the private edge_control_plane app's is_valid_edge_proxy_request() verifies it as the proxy's own: a valid X-Proxy-Key whose 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 edge_control_plane installed; SaaS is untouched.

How did you test this code?

Middleware unit tests: verifier wired only when installed and non-SaaS; verified requests untracked, unverified tracked; a proxy header with no verifier still tracked. The verifier itself is tested in flagsmith-private.

@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
docs Ignored Ignored Preview Nov 7, 2026 8:16am UTC
flagsmith-frontend-preview Ignored Ignored Preview Nov 7, 2026 8:16am UTC
flagsmith-frontend-staging Ignored Ignored Preview Nov 7, 2026 8:16am UTC

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

Explain Change →

Walkthrough

APIUsageMiddleware conditionally wires is_valid_edge_proxy_request when the Edge Control Plane app is installed and the deployment is not SaaS. It skips usage tracking for a request with an X-Environment-Key header only when the validator confirms that the request is valid. Tests cover verifier wiring and tracking behaviour.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 9fd86

No actionable merge-blocking issue is established; the redundant test settings do not affect request tracking.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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.90%. Comparing base (4449ad4) to head (9fd86fb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8407   +/-   ##
=======================================
  Coverage   98.90%   98.90%           
=======================================
  Files        1698     1698           
  Lines       71491    71529   +38     
=======================================
+ Hits        70707    70745   +38     
  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
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #22929 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  5 passed

Details

stats  5 tests across 5 suites
duration  37 seconds
commit  9fd86fb
info  🔄 Run: #22929 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #22929 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  49 seconds
commit  9fd86fb
info  🔄 Run: #22929 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #22929 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.5 seconds
commit  9fd86fb
info  🔄 Run: #22929 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #22929 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  30.9 seconds
commit  9fd86fb
info  🔄 Run: #22929 (attempt 1)

✅ 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)

✅ 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)

@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
@gagantrivedi
gagantrivedi force-pushed the feat/edge-proxy-app-wiring branch from 4330617 to 2b4b6f4 Compare September 16, 2026 10:21
Base automatically changed from feat/edge-proxy-app-wiring to main September 16, 2026 11:12
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).
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.
@gagantrivedi
gagantrivedi force-pushed the feat/untrack-edge-proxy-requests branch from b2b876e to 48e25bb Compare November 7, 2026 07:44
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Nov 7, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Nov 7, 2026
@github-actions github-actions Bot removed the feature New feature or request label Nov 7, 2026
@gagantrivedi
gagantrivedi marked this pull request as ready for review November 7, 2026 08:16
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Nov 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

api/tests/unit/app_analytics/test_middleware.py-184-210: 1

184-210: Trivial · Maintainability & Code Quality · Low value

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Test the verifier through the real wiring path.

This test sets settings.EDGE_CONTROL_PLANE_INSTALLED = False and then assigns middleware.is_valid_edge_proxy_request by hand. It checks the branch in __call__, but not that __init__ wires the verifier. A separate test covers the wiring, so the coverage is acceptable.

The settings.EDGE_CONTROL_PLANE_INSTALLED = False assignment on Line 195 duplicates the autouse fixture. Remove it to reduce noise. The same applies to Line 222.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b5ee4f57-0e49-4094-83c0-2a9e76543882
Commits

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

Files selected for processing: 2

  • api/app_analytics/middleware.py
  • api/tests/unit/app_analytics/test_middleware.py

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

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

24 screenshots compared. See report for details.
View full report

This branch has not been deployed

No deployments
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