Skip to content
147 changes: 120 additions & 27 deletions docs/rfcs/0001-template-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ runtime decision per leaf.
type-tag mechanism in §4.2 already requires a slot name; using the
Drain3 hint format keeps configs portable.
- **Built-in metrics surface.** Drain3 exposes a set of state
counters via callback. `replace` — Ourios exposes Prometheus
metrics directly per §6.8, with names that match `[§3.1]`'s
required set rather than Drain3's internal names.
counters via callback. `replace` — Ourios exposes OTel metrics
directly per §6.8 (instrumented via the meter API), with names that
match `[§3.1]`'s required set rather than Drain3's internal names.
- **Parameter masking after the fact.** Drain3 has utilities to
retroactively mask params in already-clustered lines. `reject` —
Ourios masks once, at ingest, deterministically. Retroactive
Expand Down Expand Up @@ -406,14 +406,16 @@ direction and the primary obligation lives in those other RFCs.

> **Scenario §3.1.2 — Mandatory metric set is exposed**
> - **Given** a running miner
> - **When** the Prometheus registry is enumerated
> - **Then** it contains every metric named in §6.8's table
> - **When** the miner's meter (`global::meter("ourios.miner")`) is
> collected via an SDK in-memory reader, at zero traffic
> - **Then** the collected metric stream contains every metric named
> in §6.8's table (each present via its init-seeded data point)
> (`template_count`, `merges_total`, `confidence`,
> `confidence_p50`, `confidence_p01`, `body_retention_ratio`,
> `parse_failures_total`, `params_overflow_total`,
> `params_overflow_ratio`, `template_version_changes_total`,
> `miner_latency_seconds`) with the types and labels listed
> there
> `miner_latency_seconds`) with the instrument kinds and
> attributes listed there

