Handle Hygraph circuit breaker fallbacks#451
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
|
Caution Review failedFailed to post review comments WalkthroughRefactors backend observability and services across multiple layers: introduces OpenTelemetry and Prometheus metrics integration with safe updates, restructures HygraphService for lazy initialization and dependency injection, adds legacy price endpoint redirects, replaces Material/Module models with ProjectQuote/SyncEvent, and updates supporting infrastructure (cache factory, security helpers). Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API as /api/price/{path}
participant Handler as redirect_legacy_price_paths()
participant Response as RedirectResponse
Client->>API: POST /api/price/preview
API->>Handler: route to handler (remaining="preview")
Handler->>Handler: compute target: /api/v1/price/preview
Handler->>Handler: build full URL from request
Handler->>Response: create RedirectResponse(status_code=308)
Response->>Client: 308 Location: /api/v1/price/preview
Client->>API: follow redirect to /api/v1/price/preview
sequenceDiagram
participant Sync as routes_sync.py
participant Factory as get_hygraph_service()
participant Cache as _HYGRAPH_SERVICE_CACHE
participant HG as HygraphService
participant CB as CircuitBreaker
Sync->>Factory: get_hygraph_service()
Factory->>Cache: check cache key (webhook_secret)
alt Cache hit
Cache-->>Factory: return cached HygraphService
else Cache miss
Factory->>HG: HygraphService(client, cache, ttl)
HG->>HG: lazy init _default instance
Factory->>Cache: store service
end
Factory-->>Sync: return HygraphService instance
Sync->>HG: pull_materials()
HG->>CB: execute with circuit breaker
alt Success
CB-->>HG: return result
Sync->>Sync: record_http_request()
else CircuitOpen
CB-->>HG: raise CircuitOpenError(fallback_result)
Sync->>Sync: record_hygraph_cb_trip()
Sync->>Sync: record_hygraph_cb_fallback()
Sync->>Sync: emit observability metrics
end
sequenceDiagram
participant Metrics as observe_http_request()
participant OTEL as OTEL HTTP Histogram
participant Prom as Prometheus HTTP Histogram
participant Safe as _safe_record_histogram()
Metrics->>Safe: call with OTEL histogram
Safe->>OTEL: histogram.record(value, attributes)
alt Success
OTEL-->>Safe: recorded
else Error
Safe->>Safe: log warning (skip)
end
Metrics->>Safe: call with Prometheus histogram
Safe->>Prom: histogram.record(value, attributes)
alt Success
Prom-->>Safe: recorded
else Error
Safe->>Safe: log warning (skip)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Rationale: This PR introduces interconnected changes across critical subsystems—HygraphService undergoes a major architectural shift to dependency injection and singleton patterns; metrics layer integrates OpenTelemetry with Prometheus and adds safe-update helpers; models are replaced with new schemas; new routing/redirect logic and factory patterns are added. While individual changes are understandable, the coordination between Hygraph service refactoring, metrics callbacks, test assertions, and model dependencies requires careful cross-file reasoning to verify correctness and catch subtle initialization or caching edge cases. Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Note Docstrings generation - SUCCESS |
…7wf` Docstrings generation was requested by @shayancoin. * #451 (comment) The following files were modified: * `backend/api/main.py` * `backend/api/metrics.py` * `backend/api/routes_sync.py` * `backend/api/security.py` * `backend/services/cache.py` * `backend/services/hygraph_service.py` * `backend/tests/test_routes_quote_cnc.py` * `backend/tests/test_security.py` * `backend/tests/test_sync_routes_metrics.py`
…7wf` (#453) Docstrings generation was requested by @shayancoin. * #451 (comment) The following files were modified: * `backend/api/main.py` * `backend/api/metrics.py` * `backend/api/routes_sync.py` * `backend/api/security.py` * `backend/services/cache.py` * `backend/services/hygraph_service.py` * `backend/tests/test_routes_quote_cnc.py` * `backend/tests/test_security.py` * `backend/tests/test_sync_routes_metrics.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Shayan <shayan@coin.link>
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68f5c02182b08330b908f6c62b14dc10
Summary by CodeRabbit
Release Notes
New Features
Improvements