M5-S1 — Health and metrics
Section titled “M5-S1 — Health and metrics”| Module | M5 — Observe |
| After this session you can | Say from its health endpoints which application in a pod is not up, scrape every metrics endpoint of the release into Prometheus, and write the alerts that matter. |
| Time | Facilitated: 43 min · On your own: 43 min |
| Before you start | M4-S3: the release healthy after the restore. About 1 GB of spare memory for Prometheus. |
| Go deeper | Observability · Observability: the admin port · Runbooks: triage metrics and health |
◆ Orientation (1 min) — See it before the users do
Section titled “◆ Orientation (1 min) — See it before the users do”So far you learned about problems when a command failed or a page did not load. In production you want to know first: a pod that is up but not ready, a queue that keeps growing, a transport quietly falling back. Osos exposes health and metrics on every workload; this session shows where, what they mean, and which ones deserve to wake someone up.
▤ Concept (6 min) — Health, metrics and what to alert on
Section titled “▤ Concept (6 min) — Health, metrics and what to alert on”Health: ready is not the same as alive
Section titled “Health: ready is not the same as alive”Kubernetes asks each pod two questions: are you ready for traffic (readiness), and are you alive at all (liveness). Osos answers them differently by shape:
| Workload | Readiness | Liveness | Where |
|---|---|---|---|
Combined pods (core-rest, core-data) | GET /healthz: 200 only when every hosted application is up; the body lists each application’s state. Also the start-up probe (up to 150 seconds). | GET /livez: 200 while the process serves, whatever one application’s state | The admin port, core.adminPort (9900) |
| Standalone services (identity, storage, and others) | GET /api/ready, checking the database, bus and Redis connections the service uses | GET /api/live | The service port, 3000 |
For a combined pod the difference matters. Readiness is the aggregate: one half-started
application takes the whole pod out of its Services, because serving some requests from a pod that is
not fully up is worse than serving none. Liveness is the process only, so one sick application
never restarts the pod and its healthy neighbours with it. /livez at 200 while /healthz answers
503 is the system working as designed: read the /healthz body to see which application is not up.
Metrics: where they are
Section titled “Metrics: where they are”All metrics are in Prometheus format. Each workload tells Prometheus where to find them through its
pod annotations (prometheus.io/scrape, path, port), so a Prometheus that follows annotations
finds them all without configuration:
| Workload | Endpoint |
|---|---|
| Combined pods | The admin port’s /metrics (process metrics and the in-process transport); each hosted application also serves its own /api/<app>/metrics on its own port |
| Standalone HTTP services | Their metrics path on port 3000 (read it from the annotations) |
| Workers without an HTTP server (indexing, notification) | /metrics on metrics.port, 9100 |
| Directory importers and other batch jobs | Pushed to a Pushgateway when metrics.pushgatewayUrl is set |
If your cluster runs the Prometheus Operator, the chart also renders a ServiceMonitor for the combined
pods and switches their annotations off, so they are not scraped twice. Every metric carries a
service label naming the application.
The gateway exposes Prometheus metrics too, on its status listener (port 8007); add it as a scrape
target alongside the annotated pods. Its plugins’ per-request timings also go to the gateway’s log at
the info level. The scheduler has no HTTP health endpoint (its probes are off in the chart): watch it
through its metrics and its log instead.
What deserves an alert
Section titled “What deserves an alert”| Signal | Alert when | Why |
|---|---|---|
| Readiness of any release pod | Not ready for more than five minutes | Users are, or will be, affected |
core_inproc_dispatch_total{outcome="fallback"} | Above zero | The in-process transport hit a fault and quietly retried over the network: invisible to users, so only this alert shows it |
osos_queue_depth (indexing, port 9100) | Growing for 15 minutes (max by (queue), not sum) | A search-index backlog |
| Dead-letter queue depth in RabbitMQ | Above zero | Work that failed every retry is waiting for you (M7) |
osos_scheduled_jobs_total{status="failed"} | Increasing | Scheduled work is failing |
http_request_duration_seconds with status_code 5xx | Error rate above your baseline | Applications are failing requests |
osos_import_runs_total, osos_import_records_synced_total | No successful run in two schedules | The directory import is silently failing (M4-S2) |
Keep cardinality bounded
Section titled “Keep cardinality bounded”A metric with a label per space, per reaction or per entity can grow without limit and exhaust
Prometheus. The platform caps every metric at metrics.maxSeries (5000) label combinations: beyond
that, new combinations collapse into one series whose labels all read __over_limit__, and the
service logs Metric cardinality cap reached once. When you see it, do not just raise the cap: drop
the noisy labels with metrics.spaceIdLabelEnabled: false or metrics.idLabelsEnabled: false.
⛏ Lab (30 min) — Read the health, scrape the metrics
Section titled “⛏ Lab (30 min) — Read the health, scrape the metrics”Goal. You have read the health of both shapes, found each kind of metrics endpoint, and scraped the release with a Prometheus running in the lab cluster.
Before you start. The release healthy. Each port-forward runs in its own terminal; stop it with Ctrl+C when the step is done.
Health
- Port-forward the admin port of
core-rest:kubectl -n northwind port-forward deploy/nw-osos-core-rest 9900:9900. - In another terminal:
curl -s localhost:9900/healthzandcurl -s localhost:9900/livez. Note which applications/healthzlists, and their states. - Read how Kubernetes uses them:
kubectl -n northwind get deploy nw-osos-core-rest -o jsonpath='{.spec.template.spec.containers[0].readinessProbe}', then the same withlivenessProbeandstartupProbe.
Metrics endpoints
- On the same port-forward:
curl -s localhost:9900/metrics | grep core_inproc_dispatch_total | head. Is the transport in use? Is anyoutcome="fallback"series above zero? - Find a standalone service’s endpoint from its annotations:
kubectl -n northwind get pod -l app=osos-identity -o jsonpath='{.items[0].metadata.annotations}'. - Port-forward the indexing worker’s metrics port
(
kubectl -n northwind port-forward deploy/nw-osos-indexing 9100:9100) and runcurl -s localhost:9100/metrics | grep osos_queue_depth.
Prometheus
-
Install a small Prometheus that follows pod annotations:
Terminal window helm repo add prometheus-community https://prometheus-community.github.io/helm-chartshelm install prom prometheus-community/prometheus -n monitoring --create-namespace \--set alertmanager.enabled=false --set prometheus-pushgateway.enabled=false \--set prometheus-node-exporter.enabled=false --set kube-state-metrics.enabled=false -
When it is ready, port-forward it:
kubectl -n monitoring port-forward svc/prom-prometheus-server 9090:80, and openhttp://localhost:9090. -
In Status › Targets, find the release’s pods. Then run these queries in the query box:
up{kubernetes_namespace="northwind"},core_inproc_dispatch_totalandmax by (queue) (osos_queue_depth).Screenshot pending Prometheus Targets page listing the northwind release's pods under the kubernetes-pods job, each with state UP What to notice: the combined pods appear once each, on the admin port 9900, and the workers on port 9100; nothing was configured per target.
-
Write two alert expressions in
inventory.md, in PromQL: one for the transport fallback and one for a growing indexing backlog.
Check.
- You recorded
/healthzand/livezanswers forcore-rest, and which probe uses each. - You can say whether the in-process transport is in use, and whether any fallback occurred.
- You found the identity service’s metrics path and port from its annotations.
-
osos_queue_depthappeared on the indexing worker’s port9100. - Prometheus shows the release’s pods as targets, and
upis1for them. - Your two alert expressions are written down.
Pass condition. All six checks hold.
If something goes wrong
| What you see | What to do |
|---|---|
| The port-forward fails with “unable to listen” | Something already uses that port on your computer; pick another local port, for example 19900:9900. |
/healthz answers 503 | Read its body: it names the application that is not up. Check that pod’s logs for that application. |
No core_inproc_dispatch_total lines at all | The transport has not dispatched anything yet; use the portal for a minute and look again. Absence means “not in use”, not “healthy”. |
Prometheus pods stay Pending | The lab is short of memory. Scale nothing of the release down; stop other programs, or give Docker more memory. |
| No release targets in Prometheus | Check the pods carry prometheus.io/scrape: "true"; with no Prometheus Operator in the lab, they should. |
Model answer
-
/healthzoncore-restanswers200with each hosted application (audit, notification-api, reaction, dependency, comments, timeline, workflow, logging, packaging, functions) in the stateup;/livezanswers200with"status": "alive"and the number of applications. The start-up and readiness probes call/healthz; the liveness probe calls/livez. -
After using the portal,
core_inproc_dispatch_totalshows series withoutcome="ok": the transport is in use. Nofallbackseries should be above zero. -
Alert expressions, for example:
sum(increase(core_inproc_dispatch_total{outcome="fallback"}[10m])) > 0max by (queue) (deriv(osos_queue_depth[15m])) > 0 and max by (queue) (osos_queue_depth) > 100Choose the threshold from your own baseline; 100 waiting jobs is a starting point for a small tenant.
✓ Practice (5 min) — Check your understanding
Section titled “✓ Practice (5 min) — Check your understanding”core-rest shows 0/1 ready but is never restarted. /livez answers 200. What do you do?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
Why alert on core_inproc_dispatch_total{outcome="fallback"} when users see no errors?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
A dashboard of reaction metrics shows one series whose labels all read __over_limit__. What does it
mean, and what do you do?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
You run three indexing replicas. Which query shows the real search-index backlog per queue?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
↺ Recap (1 min) — Health and metrics you can read
Section titled “↺ Recap (1 min) — Health and metrics you can read”You can read the health of both shapes and tell readiness from liveness, find every metrics endpoint and scrape it, and name the alerts that matter, with cardinality kept in check.
Next. In M5-S2 you follow one request through the logs of every service it touched, set up error reporting, and learn what the platform keeps, and for how long.