diff --git a/README.md b/README.md index 1565d3c..792d6ba 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,23 @@ container so the published port works. Production knobs (`COOKIE_SECURE`, means dev mirror mode without credentials; a cookie-using browser frontend must be allowlisted explicitly. Works with `docker compose` too. +Three more services make up the telemetry sink: `temps` (UI and API on +`127.0.0.1:3000`, OTLP ingest on `127.0.0.1:9000`) with its TimescaleDB and +ClickHouse stores. Its image is built locally from +`observability/Containerfile.temps` — the published one is tagged alpine but +ships a glibc binary that cannot exec. Temps refuses to start its console +without a container socket, so `systemctl --user start podman.socket` first. +Log in at http://127.0.0.1:3000 as `admin@hezarfen.local` with the password in +`observability/temps-admin-password`, then mint an ingest key (Settings → API +Keys, or `podman exec hezarfen-temps temps api-key --name `) and note the +project id shown on the project page. Uncomment the backend's +`OTEL_EXPORTER_OTLP_ENDPOINT` (`http://temps:9000/api/otel`), +`OTEL_EXPORTER_OTLP_PROTOCOL` (`http/protobuf` — Temps has no gRPC listener) +and `OTEL_EXPORTER_OTLP_HEADERS` +(`Authorization=Bearer ,X-Temps-Project-Id=`), and traces, metrics and +logs start landing. Signals are kept 90 days +(`TEMPS_OTEL_RETENTION_DAYS`). + The backend survives the database going away, at boot and at runtime. At boot it retries the connection (1s doubling to 5s) until the server diff --git a/compose.yaml b/compose.yaml index 793423c..c8baf89 100644 --- a/compose.yaml +++ b/compose.yaml @@ -58,6 +58,16 @@ services: # RATE_LIMIT_AUTH_PER_MINUTE: "10" # RATE_LIMIT_API_PER_MINUTE: "300" # TRUST_PROXY: "true" + # Telemetry — export traces, metrics and logs to Temps over OTLP/HTTP. + # Uncomment once a Temps project exists: create the project in the UI at + # http://127.0.0.1:3000, mint an API key (tk_...) under Settings > API + # Keys, and put its numeric project id in the header. OTLP/HTTP protobuf + # only — Temps has no gRPC port, and the ingest path is /api/otel/v1/*, + # so the endpoint carries the /api/otel prefix. + # OTEL_EXPORTER_OTLP_ENDPOINT: http://temps:9000/api/otel + # OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf + # OTEL_EXPORTER_OTLP_HEADERS: "Authorization=Bearer tk_xxx,X-Temps-Project-Id=1" + # OTEL_SERVICE_NAME: hezarfen-backend # AI bridge — the AI services dial IN over QUIC. Unset means off; a # bad address or a missing token fails the boot rather than leaving a # silently dead feature. Listening with no service connected is fine: @@ -80,6 +90,124 @@ services: retries: 3 start_period: 10s + # ── Telemetry sink ──────────────────────────────────────────────────────── + # Temps is the only telemetry sink (no Grafana/Jaeger/Loki). It stores + # metadata in TimescaleDB and the OTLP signals themselves in ClickHouse, so + # both come along. Neither database is published to the host; only the Temps + # API/UI (3000) and its public ingest listener (9000) are, on loopback. + temps-postgres: + image: docker.io/gotempsh/timescaledb-walg:pg18 + container_name: hezarfen-temps-postgres + environment: + POSTGRES_DB: temps + POSTGRES_USER: temps + # Local-dev credential, same status as the root/root above. Never leaves + # the compose network — the port is not published. + POSTGRES_PASSWORD: temps_local_dev + TIMESCALEDB_TELEMETRY: off + volumes: + # Spilo/timescaledb-ha initialises its cluster here, not in the stock + # postgres image's /var/lib/postgresql/data. Mounting the wrong path + # loses everything on every recreation. + - temps-postgres-data:/home/postgres/pgdata/data + restart: unless-stopped + healthcheck: + test: + [ + "CMD-SHELL", + "PGPASSWORD=$$POSTGRES_PASSWORD psql -h 127.0.0.1 -U temps -d temps -tAc 'SELECT 1' | grep -qx 1", + ] + interval: 10s + timeout: 5s + retries: 12 + start_period: 30s + + temps-clickhouse: + image: docker.io/clickhouse/clickhouse-server:26.7.5.10-alpine + container_name: hezarfen-temps-clickhouse + environment: + CLICKHOUSE_DB: temps + CLICKHOUSE_USER: temps + CLICKHOUSE_PASSWORD: temps_local_dev + volumes: + - temps-clickhouse-data:/var/lib/clickhouse + ulimits: + nofile: + soft: 262144 + hard: 262144 + restart: unless-stopped + healthcheck: + test: ["CMD", "clickhouse-client", "--user", "temps", "--database", "temps", "--query", "SELECT 1"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 20s + + temps: + # Built locally from the pinned upstream artifact — see + # observability/Containerfile.temps for why the published image can't run. + build: + context: ./observability + dockerfile: Containerfile.temps + image: localhost/hezarfen-temps:0.1.0-nightly.20260906.48c2396e + container_name: hezarfen-temps + environment: + TEMPS_DATABASE_URL: postgresql://temps:temps_local_dev@temps-postgres:5432/temps + # UI + API on 3000, public ingest (OTLP among it) on 9000. + TEMPS_ADDRESS: 0.0.0.0:3000 + TEMPS_CONSOLE_ADDRESS: 0.0.0.0:9000 + TEMPS_DATA_DIR: /app/data + TEMPS_LOG_LEVEL: info + TEMPS_CLICKHOUSE_URL: http://temps-clickhouse:8123 + TEMPS_CLICKHOUSE_DATABASE: temps + TEMPS_CLICKHOUSE_USER: temps + TEMPS_CLICKHOUSE_PASSWORD: temps_local_dev + # Signal retention. 90 is also Temps' own default (the spans table's + # `retention_days` column defaults to 90 and the TTL is derived from it), + # set here so the number is in the file rather than only in Temps' own + # settings row, which the console can change. + TEMPS_OTEL_RETENTION_DAYS: "90" + # First-boot admin, created once. The password is mounted from a file so + # it stays out of argv; change observability/temps-admin-password before + # this is reachable from anywhere but your machine. + TEMPS_ADMIN_EMAIL: admin@hezarfen.local + TEMPS_ADMIN_PASSWORD_FILE: /run/temps/admin_password + TEMPS_EXECUTION_ENV: docker + ports: + - "127.0.0.1:3000:3000" + - "127.0.0.1:9000:9000" + volumes: + - temps-data:/app/data + - ./observability/temps-admin-password:/run/temps/admin_password:ro + # Temps refuses to start its console (UI + OTLP ingest) without a + # container socket. Podman's API is Docker-compatible; start it with + # `systemctl --user start podman.socket`. Running as root inside the + # container is what makes the rootless socket readable (container root + # maps to your host user) — same reasoning as surrealdb above. + - ${XDG_RUNTIME_DIR:-/run/user/1000}/podman/podman.sock:/var/run/docker.sock + user: "0" + # SELinux blocks reading the podman socket from inside the container + # ("Permission denied", which Temps reports as "Socket not found"). + # Relabelling the socket itself would break podman, so the label is + # dropped for this container only. + security_opt: + - label=disable + depends_on: + temps-postgres: + condition: service_healthy + temps-clickhouse: + condition: service_healthy + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:9000/readyz"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 40s + volumes: hezarfen-data: surreal-data: + temps-postgres-data: + temps-clickhouse-data: + temps-data: diff --git a/observability/Containerfile.temps b/observability/Containerfile.temps new file mode 100644 index 0000000..a9f1ef6 --- /dev/null +++ b/observability/Containerfile.temps @@ -0,0 +1,20 @@ +# Temps ships a broken runtime image: ghcr.io/gotempsh/temps:* is alpine/musl +# but the binary inside is glibc-linked, so it dies with "exec container +# process (missing dynamic library?) /usr/local/bin/temps". Their supported +# path is building the whole thing from source. Rebasing the same pinned +# artifact onto debian-slim gives a runnable image in seconds instead. +# Delete this file and use the upstream image directly once it executes. +FROM ghcr.io/gotempsh/temps:0.1.0-nightly.20260906.48c2396e AS artifacts + +FROM docker.io/library/debian:bookworm-slim +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates tzdata wget \ + && rm -rf /var/lib/apt/lists/* +COPY --from=artifacts /usr/local/bin/temps /usr/local/bin/temps +RUN useradd --uid 1000 --create-home temps \ + && mkdir -p /app/data \ + && chown -R temps:temps /app +USER temps +WORKDIR /app +ENTRYPOINT ["/usr/local/bin/temps"] +CMD ["serve"] diff --git a/observability/temps-admin-password b/observability/temps-admin-password new file mode 100644 index 0000000..2267764 --- /dev/null +++ b/observability/temps-admin-password @@ -0,0 +1 @@ +Temps-Local-Dev-1