feat(B.13-B.17+B.16): Error-Handling-Infra, Observability, Graceful Shutdown, Cost-Cap, API Versioning
B.13 Error-Handling-Infrastruktur:
- ErrorCategory Enum (TRANSIENT/PERMANENT/PARTIAL), ApiError erweitert
- Einheitliches Error-Response-Format: {code, detail, field, trace_id, retryable, category}
- 3 FastAPI Exception-Handler (ApiError, HTTPException, unhandled)
- classify_exception() Helper, 6 neue Error-Codes
- 28 Tests in test_error_handling.py
B.14 Observability & trace_id-Korrelation:
- trace_id pro Request (UUID4 short) in structlog contextvars
- X-Trace-Id Response-Header
- Sensitive Fields structlog processor
- llm_complete()/llm_embed() akzeptieren trace_id kwarg
- 12 Tests in test_observability.py
B.15 Graceful Shutdown & Connection Draining:
- _shutdown_event + _inflight_requests Tracking in main.py
- drain_all_connections() in ws_helpers.py
- Worker on_shutdown pausiert WorkflowInstances (status=paused)
- 8 Tests in test_graceful_shutdown.py
B.16 API Versioning Strategie:
- Plugin-Dev-Guide Kapitel 30: URL-basiertes Versioning, Breaking Change Prozess
B.17 Cost Overrun Protection:
- llm_monthly_budget_usd + llm_hard_cutoff Settings
- _check_tenant_budget() vor jedem LLM-Call
- _track_tenant_cost() in Redis (INCRBYFLOAT)
- _check_cost_alerts() bei 50%/80%/100% -> post_system_message()
- 20 Tests in test_cost_protection.py
Total: 68 neue Tests, alle grün. Keine Regressionen.
This commit is contained in:
@@ -2068,4 +2068,28 @@ results = {
|
||||
|
||||
---
|
||||
|
||||
## 30. API Versioning Strategie
|
||||
|
||||
LeoCRM verwendet **URL-basiertes API-Versioning** (`/api/v1/`). Diese Strategie ist verbindlich für alle zukünftigen API-Änderungen.
|
||||
|
||||
### Regeln
|
||||
|
||||
| Änderungstyp | Versionierung | Beispiele |
|
||||
|-------------|--------------|----------|
|
||||
| **Non-breaking** | Innerhalb v1 | Neue Endpoints, neue optionale Felder, neue Query-Parameter |
|
||||
| **Breaking** | Neue v2-Router parallel | Feld entfernt, Feld-Typ geändert, Endpoint entfernt, Semantik geändert |
|
||||
|
||||
### Breaking Change Prozess
|
||||
|
||||
1. **Neuen Router erstellen** — `APIRouter(prefix="/api/v2/...")` parallel zu v1
|
||||
2. **v1 Routes deprecated markieren** — `@router.get("/api/v1/...", deprecated=True)` + `Deprecation` Header
|
||||
3. **Übergangszeit** — 1 Release-Zyklus beide Versionen parallel
|
||||
4. **v1 Routes entfernen** — nach Übergangszeit + Verifikation dass keine Clients mehr v1 nutzen
|
||||
|
||||
### Plugin API Versioning
|
||||
|
||||
Plugins deklarieren ihre API-Prefixe im Manifest (`routes.prefix`). Plugin-API-Änderungen folgen derselben Strategie — Breaking Changes erfordern neue Prefix-Version.
|
||||
|
||||
---
|
||||
|
||||
*This document is authoritative for all plugin development at LeoCRM.*
|
||||
|
||||
Reference in New Issue
Block a user