You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB
Python

"""
Pydantic schemas for error logs
"""
from datetime import datetime
from typing import Optional, Dict, List, Any
from pydantic import BaseModel, Field
class ErrorLogBase(BaseModel):
"""Base schema for error logs"""
request_id: str
endpoint: str
method: str
path: str
query_params: Optional[Dict[str, Any]] = None
request_body: Optional[Dict[str, Any]] = None
error_type: str
error_message: str
error_detail: Optional[Dict[str, Any]] = None
status_code: int
stack_trace: Optional[str] = None
user_agent: Optional[str] = None
client_ip: Optional[str] = None
response_time_ms: Optional[float] = None
class ErrorLogResponse(ErrorLogBase):
"""Response schema for error log"""
id: int
headers: Optional[Dict[str, str]] = None
is_resolved: bool = False
resolved_at: Optional[str] = None
resolution_notes: Optional[str] = None
created_at: str
class Config:
from_attributes = True
class ErrorLogListResponse(BaseModel):
"""Response schema for error log list"""
items: List[ErrorLogResponse]
total: int
page: int
page_size: int
total_pages: int
class ErrorLogStats(BaseModel):
"""Statistics about error logs"""
total_errors: int
resolved_errors: int
unresolved_errors: int
resolution_rate: float
errors_by_type: Dict[str, int]
errors_by_status_code: Dict[str, int]
errors_by_endpoint: Dict[str, int]
average_response_time_ms: float
hourly_trend: Dict[str, int]
start_date: str
end_date: str
class ErrorLogUpdate(BaseModel):
"""Schema for updating error log"""
is_resolved: Optional[bool] = None
resolution_notes: Optional[str] = None
class ErrorLogFilter(BaseModel):
"""Schema for filtering error logs"""
start_date: Optional[datetime] = None
end_date: Optional[datetime] = None
error_type: Optional[str] = None
status_code: Optional[int] = None
endpoint: Optional[str] = None
is_resolved: Optional[bool] = None
page: int = Field(1, ge=1)
page_size: int = Field(50, ge=1, le=200)