Skip to content

feat: add per-status-code HTTP metrics and buffer pool gauges - #1196

Closed
FlorentinDUBOIS wants to merge 3 commits into
mainfrom
feat/metrics-gaps
Closed

FlorentinDUBOIS wants to merge 3 commits into
mainfrom
feat/metrics-gaps

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Summary

  • Per-status-code tracking for 18 common HTTP codes as http.status.{code} metrics
  • Per-cluster/backend http.errors counter for error aggregation
  • buffer.used and buffer.capacity gauges emitted each event loop iteration
  • 2 new tests in local_drain.rs for metric aggregation

Review fixes applied

  • Added missing 507 status code (Sozu generates Answer507 but tracker omitted it)
  • Formatting cleanup

Closes #937, closes #597, closes #1146

Test plan

  • cargo test --workspace passes (2 new tests)
  • cargo clippy --workspace clean
  • E2e tests pass (20/20)

Comment thread lib/src/server.rs
Comment on lines +595 to +602
gauge!("client.connections", nb_connections);
gauge!("client.connections_max", max_connections);
if max_connections > 0 {
gauge!(
"client.connections_percent",
nb_connections * 100 / max_connections
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Yes, PR #1189 added connections_percentage and max_connections in SessionManager::incr()/decr().

I've rebased onto main and consolidated: removed the per-change-event gauges from #1189 and kept the event-loop versions with consistent naming (connections_max, connections_percent). This way all resource gauges (connections, slab, buffer pool) are emitted together each iteration, with division-by-zero guards.

FlorentinDUBOIS added a commit that referenced this pull request Mar 14, 2026
Supersede PR #1189's per-change gauges (connections_percentage,
max_connections) with event-loop-emitted versions using consistent
naming (connections_max, connections_percent). All resource gauges
(connections, slab, buffer pool) are now emitted together each
iteration with division-by-zero guards.

Addresses llenotre's review comment on PR #1196.

Signed-off-by: Florentin Dubois <[email protected]>
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

Copy link
Copy Markdown
Collaborator Author

closes with #1233

FlorentinDUBOIS added a commit that referenced this pull request May 2, 2026
The CHANGELOG previously carried three concurrent Unreleased blocks —
`## [Unreleased]` (main-scoped post-1.1.1 fixes from PRs #1162, #1191, #1192,
#1193, #1194, #1196, #1202, #1223), `## feat/answer-templates-rewrite-auth -
Unreleased` (answer templates, URL rewrite, basic auth), and
`## feat/h2-mux - Unreleased` (the H2 multiplexer rewrite from PR #1209). All
three feature stacks are on `main`; the per-branch dividers were release-
engineering staging that no longer reflects current state.

Changes:
- Drop the `## feat/answer-templates-rewrite-auth - Unreleased` and
  `## feat/h2-mux - Unreleased` dividers; their bodies now appear under
  `## [Unreleased]` with provenance markers (`### Added — Answer templates / ...`,
  `### Added — H2 multiplexer (PR #1209)`).
- Promote the breaking changes (proto-tag renumbers, dashboard metric renames,
  `http.errors` labelling, pattern-trie regex anchoring, empty-val del-header
  semantic, sub-16393 `buffer_size` rejection, cipher-list constant rename) to
  a top-level `### Breaking changes (v1.1.x → v2.0.0)` paragraph at the top of
  the section so operators see them first.
- Drop emoji from top-level subheaders (🌟 → Added, 🔄 → Changed, ⛑️ → Fixed,
  ✍️ → Changed, 📚 → Documentation, 🤖 → CI, ⚠️ → Behaviour-affecting). Per-
  commit-log subsection at depth ≥ 4 keeps minor emoji ornaments where they
  don't conflict with Keep-a-Changelog vocabulary.
- Preserve historical release entries (`## 1.1.1`, `## 1.1.0`, …) verbatim;
  they are released and immutable.

Net effect: a single `## [Unreleased]` block ready for the v2.0.0 release-cut
in §3.4.c of `tasks/todo.md`. Future passes can de-duplicate the multiple
`### Added`/`### Changed`/`### Fixed` sub-blocks into one each per
Keep-a-Changelog strict shape; this commit is the structural collapse only.

Refs: tasks/todo.md §3.1.a; codex M12 amendment (3-way not 2-way collapse).
Signed-off-by: Florentin Dubois <[email protected]>
jrcribb pushed a commit to jrcribb/sozu that referenced this pull request Aug 10, 2026
The CHANGELOG previously carried three concurrent Unreleased blocks —
`## [Unreleased]` (main-scoped post-1.1.1 fixes from PRs sozu-proxy#1162, sozu-proxy#1191, sozu-proxy#1192,
sozu-proxy#1193, sozu-proxy#1194, sozu-proxy#1196, sozu-proxy#1202, sozu-proxy#1223), `## feat/answer-templates-rewrite-auth -
Unreleased` (answer templates, URL rewrite, basic auth), and
`## feat/h2-mux - Unreleased` (the H2 multiplexer rewrite from PR sozu-proxy#1209). All
three feature stacks are on `main`; the per-branch dividers were release-
engineering staging that no longer reflects current state.

Changes:
- Drop the `## feat/answer-templates-rewrite-auth - Unreleased` and
  `## feat/h2-mux - Unreleased` dividers; their bodies now appear under
  `## [Unreleased]` with provenance markers (`### Added — Answer templates / ...`,
  `### Added — H2 multiplexer (PR sozu-proxy#1209)`).
- Promote the breaking changes (proto-tag renumbers, dashboard metric renames,
  `http.errors` labelling, pattern-trie regex anchoring, empty-val del-header
  semantic, sub-16393 `buffer_size` rejection, cipher-list constant rename) to
  a top-level `### Breaking changes (v1.1.x → v2.0.0)` paragraph at the top of
  the section so operators see them first.
- Drop emoji from top-level subheaders (🌟 → Added, 🔄 → Changed, ⛑️ → Fixed,
  ✍️ → Changed, 📚 → Documentation, 🤖 → CI, ⚠️ → Behaviour-affecting). Per-
  commit-log subsection at depth ≥ 4 keeps minor emoji ornaments where they
  don't conflict with Keep-a-Changelog vocabulary.
- Preserve historical release entries (`## 1.1.1`, `## 1.1.0`, …) verbatim;
  they are released and immutable.

Net effect: a single `## [Unreleased]` block ready for the v2.0.0 release-cut
in §3.4.c of `tasks/todo.md`. Future passes can de-duplicate the multiple
`### Added`/`### Changed`/`### Fixed` sub-blocks into one each per
Keep-a-Changelog strict shape; this commit is the structural collapse only.

Refs: tasks/todo.md §3.1.a; codex M12 amendment (3-way not 2-way collapse).
Signed-off-by: Florentin Dubois <[email protected]>
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.

Metrics related to Http status code Improve metrics and access logs add metrics for backend servers

2 participants