Skip to content

feat: add mock upstream support across HTTP e2e suites#73

Merged
jy-tan merged 2 commits intomainfrom
e2e-mock-server
Feb 26, 2026
Merged

feat: add mock upstream support across HTTP e2e suites#73
jy-tan merged 2 commits intomainfrom
e2e-mock-server

Conversation

@jy-tan
Copy link
Contributor

@jy-tan jy-tan commented Feb 26, 2026

Summary

Add deterministic mock-upstream support across all HTTP-focused e2e instrumentation suites, and centralize external HTTP configuration so benchmarks/tests are stable and easy to run offline while still allowing real-upstream overrides.

Changes

  • Add drift/instrumentation/e2e_common/external_http.py to centralize USE_MOCK_EXTERNALS and MOCK_SERVER_BASE_URL handling, shared external timeout defaults, and URL rewrite helpers for mock routing
  • Expand drift/instrumentation/e2e_common/mock_upstream/mock_server.py to cover broader endpoint behavior used by e2e apps (jsonplaceholder/httpbin-style routes, status/redirect/text/binary/auth flows, and legacy-compatible paths).
  • Wire mock-upstream service into docker compose for all relevant suites and default to mock mode with override support: django, fastapi, flask, requests, httpx, urllib, urllib3, aiohttp.
  • Refactor framework e2e apps (django/fastapi/flask) to use shared external HTTP helpers instead of per-app duplicated mock config.
  • Add lightweight per-library request rewriting/timeout handling for instrumentation-specific suites so existing tests keep working while routing via mock upstream.
  • Preserve easy opt-out for real upstream validation by setting USE_MOCK_EXTERNALS=0.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 18 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="drift/instrumentation/django/e2e-tests/src/views.py">

<violation number="1" location="drift/instrumentation/django/e2e-tests/src/views.py:102">
P2: The fallback response in create_post can raise UnboundLocalError when json.loads fails, because data is only defined inside the try. Initialize data before the try or guard access in the except block so the fallback path works on invalid JSON.</violation>
</file>

<file name="drift/instrumentation/aiohttp/e2e-tests/src/app.py">

<violation number="1" location="drift/instrumentation/aiohttp/e2e-tests/src/app.py:28">
P2: This patch overrides session-level timeouts. For example, `/test/timeout` creates `ClientSession(timeout=timeout)` but the patched `_request` replaces it with `EXTERNAL_HTTP_TIMEOUT_SECONDS`, so explicit session timeouts are ignored. Preserve session-level timeouts when callers set them, and only apply the external default when the session is using aiohttp’s default timeout.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@jy-tan jy-tan merged commit e449adb into main Feb 26, 2026
43 of 44 checks passed
@jy-tan jy-tan deleted the e2e-mock-server branch February 26, 2026 08:03
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.

2 participants