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.
This commit is contained in:
@@ -2,8 +2,6 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
_FIELDS = ("event", "monitor_id", "url", "outcome", "latency_ms", "http_status", "error")
|
|
||||||
|
|
||||||
|
|
||||||
class JsonFormatter(logging.Formatter):
|
class JsonFormatter(logging.Formatter):
|
||||||
def format(self, record: logging.LogRecord) -> str:
|
def format(self, record: logging.LogRecord) -> str:
|
||||||
@@ -13,12 +11,10 @@ class JsonFormatter(logging.Formatter):
|
|||||||
"logger": record.name,
|
"logger": record.name,
|
||||||
"message": record.getMessage(),
|
"message": record.getMessage(),
|
||||||
}
|
}
|
||||||
for field in _FIELDS:
|
for key in ("monitor_id", "target", "outcome", "latency_ms", "http_status"):
|
||||||
value = getattr(record, field, None)
|
value = getattr(record, key, None)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
payload[field] = value
|
payload[key] = value
|
||||||
if record.exc_info:
|
|
||||||
payload["exception"] = self.formatException(record.exc_info)
|
|
||||||
return json.dumps(payload, separators=(",", ":"), default=str)
|
return json.dumps(payload, separators=(",", ":"), default=str)
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +22,5 @@ def configure_logging(level: str) -> None:
|
|||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
handler.setFormatter(JsonFormatter())
|
handler.setFormatter(JsonFormatter())
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
root.handlers.clear()
|
root.handlers = [handler]
|
||||||
root.addHandler(handler)
|
root.setLevel(level.upper())
|
||||||
root.setLevel(level)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user