Skip to content

Rewrite/metrics gaps - #1233

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
rewrite/metrics-gaps
Apr 28, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
rewrite/metrics-gaps

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

No description provided.

Add 18 dedicated counters (`http.status.{200,201,204,301,302,304,400,401,
403,404,408,413,429,500,502,503,504,507}`) on top of the bucketed
`http.status.{1xx,…,5xx,other,none}` metrics already emitted by both
protocol stacks. The list covers Sōzu's default-answer codes (400/401/404/
408/413/502/503/504/507 and the 301 redirect) and the upstream codes
operators routinely chart.

The 18-code lookup lives in `lib/src/metrics/mod.rs` as a single
`http_status_code_metric_name(u16)` helper so H1
(`kawa_h1::save_http_status_metric`) and H2 (`mux::stream::generate_access_log`)
share one source of truth and cannot drift on which codes get a per-code
counter. Codes outside the short-list keep contributing to their bucket
only, so the metric keyspace stays bounded.

Closes part of #937 / #1146; full closure lands with the dedup commit and
the doc/CHANGELOG refresh that follows.

Signed-off-by: Florentin Dubois <[email protected]>
Replace the unlabeled `incr!("http.errors")` in
`kawa_h1::log_request_error` (`lib/src/protocol/kawa_h1/mod.rs:1049`) and
`mux::stream::generate_access_log` (`lib/src/protocol/mux/stream.rs:208`)
with a single labelled emission that carries `(cluster_id, backend_id)`.
The labels are filtered centrally by `metrics::filter_labels_for_detail`
according to the configured `metrics.detail` (default `cluster`), so:

- `process` / `frontend` collapse back to a proxy-wide counter — same
  visibility as today's unlabeled call,
- `cluster` (default) attributes errors per cluster,
- `backend` keeps the per-backend split.

Replacement, not addition. Earlier patches that added a labelled
emission alongside the unlabeled one would have double-counted
`http.errors` after central label filtering merged the two emissions
into the same key.

Update the unit coverage in `local_drain.rs` to use the dotted on-the-
wire metric name (`http.errors`) instead of the historical underscore
test fixture, and add a per-backend variant that mirrors the `backend`
detail path.

Closes part of #597; full closure lands with the doc/CHANGELOG refresh.

Signed-off-by: Florentin Dubois <[email protected]>
Sample frontend, slab, and buffer-pool utilisation once per run-loop
iteration, alongside the existing `process.uptime_seconds` /
`server.live` / `accept_queue.saturated_seconds` gauges. The block runs
in `Server::run` after the hourly drain reset, so all proxy gauges
advance in lock-step.

New gauges:

- `client.connections_max`     — replaces `client.max_connections`
- `client.connections_percent` — replaces `client.connections_percentage`
- `slab.capacity`              — `Slab::capacity()`
- `slab.usage_percent`         — `slab.entries / slab.capacity`
- `slab.accept_threshold_percent`
                                — `slab.entries / (10 + 2 * max_connections)`,
                                  the `SessionManager::at_capacity()` gate
                                  exposed as `accept_slab_threshold()`.
                                  Configured slab capacity can be larger
                                  when `slab_entries_per_connection > 2`,
                                  so this percent and `slab.usage_percent`
                                  are emitted as independent gauges.
- `buffer.in_use`              — replaces `buffer.number`. Still emitted
                                  on `Pool::checkout` and `Drop for Checkout`
                                  in `lib/src/pool.rs` for high-resolution
                                  visibility.
- `buffer.capacity`            — pool capacity from `pool.inner.capacity()`
- `buffer.usage_percent`       — `buffer.in_use / buffer.capacity`

`Server` gains a `pool: Rc<RefCell<Pool>>` field so the run loop can
sample buffer utilisation without a per-protocol indirection. The
constructor parameter was already a `Rc<RefCell<Pool>>` and was already
shared with the three protocol stacks via `pool.clone()`.

Per-event emission of `client.connections_percentage` /
`client.max_connections` from `SessionManager::incr/decr` is dropped;
the high-resolution `client.connections` signal is preserved. The
renamed gauges are all sampled at run-loop cadence anyway, so dashboards
that previously relied on per-event updates of the renamed pair would
have lost no resolution they actually used.

Documentation refresh:

- `doc/configure.md` — proxy gauge table updated, response-status table
  enumerates the eighteen per-code counters added by the previous commit.
- `doc/lifetime_of_a_session.md` — file:line citations and gauge names
  refreshed.
- `doc/observability.md` — `gauge!` example uses the new name.
- `doc/debugging_strategies.md` — pointer to the per-code counter list,
  rename note for `buffer.in_use`.
- `CHANGELOG.md` — `Added` and `Changed (potentially dashboard-breaking)`
  rows for the renames and new gauges, with closing references for
  #597 / #937 / #1146.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit ba02c5e into main Apr 28, 2026
26 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the rewrite/metrics-gaps branch April 28, 2026 17:11
jrcribb pushed a commit to jrcribb/sozu that referenced this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant