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 / test (push) Has been cancelled
Some checks failed
ci / test (push) Has been cancelled
This commit is contained in:
@@ -1,55 +1,45 @@
|
||||
from datetime import UTC, datetime
|
||||
from datetime import datetime
|
||||
from enum import StrEnum
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from pydantic.networks import AnyHttpUrl
|
||||
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class State(StrEnum):
|
||||
unknown = "unknown"
|
||||
up = "up"
|
||||
down = "down"
|
||||
error = "error"
|
||||
class MonitorState(StrEnum):
|
||||
UNKNOWN = "unknown"
|
||||
UP = "up"
|
||||
DOWN = "down"
|
||||
ERROR = "error"
|
||||
BLOCKED = "blocked"
|
||||
|
||||
|
||||
class MonitorInput(BaseModel):
|
||||
class MonitorCreate(BaseModel):
|
||||
name: str = Field(min_length=1, max_length=100)
|
||||
url: AnyHttpUrl
|
||||
timeout_seconds: float | None = Field(default=None, gt=0, le=30)
|
||||
|
||||
@field_validator("url")
|
||||
@classmethod
|
||||
def reject_credentials(cls, value: AnyHttpUrl) -> AnyHttpUrl:
|
||||
if value.username or value.password:
|
||||
raise ValueError("URL credentials are not allowed")
|
||||
return value
|
||||
|
||||
|
||||
class CheckSnapshot(BaseModel):
|
||||
state: State = State.unknown
|
||||
class MonitorUpdate(MonitorCreate):
|
||||
pass
|
||||
|
||||
|
||||
class StatusSnapshot(BaseModel):
|
||||
state: MonitorState = MonitorState.UNKNOWN
|
||||
checked_at: datetime | None = None
|
||||
latency_ms: float | None = None
|
||||
http_status: int | None = None
|
||||
latency_ms: float | None = Field(default=None, ge=0)
|
||||
http_status: int | None = Field(default=None, ge=100, le=599)
|
||||
error: str | None = None
|
||||
|
||||
|
||||
class Monitor(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
name: str
|
||||
url: AnyHttpUrl
|
||||
timeout_seconds: float | None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
revision: int
|
||||
status: CheckSnapshot
|
||||
status: StatusSnapshot
|
||||
|
||||
|
||||
class CheckResult(CheckSnapshot):
|
||||
monitor_id: UUID
|
||||
|
||||
|
||||
def now() -> datetime:
|
||||
return datetime.now(UTC)
|
||||
class Health(BaseModel):
|
||||
status: str
|
||||
|
||||
Reference in New Issue
Block a user