Documentation
¶
Overview ¶
Example 31_metrics_observability — GoGraph's observability surface, driven end-to-end over a realistic, seeded service-mesh call graph.
GoGraph instruments every public blocking API with a latency observation and a paired error/utilisation counter (docs/metrics.md). The whole surface is dark until a consumer installs a metrics.Backend: the public metrics.NewPrometheusRegistry + metrics.SetBackend facade activates dispatch and exposes the observations in Prometheus text-exposition format over an HTTP endpoint. This example is the one demonstration of that surface — the project mandates "latency histograms on every public blocking API", and this shows an operator how to turn them on, drive a mixed workload across subsystems, and scrape the result.
What it does ¶
- Installs a Prometheus registry as the global metrics backend (metrics.NewPrometheusRegistry + metrics.SetBackend), and restores the no-op default on exit so no global state leaks.
- Generates a seeded service-mesh call graph and materialises it into three representations that feed instrumented APIs.
- Runs a mixed workload that touches instrumented entry points across subsystems: - cypher.Engine.Run — a label-scan count, run twice so the plan cache records a miss then a hit; - cypher.Engine.RunInTx — a canary CREATE, its effect verified by a follow-up count; - search.Dijkstra — shortest-latency single-source paths over a CSR built from the call graph; - graph/io/csv — a WriteCtx + ReadIntoCtx round-trip; - bolt/packstream — an encoder acquired from and returned to the pooled EncodePool.
- Serves reg.Handler() over a local httptest server and GETs /metrics, exactly as an operator's Prometheus scrape would.
- Parses the exposition and reports, as deterministic FACT lines, whether every expected metric NAME is present (the schema <package-path>.<Symbol> from docs/metrics.md, rendered by the backend with dots mapped to underscores). The observed latencies and counts are volatile and reported as "# " telemetry.
Facts vs telemetry ¶
Metric NAMES are deterministic: a fixed workload always touches the same instrumented sites, so the presence facts are reproducible and pinned by the regression test. Metric VALUES (histogram sums and bucket counts, scrape byte size, wall-clock latency, live heap) vary per run and per machine, so they are emitted as "# "-prefixed telemetry and never pinned.
Scale ¶
Run with no flags, the example builds a small deterministic default — two hundred services with two-to-six downstream calls each — so the run is instant and the presence facts are pinned by the regression test. Every dimension is a flag, so the same binary scales up to a size where the latency histograms carry a meaningful distribution:
go run ./examples/31_metrics_observability -services 200000 -calls-max 12 -seed 7
The metric names are identical at every scale; only the "# " telemetry varies between runs and machines.