Skip to main content

Observability

Synced from pick-face-replenishment

This page is a copy of docs/docs/operations/observability.md on develop, derived from that repository's code. Edit it there, then re-sync.

The service today has structured logs and two health endpoints, and nothing else. There is no metrics endpoint, no OpenTelemetry SDK, no OTLP exporter and no tracing setup in cmd/api: grep for otel, prometheus and /metrics over cmd/ and internal/ finds only the trace-context helper described below. This page says what exists and how to watch the service with it.

Metrics​

ItemState
/metrics endpointnot served (the router has only /healthz, /readyz and the 10 API operations)
OTel metric instrumentsnone: the service creates no meter, counter or histogram
OTLP exporter variables (OTEL_EXPORTER_OTLP_ENDPOINT, ...)not read: the SDK is not wired
Go runtime metrics, HTTP server durationnot emitted

Consequence: there are no service metrics to scrape from cmd/api. warehouse-infra (origin/develop) does ship a Grafana dashboard (terraform/dashboards/contexts/pick-face-replenishment.json) and Kong-based alert rules (5xx ratio, availability and latency SLO burn, container restarts), but they read Kong's kong_http_requests_total and latency histograms and kube restarts; the panels that query http_server_request_duration_seconds or the Go runtime metrics stay empty for cmd/api (it emits neither) and fill only for the analytics binaries once they are deployed. The state of the service has to be read from logs, the database and Kafka itself (see Suggested alerts).

Traces​

No spans are created. The only OpenTelemetry code is traceHeaders in internal/adapters/outbound/postgres/outbox_repository.go: it asks the global propagator for the W3C trace context of the request and appends traceparent (and tracestate, baggage when present) to the headers stored with each outbox row, so a consumer could continue the trace. The composition root installs no propagator, so the global one is the no-op default and no trace headers are stored today; every outbox row carries only the CloudEvents content-type header. The code comment that says "once the composition root installs it" describes a wiring that has not happened.

Logs​

JSON, one object per line on stdout, via log/slog (time, level, msg plus the attributes below). LOG_LEVEL selects the threshold. There is no access log: successful requests are not logged; only failures are.

Boot and lifecycle​

LevelmsgAttributesMeaning
INFOkafka topics (informational; the broker auto-creates them on first write, the service never creates them through an admin API)topics consumed and producedlogged at boot; topics play no part in /readyz
INFOpostgres adapters configuredmigrations ran and the pool pinged
WARNretryingop (run migrations, ping postgres), attempt, in, errboot retry, backoff 1 s doubling
INFOsucceeded after retryop, attempta retried boot step worked
ERRORservice exited with errorerrorboot refused (migration or ping failure, bad consumer configuration) or the listener failed
INFOhttp server listeningaddrthe listener is up (the pod turns ready)
INFOshutdown: readiness flipped to not-ready; waiting for traffic to draindrain_delaySIGINT or SIGTERM received
WARNworker did not stop before the shutdown drain deadlineworker (INVENTORY_MODE, SLOTTING_MODE, LAYOUT_MODE, outbox-relay)a worker ignored the 10 s stop bound
WARNinvalid OUTBOX_RELAY_INTERVAL; using the default, invalid OUTBOX_MAX_ATTEMPTS; using the default, ignoring invalid SHUTDOWN_DRAIN_DELAYvalue, defaulta malformed setting was replaced by its default

Outbox relay​

LevelmsgAttributesMeaning
INFOoutbox relay runninginterval, max_attempts, brokersrelay started (it always runs; a missing DATABASE_URL or KAFKA_BROKERS is a boot error)
ERRORoutbox relay pass failederrora Kafka or database error; retried after the interval
ERRORoutbox relay: row reached the attempt cap and is excluded from future claims; re-arm it with attempts = 0 after fixing the causeoutbox_id, topic, event_type, key, attempts, max_attempts, errorone row will not be retried until re-armed
ERRORoutbox relay stopped, kafka relay sink close failederrorthe relay ended abnormally

Consumers​

LevelmsgAttributesMeaning
INFOconsumer runningconsumer (inventory consumer, slotting consumer, layout consumer), topic, group_id, brokersstarted (all three always run)
INFOevent processedtype, event_id, subject, outcome (applied, duplicate, stale, ignored)one message handled
WARNskipping a message that is not a valid CloudEventconsumer, topic, errorcommitted past, never retried
WARNdead-lettering an event that can never be appliedconsumer, type, event_id, errorpoison payload
ERRORkafka reader error; retryingconsumer, topic, detailkafka-go is retrying a group join: the broker is unreachable or the consumed topic does not exist yet (its producer has not written). Not a readiness failure; the consumer recovers by itself
ERROR<consumer> handling failed; retrying the same messageerror, partition, offset, attempt, max_attempts, retry_intransient failure, logged on every attempt
ERROR<consumer> handling failed after the maximum attempts; dead-lettering the messageerror, partition, offset, attemptsmoved to the .dlq topic
ERROR<consumer> message can never be applied; dead-lettering it without retryerror, partition, offsetpoison, immediate
ERROR<consumer> dead-letter publish failed; retrying the same message, <consumer> offset commit failed; retrying the same messageerror, partition, offset, attempt, retry_inthe partition is blocked until it succeeds
ERRORconsumer stopped, consumer close failedconsumer, errorthe loop ended with an error

HTTP​

LevelmsgAttributesMeaning
ERRORrequest failederror, method, pathan unmapped error became a 500 internal-error (the response never carries the internal message)
ERRORhandler panickedpanic, method, patha recovered panic became a 500
WARNidempotency: answer not storederrora 4xx answer could not be stored for replay; it was still sent

Domain rejections (4xx) are not logged at all; they are visible only in the response.

Health endpoints​

EndpointHealthyUnhealthy
GET /healthz200 {"status":"ok"}the process is gone
GET /readyz200 {"status":"ready"}503 {"status":"not_ready"} after shutdown began; 503 dependency-unavailable while Postgres or the Kafka broker is unreachable (topics are not checked)

/healthz checks neither Postgres nor Kafka; /readyz checks Postgres and that a Kafka broker answers, never topics (Runbook).

Suggested alerts​

warehouse-infra has only the Kong-level alerts named above (5xx ratio, SLO burn, restarts). Because cmd/api exports no metrics, these are checks against its data stores and logs rather than PromQL:

SignalQuery or sourceWhy
Outbox backlogSELECT count(*), min(created_at) FROM outbox_events WHERE published_at IS NULL older than a few minutesthe relay is off, the broker is down or a row is stuck
Stuck outbox rowSELECT id, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts > 0 or the log line row reached the attempt capone event is blocked behind a persistent failure
Consumer lagKafka consumer-group lag of the three groups on their topicsa blocked partition or a stopped consumer
Dead lettersmessage count growth on the three .dlq topics, log lines dead-letteringproducers sending unusable payloads
Consumer stoppedlog consumer stopped or outbox relay stoppedthe loop ended and is not restarted
Server errorslog lines request failed and handler panickedevery 5xx is logged once
Boot loopsrepeated service exited with error / retryingdatabase unreachable or a bad migration
Open-request ageSELECT min(requested_at) FROM replenishment_requests WHERE state = 'Requested'requests that never complete (the chain is built end to end but not live; wes-work-planning plans nothing unless REPLENISHMENT_MODE=kafka is set there and the REPLENISH path is seeded, see Integration)

Adding real instruments (request duration, outbox backlog gauge, consumer outcome counters) would be a code change; this page documents the service as it is.