Skip to content

perf(portal): reduce auth log noise and enable HTTP connection reuse (#83)#164

Open
b3lz3but wants to merge 3 commits intocaptainpragmatic:masterfrom
b3lz3but:perf/portal-auth-logging-reduction
Open

perf(portal): reduce auth log noise and enable HTTP connection reuse (#83)#164
b3lz3but wants to merge 3 commits intocaptainpragmatic:masterfrom
b3lz3but:perf/portal-auth-logging-reduction

Conversation

@b3lz3but
Copy link
Copy Markdown
Contributor

@b3lz3but b3lz3but commented Mar 30, 2026

Summary

Fully addresses #83 — Portal→Platform API call optimization (16→10 calls per login).

Opt 3 — Auth logging reduction:

  • Downgrade require_customer_authentication decorator logs from INFO to DEBUG — fires on every authenticated request, ~80% log noise reduction

Opt 4 — HTTP connection reuse:

  • Switch portal_request() from one-shot requests.request() to module-level requests.Session() for HTTP keep-alive connection pooling

Opt 2 — Dashboard session cache seeding:

  • Dashboard already fetches invoice, services, and tickets summaries — now seeds account_health_data session cache so the context processor skips 3 redundant API calls

Opt 1 — Session seeding during login:

Closes #83

Performance impact

Metric Before After
API calls per login+dashboard 16 ~10
Log lines per auth request 4-5 INFO 2 DEBUG
TCP connections New per call Pooled (keep-alive)

Test plan

  • All 977 portal tests pass
  • All 14 outbound_http tests pass
  • All 29 dashboard/account_health tests pass
  • Ruff lint clean
  • All pre-commit hooks pass (DCO signed)
  • CI: platform, portal, integration, DCO check

Generated with Claude Code

…aptainpragmatic#83)

- Downgrade require_customer_authentication decorator logs from INFO to
  DEBUG (fires on every request, ~4-5 lines per authenticated call)
- Switch portal_request() from one-shot requests.request() to a
  module-level requests.Session() for HTTP keep-alive connection pooling
- Update outbound_http tests to patch _session.request

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but
Copy link
Copy Markdown
Contributor Author

Changes

Auth logging (Platform secure_auth.py):

  • Lines 264, 269: logger.infologger.debug on the require_customer_authentication decorator
  • These log on every single authenticated request — entry + success = 2 INFO lines per API call
  • Failures remain at logger.warning (no change)

Connection reuse (Portal outbound_http.py):

  • Added module-level _session = requests.Session() with default User-Agent
  • portal_request() now calls _session.request() instead of requests.request()
  • urllib3 connection pool handles TCP keep-alive automatically
  • requests.Session is thread-safe for concurrent request/response cycles

Test updates (test_outbound_http.py):

  • All 10 @patch decorators updated from requests.request to _session.request
  • All assertions unchanged — same kwargs verification

@mostlyvirtual requesting your review.

b3lz3but and others added 2 commits March 31, 2026 01:10
Update all portal test files to patch _session.request instead of
requests.request, matching the connection pooling change in
outbound_http.py.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
…aptainpragmatic#83)

Dashboard view already fetches invoice, services, and tickets summaries.
Seed the account_health session cache with this data so the context
processor (which runs on every page) skips 3 redundant API calls on the
first request after login.

Combined with the prior commit (auth logging + connection reuse), this
fully addresses captainpragmatic#83: 16 API calls per login+dashboard reduced to ~10,
~80% log noise reduction, and TCP connection reuse via keep-alive.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but
Copy link
Copy Markdown
Contributor Author

What changed (3 commits)

Commit 1 — Auth logging + connection reuse (Opt 3 + Opt 4):

  • secure_auth.py: logger.infologger.debug on require_customer_authentication decorator (2 lines that fire on every authenticated request)
  • outbound_http.py: Module-level requests.Session() replaces one-shot requests.request() — urllib3 handles TCP keep-alive automatically
  • Updated 10 mock patches in test_outbound_http.py

Commit 2 — HMAC test patches:

  • Updated 48 @patch('requests.request')@patch('apps.common.outbound_http._session.request') across 6 test files (integration, security, HMAC tests)

Commit 3 — Dashboard session cache seeding (Opt 2):

  • _get_ticket_data() and _get_services_data() now return raw summaries alongside extracted values
  • After fetching all sections, dashboard_view() seeds account_health_data + account_health_fetched_at in the session
  • The account_health context processor finds cached data → skips 3 redundant API calls (billing, services, tickets summaries)
  • Updated test mocks to match new return signatures

Opt 1 (session seeding during login):

Net result: 16 API calls per login+dashboard → ~10, ~80% log noise reduction, TCP connection reuse.

@mostlyvirtual requesting your review.

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.

perf: Portal→Platform API call optimization (16→10 calls per login)

1 participant