Skip to main content

Module http_request_metrics

Module http_request_metrics 

Source
Expand description

HTTP request/error volume counters for operational telemetry.

Issue #1239 / PRD #1237 Phase A, against the Phase-0 substrate contract (ADR 0060). Every handled HTTP request increments a single counter keyed by three bounded dimensions:

  • method — the request method, folded to the closed HTTP verb set (GET/POST/…); anything outside it collapses to OTHER.
  • route — the matched route template (/catalog/collections/:name), never the raw path. Requests that match no catalog route collapse to the reserved __unmatched__ bucket. The normalization is the caller’s job (it needs the route catalog); this module only stores the label.
  • status — the HTTP status class (2xx/4xx/5xx/…) per ADR 0060 §4, which keeps the status dimension at ≤6 values instead of the full code space.

Because all three label components are &'static str (verb labels, catalog route templates, and status-class strings are all static), the key set is bounded by construction: the product of the closed verb set, the static route table, and the six status classes. No raw path, id, query string, tenant value, or authorization material is ever admitted as a label — the caller passes pre-normalized static strings.

The counter is a plain Mutex<HashMap>; HTTP request dispatch is not a lock-contention-sensitive hot path at this granularity, and the bounded key set keeps the map small. The substrate read model and the /metrics exporter both read HttpRequestMetrics::snapshot.

Structs§

HttpRequestLabels
One bounded label set for a recorded HTTP request. Every component is &'static str so the cardinality of the key space is fixed at compile time (closed verb set × static route table × status classes).
HttpRequestMetrics

Constants§

OTHER_METHOD
Reserved method label for any verb outside the closed HTTP set.
UNMATCHED_ROUTE
Reserved route label for any request that matched no catalog route. Folding to a single bucket is what keeps raw 404 paths from blowing up the route dimension (ADR 0060 §4 overflow rule).

Functions§

method_label
Fold a request method to its bounded static label. The closed HTTP verb set maps to its canonical upper-case label; anything else collapses to OTHER_METHOD so a hostile/unknown verb cannot open a new series.
status_class
Map an HTTP status code to its bounded status class. Per ADR 0060 §4 the class (2xx/4xx/5xx/…) is preferred over the exact code so the status dimension stays at ≤6 values.