decomposer: generate deliverable files for Define the service contract and project architecture for the FastAPI endpoint monitoring service.; Implement the typed monitor CRUD API and concurrency-safe in-memory state according to the service design.; Implement secure on-demand endpoint checks with status updates, latency measurement, robust error handling, and redacted structured logs.; Add operational API endpoints and environment-driven runtime configuration to the monitoring service.; Create automated tests for the monitoring service.; Package the service with Docker and developer documentation.; Validate the complete project.
Some checks failed
ci / validate (push) Has been cancelled
Some checks failed
ci / validate (push) Has been cancelled
This commit is contained in:
@@ -1,41 +1,56 @@
|
|||||||
from datetime import UTC, datetime
|
from datetime import datetime, timezone
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field
|
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
|
||||||
class State(StrEnum):
|
def utc_now() -> datetime:
|
||||||
UNKNOWN = "unknown"
|
return datetime.now(timezone.utc)
|
||||||
UP = "up"
|
|
||||||
DOWN = "down"
|
|
||||||
ERROR = "error"
|
class HealthState(StrEnum):
|
||||||
|
unknown = "unknown"
|
||||||
|
up = "up"
|
||||||
|
down = "down"
|
||||||
|
|
||||||
|
|
||||||
class MonitorCreate(BaseModel):
|
class MonitorCreate(BaseModel):
|
||||||
name: str = Field(min_length=1, max_length=100)
|
name: str = Field(min_length=1, max_length=120)
|
||||||
url: AnyHttpUrl
|
url: AnyHttpUrl
|
||||||
|
|
||||||
|
|
||||||
class MonitorUpdate(BaseModel):
|
class MonitorUpdate(MonitorCreate):
|
||||||
name: str | None = Field(default=None, min_length=1, max_length=100)
|
pass
|
||||||
url: AnyHttpUrl | None = None
|
|
||||||
|
|
||||||
|
|
||||||
class CurrentStatus(BaseModel):
|
class CurrentStatus(BaseModel):
|
||||||
state: State = State.UNKNOWN
|
state: HealthState
|
||||||
checked_at: datetime | None = None
|
checked_at: datetime
|
||||||
status_code: int | None = None
|
latency_ms: float = Field(ge=0)
|
||||||
latency_ms: float | None = Field(default=None, ge=0)
|
http_status: int | None = None
|
||||||
error: str | None = None
|
error_code: str | None = None
|
||||||
|
error_message: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class Monitor(BaseModel):
|
class Monitor(BaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(frozen=True)
|
||||||
|
|
||||||
id: UUID = Field(default_factory=uuid4)
|
id: UUID
|
||||||
name: str
|
name: str
|
||||||
url: AnyHttpUrl
|
url: AnyHttpUrl
|
||||||
created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
|
created_at: datetime
|
||||||
updated_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
|
updated_at: datetime
|
||||||
current_status: CurrentStatus = Field(default_factory=CurrentStatus)
|
revision: int
|
||||||
|
current_status: CurrentStatus | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class CheckResponse(BaseModel):
|
||||||
|
monitor_id: UUID
|
||||||
|
status: CurrentStatus
|
||||||
|
applied: bool
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorDetail(BaseModel):
|
||||||
|
code: str
|
||||||
|
message: str
|
||||||
|
|||||||
Reference in New Issue
Block a user