Skip to content

Improve metrics and access logs #937

Closed

Description

@FlorentinDUBOIS

Hello there 👋,

After some discussions with @StevenLeRoux, @BlackYoup and @Wonshtrum.
We found out that Sōzu need to provides a little more information about request and response.
So, I use this issue to make a summary of what we need.

Firstly, I will remember that we have to tackle the issue #641, #892 and #804.

What we already have

Access logs

Currently, when we handle request (TCP, HTTP[s] or WS[s]) will write following access logs.

01H0FXZVQK7RK3W55X7V26M259 TcpTest TcpTest-0-127.0.0.1:4000	127.0.0.1:52378 -> 127.0.0.1:4000	19ms 168μs 79 68522	owner=John, uuid=3f740af1-45fd-45ce-b61f-17bf1a51505f	TCP -
01H0FXX3VTR8T3B1K0ZHXQZZNQ MyCluster the-backend-to-my-app	127.0.0.1:50444 -> 127.0.0.1:1026	61ms 4959μs 79 68535	key=value	HTTPS-TLS1.3 lolcatho.st:8443 200	GET /

Below, an explanation of the above access logs:

request id cluster id backend id client socket address -> backend socket address response time service time bytes in bytes out metadata protocol hostname status verb path
01H0FXX3VTR8T3B1K0ZHXQZZNQ MyCluster the-backend-to-my-app 127.0.0.1:50444 -> 127.0.0.1:1026 61ms 4959μs 79 68535 key=value HTTPS-TLS1.3 lolcatho.st:8443 200 GET /
request id cluster id backend id client socket address -> backend socket address response time service time bytes in bytes out metadata protocol websocket context
01H0FXZVQK7RK3W55X7V26M259 TcpTest TcpTest-0-127.0.0.1:4000 127.0.0.1:52378 -> 127.0.0.1:4000 19ms 168μs 79 68522 owner=John, uuid=3f740af1-45fd-45ce-b61f-17bf1a51505f TCP -

response time : the total duration of the request
service time : the total duration that Sozu took to treat the request
websocket context: the value is - if the protocol is TCP

You can find the code source that output those logs here:

TCP or WS

info_access!(
"{}{} -> {}\t{} {} {} {}\t{}\t{} {}",
self.log_ctx,
session_addr,
backend,
LogDuration(response_time),
LogDuration(service_time),
metrics.bin,
metrics.bout,
OptionalString::from(tags.as_ref()),
proto,
self.websocket_context.as_deref().unwrap_or("-")
);

error_access!(
"{}{} -> {}\t{} {} {} {}\t{} {} | {}",
self.log_ctx,
session,
backend,
LogDuration(response_time),
LogDuration(service_time),
metrics.bin,
metrics.bout,
proto,
self.websocket_context.as_deref().unwrap_or("-"),
message
);

HTTP

info_access!(
"{}{} -> {}\t{} {} {} {}\t{}\t{} {} {}\t{}",
self.log_context(),
session,
backend,
LogDuration(response_time),
LogDuration(service_time),
metrics.bin,
metrics.bout,
OptionalString::from(tags.as_ref()),
proto,
host,
status_line,
request_line
);

info_access!(
"{}{} -> {}\t{} {} {} {}\t{}\t{} {} {}\t{}",
self.log_context(),
session,
backend,
LogDuration(response_time),
LogDuration(service_time),
metrics.bin,
metrics.bout,
OptionalString::from(tags.as_ref()),
proto,
host,
status_line,
request_line
);

error_access!(
"{}{} -> {}\t{} {} {} {}\t{} {} {}\t{} | {} {}",
self.log_context(),
session,
backend,
LogDuration(response_time),
LogDuration(service_time),
metrics.bin,
metrics.bout,
proto,
host,
request_line,
status_line,
message,
OptionalString::from(tags.as_ref())
);

Metrics

Today, we have a bunch of metrics and we do not use all of them.
We should investigate.
To do so, we have to:

  • make a proper list of metrics (classname+labels+kind+description).
  • Then, establish the cardinality of each one and segregate them in two parts:
    • The one that are Sōzu-related (event loop, worker, etc..)
    • The one that are cluster-related (status code, response time, service time, cluster response time, data transfer, etc..)
      • The cluster-related have to be labeled with the cluster identifier and optionaly the backend identifier.

What is missing

Access logs

To us, it miss some informations in access logs as :

  • client rtt: the time in millisecond to establish a connection between the client and Sōzu
  • server rtt: the time in millisecond to establish a connection between Sōzu and the backend
  • cluster response time: the time in millisecond between the end of the transfer of the request body and the response header betweend Sōzu and the backend
  • data transfer time: the total duration in millisecond of transfering data between the client to the backend and vice-versa
  • user-agent

Metrics

We should investigate first the item above.

Registry:


Update — 2026-04-24

Partial progress on feat/h2-mux (PR #1209). The original umbrella is broad; the items below are shipped on this branch, with the remainder still outstanding.

Access logs (request-scoped)

  • c9ec90cf feat(http): propagate x-request-id and log it on access log — Sōzu now preserves an inbound x-request-id header or injects one from the request ULID, forwards it to the backend, and records it in the x_request_id access-log field (ProtobufAccessLog tag 24). Counters: http.x_request_id.propagated and http.x_request_id.generated.
  • 29c3f834 feat(logging): surface TLS metadata and XFF chain on access logs — five additional access-log fields (ProtobufAccessLog tags 25–29) carry negotiated TLS metadata (version, cipher, SNI, ALPN) and the upstream-attested X-Forwarded-For chain, populated end-to-end on H1 and H2.
  • db7c33ec feat(h2): propagate OTel trace context from H2 headers to access logs — traceparent passthrough (W3C Trace Context) records trace identifiers in access logs when the opentelemetry feature is enabled (propagator only, no SDK or exporter).
  • Correlation header name is now configurable per listener (f76c5d5b feat(listener): configurable Sozu-Id correlation header name) — see also make Sozu-Id header field name configurable #1145.

Metrics correctness and documentation

  • deeba79c fix(metrics): restore missing backend metrics in mux layer
  • a650ad69 fix(mux): prevent gauge underflow and error counter inflation
  • 5f884551 fix(mux): fix service_time inflation, gauge leak, and WebSocket upgr...
  • 5a60da82 refactor(metrics): replace mem::uninitialized with MaybeUninit::zeroed
  • 868fc227 docs(metrics): comprehensive metrics, OpenTelemetry, and traces reference
  • f0127aa3 docs(configure): document 2 emitted-but-undocumented metrics, fix Op...
  • c0d03425 docs(configure): document h2.signal.writable.rearmed.* and ready_incremental gauge — new H2 scheduler-rearm counters and the h2.streams.ready_incremental.by_urgency gauge are now documented in doc/configure.md.

Severity classification

  • 07a83e92 fix(proxy): harmonise backend retry-budget-exhaustion log severity
  • 024390a1 docs(configure): classify TLS handshake log severities
  • 440a9ee1 chore(pipe): demote idle-timeout tear-downs from error! to debug!

Audit log (control plane, not request access log — moved out of scope but related)

The refactor(command): audit log series (2200fc2a, 0c2dc869, 53b51e03, 6b21c9c4, e7a5e29d) enriches the command-socket audit log (ucred, actor/role, timestamps, fanout, MUX Session(...) layout) and raises it to info!. This is the operator-action trail, distinct from the request access log above.

Still outstanding

  • Client/server RTT, cluster response time, data-transfer time, and user-agent fields in the request access log.
  • Metric registry + cardinality classification (the three checkboxes above).
  • Per-cluster/per-backend labelling for cluster-scoped metrics.

Keep this issue open; consider splitting the residual work (access-log fields, metric registry) into dedicated child issues once priorities are set.

Activity

  1. added this to the v0.16.0 milestone on May 16, 2023
  2. Wonshtrum commented on May 26, 2023

    @Wonshtrum
    Member

    The first draft can be found on the latest commit of #904.

  3. Keksoj commented on Jun 15, 2023

    @Keksoj

    In the spirit of the request counter of #947, we could keep track of how many access logs were produced. See #950

  4. Keksoj commented on Jun 16, 2023

    @Keksoj

    Oh and we should do something about this:

    Worker 0
    =========
    ┌──────────────────────┬───────┬───────┐
    │                      │ gauge │ count │
    ├──────────────────────┼───────┼───────┤
    │ accept_queue.count   │ 0     │       │
    ├──────────────────────┼───────┼───────┤
    │ buffer.count         │ 0     │       │
    ├──────────────────────┼───────┼───────┤
    │ bytes_in             │       │ 150   │
    ├──────────────────────┼───────┼───────┤
    │ bytes_out            │       │ 178   │
    ├──────────────────────┼───────┼───────┤
    │ client.connections   │ 0     │       │
    ├──────────────────────┼───────┼───────┤
    │ http.404.errors      │       │ 2     │
    ├──────────────────────┼───────┼───────┤
    │ http.active_requests │ 0     │       │
    ├──────────────────────┼───────┼───────┤
    │ http.requests        │       │ 2     │
    ├──────────────────────┼───────┼───────┤
    │ protocol.http        │ 0     │       │
    ├──────────────────────┼───────┼───────┤
    │ sent_access_logs     │       │ 2     │
    ├──────────────────────┼───────┼───────┤
    │ slab.count           │ 6     │       │
    └──────────────────────┴───────┴───────┘
    

    Notice that many .count are actually gauges. This is wrong.

  5. added 2 commits that reference this issue on Mar 8, 2026
    bfaf6c7
    d5438be
  6. FlorentinDUBOIS commented on May 2, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Status update — 2026-05-02 (HEAD = main @ 8c883bb5)

    PR #1209 (feat/h2-mux) merged into main on 2026-04-27, and the access-log + metrics commits referenced in my 2026-04-24 update above are now in main. The companion metrics-only PR #1196 (feat/metrics-gaps) was closed unmerged on 2026-04-28 because its scope had already been folded into the H2-mux series — its sub-issues #597, #1146 and #641 were closed on 2026-05-02. The original umbrella here can now be narrowed considerably; tracking what's left below.

    Already shipped on main

    Access-log fields (command/src/command.proto:1456+, ProtobufAccessLog tags 9–29):

    Field H1 (kawa_h1) H2 / mux Pipe (TCP/WS) TCP frontend
    client_rtt (tag 9) populated kawa_h1/mod.rs:1045 None — TODO at mux/stream.rs:289 populated pipe.rs:322 populated tcp.rs:282
    server_rtt (tag 10) populated kawa_h1/mod.rs:1046 None — TODO at mux/stream.rs:290 populated pipe.rs:323 None
    user_agent (tag 16) populated populated None None
    x_request_id (tag 24) populated populated n/a n/a
    tls_version/cipher/sni/alpn (tags 25–28) populated populated n/a n/a
    xff_chain (tag 29) populated populated n/a n/a
    traceparent (otel feature) populated populated n/a n/a

    Originating commits: ed1966e1 (x-request-id), 2e7d9434 (TLS+XFF), db7c33ec (OTel propagation), f76c5d5b (configurable correlation header — closes #1145).

    Metrics:

    Cluster + backend metric labelling is broader than the original umbrella suggested. The infrastructure (MetricDetailLevel::{Process,Frontend,Cluster,Backend} at command/src/config.rs:1116-1120, filter at lib/src/metrics/mod.rs:43) is in place and is consumed by the record_backend_metrics! macro at lib/src/metrics/mod.rs:474-490 (covers bytes_in, bytes_out, backend_response_time, backend_connection_time, requests), the http.errors and http.status.* counters, the default-answer counters in kawa_h1/mod.rs:1104-1165 and mux/answers.rs:224-239, plus the connections_per_backend / backend.up / backend.down / backend.connections.error / backend.connect.retries_exhausted family across tcp.rs:559-641,914-943, kawa_h1/mod.rs:1310-1333,1664-1742, mux/router.rs:119-123,479-518, mux/mod.rs:815-819,931-947,1704-1708, mux/connection.rs:380-385. request_time/service_time (lib.rs:1273-1275), frontend_matching_time (http.rs:665-666, https.rs:860-861) and access_logs.count (lib.rs:1293) are all cluster-labelled.

    Outstanding under this umbrella

    1. H2/mux access-log client_rtt / server_rtt. lib/src/protocol/mux/stream.rs:289-290 has the call wired but commented out (f27a449d). Mux Stream has no direct backend_socket field; the socket is reachable via Stream::state == StreamState::Linked(token) → Context.backend_streams (mux/mod.rs:342-350,471-486) → Router.backends: HashMap<Token, Connection<SessionTcpStream>> (mux/router.rs:70-72) → Connection::{H1,H2}.socket (mux/connection.rs:54-57, mux/h1.rs:108-115, mux/h2.rs:1251-1269). Deciding between per-stream snapshot and per-connection RTT, and plumbing that into Stream::generate_access_log, is the residual concrete work. This is the single largest visible asymmetry between H1 and H2 access logs today.

    2. data_transfer_time. Not in the schema. Current proxy is request_time - service_time. Needs a decision: add an explicit field (and a populator that subtracts the two), or document the derivation and leave it out.

    3. cluster_response_time. Maps semantically to backend_response_time, already emitted as a metric and as the response_time access-log field (tag 21) populated from metrics.backend_response_time() at mux/stream.rs:292 and kawa_h1/mod.rs:1048. If we want HAProxy-parity wording, that's a doc/alias decision in doc/configure.md, not new instrumentation.

    4. Cardinality classification table. The 137-metric reference at doc/configure.md lists metrics but doesn't yet present them as the explicit "Sōzu-related vs cluster-related" cardinality table the original issue called for. Doc work, not code.

    5. Per-cluster/backend label residual sweep. Most cluster-scoped metrics now carry labels (see infrastructure paragraph above). What remains is an audit pass to identify any cluster-scoped metric still emitted unlabelled. Likely a short list, not a wholesale conversion.

    Linked issues — re-checked against main

    • Write a log when backends are detected down or up. #892 (backend up/down log). Largely shipped: lib/src/health_check.rs:461-492 logs UP/DOWN transitions and emits health_check.up / health_check.down; server wires it at server.rs:889-890,1448-1457,1547. Retry-policy paths log transitions independently at tcp.rs:580-641, kawa_h1/mod.rs:1683-1742, mux/mod.rs:807-819,929-947. Probably closeable — proposing to close as completed once @StevenLeRoux / @BlackYoup confirm the existing log lines satisfy what they need.
    • Add some metrics (regex, lookup time) #804 (regex / lookup-time metrics). Partially shipped: regex_matching_time is emitted for domain and path regexes at lib/src/router/mod.rs:580-584,660-664; frontend_matching_time at http.rs:665-666 and https.rs:860-861. Only a dedicated router.lookup_time / non-regex matching-time metric is missing.

    Proposed next steps

    I'd like to close out this umbrella in two passes:

    1. A small follow-up MR for the H2/mux RTT lift (item 1 above) — single-purpose, matches H1/Pipe behavior, no schema change.
    2. A doc-only pass that maps response_time to the HAProxy cluster_response_time notion, presents the cardinality table (item 4), and decides on data_transfer_time either way (item 2).

    Once those land, the residual is just (5) — an audit pass — and the linked issues #892/#804 can be re-scoped to their respective small remnants. Happy to keep this issue open as the meta-tracker until those land, or split off a successor — whichever you prefer.

  7. FlorentinDUBOIS commented on May 5, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Closing — covered by #1245 (per-cluster availability + access-log timeout discriminator), #1242 (H2 client/server RTT on access log), #1225 (H2 flood/frame/error counters + TLS handshake + access-log enrichment), and #1233 (metrics gaps rewrite). Reopen for a specific gap still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions