Repository navigation
feat(gateway): log one access line per proxied connection - #1589
Merged
Merged
Conversation
Seeing who connected to which app meant turning on the per-connection debug logs: about six lines per terminated connection plus a span entered on every poll, which costs 17% of the new-connection rate on a 4-core gateway. Emit a single `dstack_gateway::access` info line when a connection ends instead: client, peer, SNI, route, app, port, backend instance, bytes in/out, duration and outcome. It costs about 3% in the same benchmark and is on by default; `dstack_gateway::access=off` turns it off, leaving one level check per connection. Bytes come from TCP_INFO on a dup of the inbound socket, so the spliced and kTLS paths, whose payload never enters the process, are counted the same way as the userspace relay, failed connections included. For terminated connections they are TLS bytes on the wire. The glibc `tcp_info` fields need libc 0.2.189. `Proxy::proxy` takes the parsed `DstInfo` rather than its fields to stay under clippy's argument limit. Signed-off-by: Kevin Wang <wy721@qq.com>
Most proxied connections finish in a few milliseconds, where whole milliseconds round away most of the signal. Signed-off-by: Kevin Wang <wy721@qq.com>
The `conn` span is debug-level, so at the default level it is never created and the access line carries no id. Allocate the id for every connection and log it as `conn_id`, so the line can be matched with the same connection's debug logs when those are on. Signed-off-by: Kevin Wang <wy721@qq.com>
The access line had its own `conn_id` field because the `conn` span was
debug-level and absent by default. Make the span info-level instead, so
every log line a connection emits carries `conn{id=...}` and the access
line is the one place that names the app, SNI and backend. The span costs
about 1.5us of gateway CPU per connection (~1.5% of TLS-terminate CPS) on
the same 4-core benchmark.
Signed-off-by: Kevin Wang <wy721@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a default-on
dstack_gateway::accessinfo line, written once when each proxied connection ends:Today, seeing who connected to what means enabling the per-connection debug logs. Those emit about 6 lines per connection and enter a span on every poll. Disable this line with
RUST_LOG=info,dstack_gateway::access=off.TCP_INFOon a dup of the inbound socket. That covers the userspace, splice and kTLS relays, including failed connections. For terminated TLS they count wire bytes.instanceis the backend instance that won the connect race.tcp_infobyte fields.Benchmark (tdxlab, Docker; gateway 4 cores / 4 workers, nginx origin 4 cores,
wrk8 threads / 128 conns withConnection: close; TLS terminate; 20 s per variant, variants interleaved, 6 rounds, first round dropped as warm-up):connspan onlyThis is the worst case (tiny responses, one TLS handshake per request); the per-connection cost is ~10 µs, mostly the access line itself. For comparison the current debug logs cost ~20 µs per connection.
Tests:
cargo test -p dstack-gateway,test-run/e2eandtest-run/proxy-e2epass. For proxy-e2e,RUST_LOG=infowas set locally so the line could be checked. Across baseline/splice/kTLS arms it showed ~1 MiBbytes_outand the expected outcomes.