mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
from datetime import UTC, datetime
|
|
from typing import Optional
|
|
|
|
import structlog
|
|
|
|
from insights.kafka_client.routing import get_producer
|
|
from insights.kafka_client.topics import KAFKA_LOG_ENTRIES
|
|
|
|
from products.endpoints.backend.constants import ENDPOINTS_LOG_SOURCE
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
|
|
# Datastore DateTime64(6, 'UTC') input format — same as the temporal logger uses.
|
|
_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
|
|
|
|
|
|
def build_execution_message(
|
|
*,
|
|
succeeded: bool,
|
|
execution_type: str,
|
|
cache_outcome: Optional[str] = None,
|
|
duration_ms: Optional[int] = None,
|
|
rows: Optional[int] = None,
|
|
version: Optional[int] = None,
|
|
error: Optional[str] = None,
|
|
) -> str:
|
|
"""One human-readable line carrying the extra data as searchable `key=value` tokens.
|
|
|
|
Only non-sensitive execution metadata belongs here. Never add variable values — they
|
|
routinely carry PII (emails, customer IDs, filter values) and must stay out of logs.
|
|
"""
|
|
prefix = "Endpoint executed" if succeeded else "Endpoint execution failed"
|
|
tokens = {
|
|
"path": execution_type,
|
|
"cache": cache_outcome,
|
|
"duration_ms": duration_ms,
|
|
"rows": rows,
|
|
"version": version,
|
|
"error": error,
|
|
}
|
|
token_str = " ".join(f"{key}={value}" for key, value in tokens.items() if value is not None)
|
|
return f"{prefix} · {token_str}" if token_str else prefix
|
|
|
|
|
|
def log_endpoint_execution(
|
|
*,
|
|
team_id: int,
|
|
endpoint_id: str,
|
|
instance_id: str,
|
|
level: str,
|
|
message: str,
|
|
) -> None:
|
|
"""Emit a user-facing endpoint execution log entry to the `log_entries` table.
|
|
|
|
Best-effort: a produce failure must never break or slow down an endpoint run, so failures are
|
|
swallowed (debug-logged). We don't flush — `produce()` polls non-blocking.
|
|
"""
|
|
try:
|
|
producer = get_producer(topic=KAFKA_LOG_ENTRIES)
|
|
producer.produce(
|
|
topic=KAFKA_LOG_ENTRIES,
|
|
data={
|
|
"team_id": team_id,
|
|
"log_source": ENDPOINTS_LOG_SOURCE,
|
|
"log_source_id": str(endpoint_id),
|
|
"instance_id": instance_id,
|
|
"timestamp": datetime.now(tz=UTC).strftime(_TIMESTAMP_FORMAT),
|
|
"level": level,
|
|
"message": message,
|
|
},
|
|
)
|
|
except Exception:
|
|
logger.debug("Failed to emit endpoint execution log entry", exc_info=True)
|