> **Scenario §3.2.1 — Default per-parameter byte limit is 256**
> - **Given** a tenant configuration with no per-parameter byte
Expand Down Expand Up @@ -557,12 +559,19 @@ direction and the primary obligation lives in those other RFCs.
> **Scenario RFC0001.8 — confidence_p50 and confidence_p01 are emitted as gauges**
> - **Given** a running miner with a non-empty `confidence`
> histogram for some `(tenant_id, service)`
> - **When** the Prometheus registry is scraped
> - **Then** `confidence_p50{tenant_id, service}` and
> `confidence_p01{tenant_id, service}` are present as gauges
> - **When** the miner's meter is collected via an SDK in-memory reader
> - **Then** `confidence_p50` and `confidence_p01` (attributes
> `tenant_id`, `service`) are present as gauges
> - **And** each value matches the corresponding quantile of the
> same-labelled histogram (computed in-process on a short
> same-attributed histogram (computed in-process on a short
> ticker per §6.8)
>
> *(Pending the §6.8 dotted-semconv redesign: this scenario may be
> superseded if `confidence_p50` / `confidence_p01` become
> backend-derived quantiles over the exported histogram rather than
> in-process gauges. The change is a contract change to the §3.1.2
> mandatory set and is made under that redesign's own review, not
> the 2026-06-03 architecture amendment.)*

> **Scenario RFC0001.9 — `body_kind = Structured` short-circuits to a structured-template id**
> - **Given** an `OtlpLogRecord` whose `body` is
Expand Down Expand Up @@ -1323,9 +1332,9 @@ any param has `type_tag == OVERFLOW`.

**Telemetry.** Two metrics for `[§3.2]` and hazard H2:

- `params_overflow_total` (counter, labelled `tenant_id`,
- `params_overflow_total` (counter, attributes `tenant_id`,
`service`): increments per overflow.
- `params_overflow_ratio` (gauge, labelled `tenant_id`,
- `params_overflow_ratio` (gauge, attributes `tenant_id`,
`service`): rolling overflow rate. Alert at `> 0.01` per service
per `[§3.2]`.

Expand Down Expand Up @@ -1472,9 +1481,90 @@ exactly the H5 detection signal.

### 6.8 Telemetry `[§3.1]`, §6.3

The metrics enumerated in `[§3.1]` are mandatory. Full set:

| Metric | Type | Labels | Source invariant / hazard |
> **Amendment 2026-06-03.** Telemetry export is realigned from a
> Prometheus client/scrape model to the **OpenTelemetry SDK** (the
> maintainer direction recorded against RFC 0009 §3.6 and the roadmap
> §5 note). This amendment fixes the *export architecture* and the
> Prometheus-era terminology (registry → meter provider, scrape →
> OTLP push, labels → attributes) throughout §§6.8–6.9 and the §5
> scenarios. It deliberately does **not** rename the metrics: the
> identifiers in the table below stay as-is, pending a dedicated
> dotted-semconv redesign that converts them to the
> `ourios.miner.*` scheme, adds them to the `semconv/registry/`
> weaver registry alongside the compaction set (RFC 0009 §3.6), and
> resolves the instrument-type and quantile questions that are
> genuine contract changes to the §3.1.2 mandatory set — including
> whether `confidence_p50` / `confidence_p01` remain in-process
> gauges (RFC0001.8) or become collector-/backend-derived quantiles
> over the exported histogram, the OTLP-native idiom. That redesign
> moves the mandatory-set contract under its own review rather than
> riding this architecture change.

#### Export architecture (OTel SDK + OTLP)

Metrics are instrumented through the OpenTelemetry **meter API** and
exported via the OTel SDK's **OTLP metric exporter** (push, over OTLP
to a collector / endpoint). There is no `prometheus` client crate and
no `/metrics` scrape endpoint; any Prometheus compatibility is a
downstream collector concern, not Ourios's.

The dependency split follows the standard OTel layering so the heavy
SDK and transport crates do not leak into every library:

- **Instrumented crates** (`ourios-miner`, `ourios-parquet`,
`ourios-ingester`, `ourios-querier`) depend only on the lightweight
`opentelemetry` **API** crate and resolve instruments through
`global::meter("ourios.<subsystem>")`. No SDK, no OTLP, no
transport dependency in a library crate.
- A new **`ourios-telemetry`** crate owns the heavy deps
(`opentelemetry_sdk`, `opentelemetry-otlp`, and the OTLP transport).
It exposes an `init()` that builds the OTLP push `MeterProvider`
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved
(periodic-reader export, interval configurable), installs it as the
process-global provider, and returns a guard whose `shutdown()`
flushes pending metrics on exit. The binary (`ourios-server`) calls
`init()` once at start-up; benches and integration tests call the
same entry point or substitute an in-memory reader. Adding this
crate extends the `CLAUDE.md` §7 target layout; the new-crate
commitment is blessed here, in this RFC, per §7's rule.

Dimensions are OTel **attributes**, not Prometheus labels, and OTel
splits them in two: **resource attributes** identify the telemetry
producer and are set once on the `MeterProvider`; **data-point
attributes** vary per measurement. Ourios's own identity —
`service.name = ourios-ingester` (with `service.version`, etc.) — is a
**resource attribute**: per the semantic conventions it MUST be set
once on the provider's `Resource` (by the `ourios-telemetry` crate)
and MUST NOT be repeated on individual data points.
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved

The per-measurement dimensions in the table below — `tenant_id` and
the originating **service** of the ingested logs — are **data-point
attributes**. A single ingester multiplexes many tenants and many
source services, and `[§3.1]` / `[§3.2]` require per-`(tenant,
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved
service)` breakdowns — notably the §6.5 / H2.2 *per-service* overflow
alert — which a single producer-level resource attribute could not
provide. This originating-service dimension is the *log's source*
service (the value §6.1's tenant derivation reads), **distinct from
Ourios's own `service.name`**; to avoid colliding with that reserved
resource key it is carried under a namespaced `ourios.*` attribute,
whose exact key is fixed by the deferred dotted-semconv redesign, not
here.
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved

OTel's metric model is **collect-on-read**: a reader / exporter sees
the data points produced during a collection cycle, not a registry of
instruments, and a synchronous instrument that has recorded no
measurement contributes no data point. To preserve §3.1.2's
"full mandatory set is exposed" guarantee even at zero traffic, the
miner **seeds each mandatory instrument with an initial zero-valued
measurement at init**, so every metric in the table below appears in
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved
every collection cycle regardless of traffic. Verification is
therefore by *collecting the metric stream* (an SDK in-memory reader
in tests), not by enumerating registered instruments.

The metrics enumerated in `[§3.1]` are mandatory. Full set (names and
instrument kinds pending the dotted-semconv redesign noted above; the
dimensions shown are exported as **attributes**, not labels):

| Metric | Type | Attributes | Source invariant / hazard |
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved
|---|---|---|---|
| `template_count` | gauge | `tenant_id` | `[§3.1]` |
| `merges_total` | counter | `tenant_id`, `event_type` | `[§3.1]`, H1 |
Expand All @@ -1494,7 +1584,7 @@ named views derived from it in-process. The miner recomputes them
on a short ticker (default 10 s, configurable; the cost is one
quantile evaluation over the histogram per tenant per service per
tick — negligible relative to the hot path) and caches the value
between ticks so a Prometheus scrape never blocks on
between ticks so a metric export cycle never blocks on
recomputation. The gauges exist so alerting rules and runbooks can
name them directly per `[§3.1]` rather than spelling out a
`histogram_quantile(...)` expression at every reference.
Expand Down Expand Up @@ -1530,11 +1620,12 @@ exactly as in live ingest, but updates to the §6.8 metrics are
suppressed (counters do not increment, histograms do not observe,
gauges retain their previous value or, if the miner has never
served live traffic, their zero / empty initialisation value). The
metrics themselves remain registered and visible to scrapes —
§3.1.2's invariant that the registry exposes the full §6.8 set
holds across replay; only the *update* path is gated, not the
*registration* path. A single `wal_replay_progress` gauge
(labelled `tenant_id`, value: fraction of the tenant's replay
instruments' init-seeded data points keep the full §6.8 set visible to
the exporter during replay — suppressing the *update* path leaves each
metric at its seeded / last value, so §3.1.2's "full set exposed"
invariant holds across replay without recording replay-window
measurements. A single `wal_replay_progress` gauge
(attribute `tenant_id`, value: fraction of the tenant's replay
window completed in `[0.0, 1.0]`) is exposed during replay so
operators can see the cold-start curve and confirm replay finished.
This metric is replay-only and is not part of the §3.1 mandatory
Expand Down Expand Up @@ -1709,11 +1800,13 @@ resolves bidirectionally between RFC and tests.
§3.2.1 (default param byte limit = 256),
§3.2.2 (limit > 1 KiB rejected).

- **Metrics registry test**: enumerate the Prometheus registry on
a freshly-initialised miner; assert the names, types, and labels
in §6.8's table are all present, and that the
`confidence_p50` / `confidence_p01` gauges track the
same-labelled `confidence` histogram quantiles.
- **Metrics registry test**: collect the miner's meter
Comment thread
jensholdgaard marked this conversation as resolved.
Resolved
(`global::meter("ourios.miner")`) of a freshly-initialised miner via
an SDK in-memory reader and assert the collected stream contains
every §6.8 metric name (each present via its init-seeded data
point), with the instrument kinds and attributes in §6.8's table,
and that the `confidence_p50` / `confidence_p01` gauges track the
same-attributed `confidence` histogram quantiles.
*Covers:* §3.1.2, RFC0001.8.

- **Data-model contract tests**: small unit tests against the
Expand Down
27 changes: 15 additions & 12 deletions docs/rfcs/0008-wal.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,15 +876,17 @@ durability silently is worse than running out of disk loudly.
- `wal_recovery_seconds: Gauge` (set once at startup).
- `wal_corrupt_frames_total: u64` — RFC0008.5 surface.

Per `docs/roadmap.md` §5's 2026-05-19 maintainer note
("instrument via OpenTelemetry metric meters, *not* the
legacy `prometheus` client crate; Prometheus scrape
compatibility is delivered via the OTel
`opentelemetry-prometheus` exporter so the project stays one
metric-model end-to-end"), these are OTel meters; the
`CLAUDE.md` §6.3 "every subsystem exposes Prometheus
metrics" line predates that direction and the §5 note
flagged it for a follow-up amendment.
Per `docs/roadmap.md` §5's maintainer note (2026-05-19,
updated 2026-06-03: "instrument through the OpenTelemetry
metrics API (meters) and export via the OTel SDK's OTLP
metric exporter (push), *not* the legacy `prometheus` client
crate and *not* a scrape endpoint; any Prometheus
compatibility is a downstream collector concern"), these are
OTel metrics exported over OTLP; the `CLAUDE.md` §6.3 "every subsystem
exposes Prometheus metrics" line predates that direction and
the note flagged it for a follow-up amendment. RFC 0001 §6.8
(2026-06-03 amendment) is the normative reference for the
export architecture.

### 6.9 WAL-tunables classification

Expand Down Expand Up @@ -1232,9 +1234,10 @@ runs on every PR regardless of which files changed — `H3`'s
that lands with the post-MVP `ourios-wal` crate; until
then audit-event durability is in-memory and the corpus
bench accepts that").
- `docs/roadmap.md` §5 — the 2026-05-19 maintainer note
pinning OTel meters (not direct Prometheus) as the
metrics surface; the §6.8 instrumentation cites it.
- `docs/roadmap.md` §5 — the maintainer note (2026-05-19,
updated 2026-06-03) pinning OTel metrics (via meters) + OTLP
export (not direct Prometheus, not a scrape endpoint) as the metrics
surface; the §6.8 instrumentation cites it.
- *PostgreSQL WAL design notes* — informed the
segment-rotation + checkpoint-truncation pattern.
- *LMDB B+tree on a memory-mapped file* — informed the
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ is *"answering 'does the thesis hold?' doesn't require it,"* not
| **Write-ahead log** (`ourios-wal`) | Corpus replay is bounded and reproducible; durability is irrelevant for thesis-proving | First post-MVP shipping PR series — required before any non-corpus traffic |
| **OTLP wire endpoints** (gRPC + HTTP listeners) | Bench reads OTLP from disk, not the network — see Phase 3. The wire-decode layer (`tonic`, `axum`, `opentelemetry-proto`) is independent of the record shape and adds no signal to thesis gates | First post-MVP shipping PR series — paired with WAL since both gate non-corpus ingest. RFC 0003 (forthcoming) specifies the wire-decode design |
| **Snapshot mechanism** (RFC 0001 §6.9) | Corpus runs from cold start; replay budget moot | After WAL — snapshots are an optimisation on top of WAL replay |
| **Full §6.8 telemetry surface** | One or two metrics suffice for the bench; the §3.1.2 mandatory set is a production observability concern | After Phase 1 finishes — the metrics depend on the miner's hot path being final. Implementation note (maintainer direction, 2026-05-19): instrument via **OpenTelemetry metric meters**, *not* the legacy `prometheus` client crate. Prometheus scrape compatibility is delivered via the OTel `opentelemetry-prometheus` exporter so the project stays one metric-model end-to-end. Affects the §6.8 RFC wording (a follow-up amendment swaps "Prometheus gauge/counter" for "OTel meters + Prometheus exporter") |
| **Full §6.8 telemetry surface** | One or two metrics suffice for the bench; the §3.1.2 mandatory set is a production observability concern | After Phase 1 finishes — the metrics depend on the miner's hot path being final. Implementation note (maintainer direction, 2026-05-19, **updated 2026-06-03**): instrument through the **OpenTelemetry metrics API** (meters create the instruments) and export the resulting metrics through the OTel SDK's **OTLP metric exporter** (push), *not* the legacy `prometheus` client crate and *not* a `/metrics` scrape endpoint — any Prometheus compatibility is a downstream collector concern, keeping the project one metric-model end-to-end. The RFC 0001 §6.8 architecture amendment (2026-06-03) reframes the export model and terminology; the dotted-semconv name redesign (joining `semconv/registry/`, RFC 0009 §3.6) is a tracked follow-up |
| **Query DSL** (RFC 0002) | Raw SQL through DataFusion serves the bench; DSL is operator UX | Post-MVP — RFC 0002 already drafted but not specified |
| **Multi-tenancy at runtime** (rate limits, eviction, lifecycle) | Bench uses one tenant; the type is in place but no orchestration around it | Post-MVP, tied to operator-console RFC (see RFC 0001 §9 *"Multi-tenancy and operational lifecycle"*) |
| **`ourios-server` binary + Helm chart** | Bench is a binary in `ourios-bench`; full deployment shape is shipping concern | Post-MVP, sequencing TBD |
Expand Down
Loading