fix: count transport-layer failures in per-host statistics#2203
Merged
mre merged 1 commit intoJun 2, 2026
Merged
Conversation
19b09ad to
ad02a69
Compare
The per-host `HostStats` aggregator only updated counters when an HTTP response was received. Requests that failed before reaching the server (DNS, TCP, TLS, connection reset, etc.) returned early from `perform_request` and never reached `update_stats`, so they were invisible to `total_requests` and the error buckets. A host whose only failures were network errors reported 100% success even when the top-of-report `ResponseStats` recorded errors against it. Add a `network_errors` counter on `HostStats` and a `record_network_error` method. Call it from the `Err` arm of `perform_request` so the failure contributes to `total_requests` and to the success-rate denominator. Surface the new counter in the markdown table (new column), in the detailed text output (line shown when non-zero), in the JSON serialization, and in `error_rate`. The compact output is unchanged; its success-rate column already reflects the corrected math. Closes lycheeverse#2202
ad02a69 to
dbaf216
Compare
thomas-zahner
approved these changes
May 22, 2026
thomas-zahner
left a comment
Member
There was a problem hiding this comment.
@afalhambra-hivemq Awesome 🚀
@mre any additional thoughts?
Contributor
Author
Thanks @thomas-zahner! @mre - do you mind having a look at it? Thanks as well |
Souradip121
reviewed
Jun 2, 2026
Souradip121
reviewed
Jun 2, 2026
Souradip121
left a comment
There was a problem hiding this comment.
@mre, @afalhambra-hivemq what do you think of this??
Member
|
Looks good to me. Thanks for the contribution @afalhambra-hivemq. ⭐ |
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.
Fixes #2202.
Problem
The per-host statistics table reports an inaccurate success rate for hosts whose links fail at the transport layer (DNS lookup, TCP connect, TLS handshake, connection reset, etc.). Those failures returned early from
Host::perform_requestand never reachedupdate_stats, so they were invisible tototal_requestsand to every error bucket. In a real run the top-of-reportResponseStatsflagged twokubernetes.ioerrors while the per-host table reportedkubernetes.io | 74 requests | 100.0% successfor the same host.Full root-cause analysis with code references in #2202.
Change
Add a
network_errorscounter onHostStatsand a correspondingrecord_network_errormethod, then call it from theErrarm ofHost::perform_request. The failed request now contributes tototal_requests(so the success-rate denominator is correct) and to a dedicatednetwork_errorsbucket (so the failure mode is visible in the output).Surfaces touched:
HostStatsfield + recording method + updatederror_rate.Serializeimpl: addsnetwork_errorsto the JSON output.Network Errorscolumn on the per-host table.network_errors > 0(mirrors the existing pattern forclient_errors/server_errors).% successcolumn already reflects the corrected math, and adding a column to its rigid one-line layout would be intrusive. Happy to add it if you'd prefer consistency across all three formatters.Before (current):
After:
Tests
test_record_network_error_affects_totals_and_success_rateinlychee-lib/src/ratelimit/host/stats.rsasserts that a network error incrementstotal_requestsandnetwork_errors, leaves the HTTP-status buckets untouched, and lowers the success rate accordingly.lychee-bin/src/formatters/stats/json.rsupdated to include the new field.Verification
cargo test --workspace --all-targets: 534 passed, 0 failed.make lint(workspace clippy): clean.cargo clippy --workspace --no-deps -- -D warnings: clean.