Skip to content

fix(udp-core): [#2505] count only IPs over the limit as banned and refresh the total on reset - #2524

Merged
josecelano merged 34 commits into
torrust:developfrom
josecelano:2505-udp-banned-ips-metric
Oct 14, 2026
Merged

josecelano merged 34 commits into
torrust:developfrom
josecelano:2505-udp-banned-ips-metric

Conversation

@josecelano

@josecelano josecelano commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Closes #2505

Summary

The UDP "banned IPs" metric (udp_tracker_server_ips_banned_total in Prometheus, udp_banned_ips_total in the REST stats) counted every IP that had sent at least one invalid connection ID, and the periodic ban reset never updated it, so it went stale. This PR makes it count only IPs whose connection ID errors exceed the limit and publishes the new total on every reset. The specification was reviewed and merged in #2506.

Changes

  • udp-core (BanService): the banned total is a counter maintained when an IP's error count reaches limit + 1 and cleared by reset_bans(), so it is O(1) on every invalid-connection-ID event (AC7). The per-IP count stops at u32::MAX instead of wrapping, so an IP is never counted twice.
  • udp-core refactor: the unused BanningStats trait (an SI-30 leftover) and the write-only last_connection_id_errors_reset field are removed in their own commit, before the fix.
  • udp-server: new banning::reset_bans resets the ban service and publishes the new total through the existing gauge helper. Both it and the banning event handler hold a dedicated banning::PublicationOrder mutex (owned by the udp-server container) across the ban change and the gauge write, so a reset and a concurrent error cannot publish out of order. They release the ban lock before the gauge write, so the launcher's per-datagram ban check in strict mode never waits for the statistics store. The publication error message names the gauge.
  • Root crate: the periodic ban cleanup job calls udp-server's reset_bans instead of resetting the service directly.
  • Docs: the metric description, Metrics::udp_banned_ips_total, the REST field, and BanService::get_banned_ips_total now describe the meaning, including disabled validation mode, where these IPs are "would-be banned" and not blocked (maintainer decision A).
  • Benchmark: new Criterion group udp_ban_service/record_error for the per-event step.
  • Dev-dependency: quickcheck 1 (default-features = false) for udp-core's property test; it was already in Cargo.lock through udp-protocol.

Tests

Test Layer Guards
R1 (4 cases) udp-core unit Only IPs over the limit are counted; the two below-limit cases are red on develop, the two over-limit cases are proven by mutate-then-restore
R1p udp-core property (quickcheck) Total equals an independent model of per-IP counts for any errors and resets
R2 (3 cases) udp-core unit Total after a reset, re-crossing after a reset, and an IP that stays within the limit after a reset; the below-limit case is red on develop, the other two are proven by mutate-then-restore
R3 udp-server unit reset_bans publishes the new total
R4 root unit, paused Tokio clock The cleanup job publishes after a reset; red on develop
R5, R6 udp-server contract tests (strict and disabled) The published gauge through the real server; below-limit cases red on develop
Publication order (4) udp-server unit The handler and reset_bans hold the publication order until the gauge is written and do not hold the ban lock while waiting for the statistics store; red with the ban lock held. They take the statistics lock through a test-only Repository::write_lock_for_test seam, so #2517 can make the stats field private
Count overflow (2) udp-core unit A count at u32::MAX never crosses the limit again; fail for the wrapping and saturating variants

The udp-server handler and listener tests that asserted the old distinct-IP count were updated in the same commit as the fix. Every guard that passes on the unfixed code was proven with mutate-then-restore (mutations M1-M5 in the evidence).

Evidence

All in docs/issues/open/2505-udp-banned-ips-metric/:

  • manual-verification-evidence.md: the real-tracker reproduction (V1-V4: 1, 3, 4, and a stale 4), red, green, and mutation output for every regression test, and the like-for-like recheck on the final code (L-V1 to L-V4: 0, 0, 1, and 0 right after the one-hour reset). Two earlier rechecks (R-V, F-V) ran before later review fixes and are kept, labelled as such.
  • performance-evidence.md: the baseline and the after measurements, rerun on the final code (earlier after runs are kept and marked as superseded). The aquatic_udp_load_test passes (mean 162465.51 responses/s against the lowest baseline run, 148018.51); it sends only valid connection IDs, so it covers the ban check but not the error path. The Criterion one-sided rule does not fully pass: 23 of 28 medians pass, and 5 are above the baseline limit (IPv6 record_error by 4.0-5.7%, increase_counter/repeated by 0.1% and 0.7%), while the baseline spread itself reaches 5.1%. Back-to-back comparisons with develop show the fix costs about 0.2-0.5 ns per invalid connection ID on IPv4 and 0.5-0.8 ns (4-6%) on IPv6, of which the overflow guard is about 0.2-0.3 ns on IPv6; the cost is flat across map sizes (AC7). The maintainer accepted this cost (AC5).
  • implementation-retrospective.md: seven proposed process improvements, none applied in this PR.
  • agent-review-reports.md: independent pre-PR task review; it failed twice (B1: the first manual recheck ran before the last production change; B2: a missing test-design record) and passed after both were fixed.

Notes for Reviewers

  • The commits keep every step, including corrections, as the repository asks. Some evidence commits group work differently from the specification's Commit Points table (for example, the first recheck log landed in the perf(udp-core) commit, and the T9 and T10 evidence share one commit).
  • One local process mistake was corrected before the first push: a commit was chained after a GPG signing timeout and picked up a staged test rename; at the maintainer's choice that unpushed commit was split. It is recorded in the specification's progress log and the retrospective.
  • Dashboards built on the old, inflated value will drop; worth a release note. The value has been inflated since the metric was introduced (Add more metrics #1145).
  • History rewritten after the first reviews. At the maintainer's choice, an interactive rebase split the leftover removals out of the fix commit (late PR docs(issues): [#2505] add specification for the UDP banned-IPs metric bug #2506 review finding F11), so that commit and every later one have new IDs. The commit IDs cited in the reviews are mapped to commit subjects in docs/pr-reviews/pr-2524-review/PR-REVIEW.md; the final code was byte-identical before and after the split.
  • Reviews processed: Copilot review 5515830780 (F1, F2) and Cameron's review 5516040147 (his F1-F4, audit F3-F6) are fixed, replied to, and resolved. Cameron's second review 5517039831 (F7, F9, F10, F11; his F8 confirmed fixed) is fixed in commits added on top (audit: docs/pr-reviews/pr-2524-review/PR-REVIEW.md). Cameron's post-merge review of the specification PR docs(issues): [#2505] add specification for the UDP banned-IPs metric bug #2506 (F7-F14) is fixed on this branch with the maintainer's approval; those threads stay open until this PR merges (audit: docs/pr-reviews/pr-2506-review/PR-REVIEW.md).

Validation

  • ./contrib/dev-tools/git/hooks/pre-commit.sh passed for every commit (including linter all).
  • The pre-push checks passed on every push: nightly fmt, check, and docs, and the stable full test suite.
  • The branch was rebased onto develop again after Cameron's second review (git range-diff: all 33 commits unchanged), so the commit IDs cited in the reviews changed. The audit maps every cited ID to its commit subject.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 09:12
@josecelano josecelano self-assigned this Oct 14, 2026
@josecelano
josecelano requested a review from da2ce7 October 14, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Concurrent reset and error handling can leave the published gauge inconsistent with ban state.

2 open findings
What changed in this PR

Fixes UDP banned-IP metrics so they count only over-limit IPs and reset correctly.

Changes:

  • Maintains an O(1) banned-IP count in BanService.
  • Publishes the updated gauge after periodic resets.
  • Adds regression tests, benchmarks, documentation, and verification evidence.
File Description
src/​bootstrap/​jobs/​udp_tracker_server.rs Publishes the metric after cleanup.
packages/​udp-server/​tests/​server/​contract.rs Tests strict and disabled policies.
packages/​udp-server/​src/​statistics/​mod.rs Clarifies metric semantics.
packages/​udp-server/​src/​statistics/​metrics.rs Documents banned-IP totals.
packages/​udp-server/​src/​banning/​mod.rs Adds reset-and-publish helper.
packages/​udp-server/​src/​banning/​event/​listener.rs Updates listener assertions.
packages/​udp-server/​src/​banning/​event/​handler.rs Shares gauge-update helper.
packages/​udp-core/​src/​services/​banning.rs Maintains the accurate total.
packages/​udp-core/​Cargo.toml Adds QuickCheck for tests.
packages/​udp-core/​benches/​ban_service_benchmark.rs Adds per-error benchmark.
packages/​rest-api-protocol/​src/​v1/​context/​stats/​resources/​stats.rs Clarifies REST field semantics.
docs/​issues/​open/​2505-udp-banned-ips-metric/​performance-evidence.md Records benchmark evidence.
docs/​issues/​open/​2505-udp-banned-ips-metric/​manual-verification-evidence.md Records regression and recheck evidence.
docs/​issues/​open/​2505-udp-banned-ips-metric/​ISSUE.md Updates implementation status and evidence.
docs/​issues/​open/​2505-udp-banned-ips-metric/​implementation-retrospective.md Documents implementation lessons.
docs/​issues/​open/​2505-udp-banned-ips-metric/​agent-review-reports.md Records independent reviews.
Cargo.lock Registers the QuickCheck dependency.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/udp-server/src/banning/mod.rs Resolved
Comment thread packages/udp-server/src/banning/mod.rs Resolved
da2ce7
da2ce7 previously requested changes Oct 14, 2026

@da2ce7 da2ce7 left a comment

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.

Reviewed at c3d2f4a10bd42289cc1af2eaa5fac6990c313d05 (round 1). Recomputed from the bytes at this head, against the merge base d1bf013ea; develop is d1bf013ea and the merge is clean.

This implements the specification merged as b5f1801c6. BanService keeps a banned-IP counter (option P1), udp-server gains banning::reset_bans (G1) and the root cleanup job calls it, four descriptions state decision A, and the unused trait and the write-only field are removed (AC4). It also adds a Criterion group, a property test, and the issue's evidence, reports and retrospective: fifteen commits, nineteen files, +3742/−97. No other review had been posted, so findings start at F1.

The fix. increase_counter (banning.rs:32-41) bumps the counter exactly when a count reaches limit + 1. Counts rise in unit steps from 0, and only reset_bans clears the map, which also zeroes the counter (:68-70). So the counter equals the number of IPs with count > limit, which is what is_banned (:62-65, unchanged) tests. When limit == u32::MAX, no count can exceed the limit and nothing is counted, which matches is_banned. The const fn field read is legal at MSRV 1.88. No code still names BanningStats or last_connection_id_errors_reset. The docs on the method, the metric, Metrics::udp_banned_ips_total and the REST field all state decision A (AC3).

udp-core tests. R1 ×4 and R2 ×2 keep the count and the limit visible through record_connection_id_errors, act with get_banned_ips_total, and assert stated numbers. Two of R1's four cases are red on the unfixed code; the PR body's table says all of R1 is. The other cases are proven by mutate-then-restore: at least two tests catch every mutation of either form, and R1p catches them all. R1p checks an independent per-IP model after every step (four IPs, about one reset in eight, limit 0-3), and its 1,000 short cases are cheap. quickcheck 1 sits under [dev-dependencies] with default-features = false and resolves to the 1.1.0 already in the lockfile (one new edge).

udp-server. reset_bans (banning/mod.rs:19-28) resets and reads the total under the write lock, drops the guard, and only then awaits the now pub(crate) gauge helper, the same shape as the handler. R3 publishes 1 through handle_event, resets, and asserts 0; mutation M5 fails both R3 and R4. The handler test's three clients expect 2, where the old map length gives 3 (M0). The listener tests now observe get_count and keep their intent. R5/R6 start one tracker per policy with limit 2: L errors read 0 (red before the fix, and deterministically so), and L+1 errors are polled until the total reads 1. R6 does not assert that the client is still served; the existing disabled-mode test covers that.

Root job and R4. Each tick calls reset_bans(&ban_service, &stats_repository, CurrentClock::now()) (udp_tracker_server.rs:98). R4 spawns run_ban_cleanup_job with a 60 s interval under a paused clock, which bypasses the 3600 s configuration minimum, sleeps one interval plus 1 ms, and asserts 0. The red run was recorded with the job taking an unused repository parameter.

Benchmark and performance. B1 times repeated errors from one IP in a populated map. After ten iterations that IP is past the limit, so the benchmark measures the steady state, not the crossing. P1 ran before any production change, P2a on the first form of the fix, and P2 on 4845e5804. Recomputed from the tables: every median and limit matches, and 9 of 28 medians exceed the P1 limit in both P2a and P2. The load-test means are 150960.00, 162437.63 and 158456.71, against a lowest P1 run of 148018.51. Measured back to back against develop, the final form costs +0.39 to +0.63 ns (+3.1% to +6.2%). The acceptance is recorded (performance-evidence.md:380-384 and :464-466, and the Progress Log), and AC5's text now states the deviation, so the box is ticked against amended text. The noise figure is F1.

Evidence, spec and reports. V1-V4 and both rechecks match the committed logs: 15 cookie-error lines each, loopback sources only, and the reset 3600 s after start. The final recheck ran on 60d10af6d's tree. After 4845e5804 only the handler test changed, so the recheck exercised the final production code, though before the rebase onto d1bf013ea, which brought only dependency and benchmark changes. All 13 new Progress Log stamps precede or equal their commits. The three review entries fit the template (fail on B1, fail on B2, then pass, all from the Task Reviewer role). c3d2f4a10 maps four pre-rebase ids rather than removing them. The entries still cite PR-branch commits, which open-pull-request/SKILL.md:73-77 forbids, but the append-only template (AGENT-REVIEW-REPORTS.md:12-13) leaves no compliant edit in this PR, so this is not a finding. The retrospective fits its template and makes seven proposals. Of the earlier post-merge findings on the specification, F7 is fixed in code by a8f5fbbbf, though ISSUE.md:86-87 still credits the old sentence to the inherent method. F9, F12 and F14 still stand, F10 and F13 are moot, and F11 was not adopted.

Hygiene. Conventional subjects with [#2505]; author equals committer; author times ascend; one trailer line each; no banned token; git diff --check clean; project-words.txt untouched. The commit-point deviations are the ones the PR body lists.

Findings

  • F1 [Minor] performance-evidence.md:261: the P1 noise is stated as about 3%, but the file's own measure gives 5.1%. It blocks because AC5 relies on this figure, so the evidence would carry a false number.
  • F2 [Minor] ISSUE.md:629: the M and B identifiers each name two different things.
  • F3 [Suggestion] banning.rs:35: a count that wraps is counted twice.
  • F4 [Nit] ISSUE.md:631: AC4's evidence overlooks the open EPIC row.

Checked, no finding: lock scopes and awaits on both publish paths; borrows in increase_counter; the quickcheck API against the udp-protocol precedent; test-util for start_paused; visibility of every root-test import; the stopped clock's timestamp in R4; contract-test isolation (one tracker and one ban service per test); B1's instrument check; the PR title, Closes #2505 and the develop target; the tracker logs, which hold only loopback addresses and the documented default token.

Checks

On the loop's compute hub at this head, merge base d1bf013ea (git merge-tree clean against d1bf013ea, the develop of dispatch; receipt server-gates-krkavec-269): pre-commit profile gate exit 0 (82 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 19 errors / 4 warnings at this head and 19 / 4 at d1bf013ea re-measured, none in the files this PR touches; cargo test -p exit 0 for torrust-tracker-udp-core (54 passed), torrust-tracker-udp-server (237 passed) and torrust-tracker-rest-api-protocol (2 passed); cargo clippy --all-targets -- -D warnings exit 0 with no diagnostics and cargo fmt --check exit 0 for all three; the root crate's bootstrap::jobs::udp_tracker_server lib tests exit 0 (2 passed); cargo test -p torrust-tracker-udp-core --benches exit 0; cargo machete --with-metadata exit 0; validate-audit-record.py --pr-number 2524 reports that no audit record exists yet for this PR. GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker-udp-server): completed/success; Package Coverage (torrust-tracker-rest-api-protocol): completed/success; Package Coverage (torrust-tracker-udp-core): completed/success; Package Coverage (torrust-tracker): completed/success; Docker E2E: completed/skipped; Build on ubuntu-latest (stable): completed/success; Build on windows-latest (stable): completed/success; Build on macos-latest (stable): completed/success; Test (Docker) (release): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on windows-latest (nightly): completed/success; Discover Package Coverage: completed/success; Build on macos-latest (nightly): completed/success; Generate Coverage Report: completed/success; Docs Lint: completed/success; Unit (nightly): completed/success; Documented Clippy Allows: completed/success; Layer Boundary Bans: completed/success; Unit (stable): completed/success". At posting, develop is d1bf013ea.

@josecelano
josecelano force-pushed the 2505-udp-banned-ips-metric branch from c3d2f4a to 4b2c0f3 Compare October 14, 2026 10:28
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…lding the ban lock

The reset path added a second publisher of the banned-IPs gauge. Both it and
the banning event handler released the BanService lock before writing the
gauge, so a reset and a concurrent connection ID error could publish out of
order and leave the gauge inconsistent with the ban state until the next
error. Hold the ban lock until the gauge is written in both paths, and add
lock-ordering regression tests. Addresses PR torrust#2524 review finding F1.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…ication error

The shared helper that publishes the banned-IPs total, now also used by the
reset path, logged "Failed to increase the counter" although it sets a gauge.
Name the gauge so operators can diagnose a stale value. Addresses PR torrust#2524
review finding F2.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
… instead of wrapping

In release builds the per-IP count wrapped after u32::MAX errors, so an IP
already counted as banned would cross the limit again and be counted twice.
Stop the count at u32::MAX with checked_add and count the crossing only when
the count increased; saturating_add would double-count when the limit is
u32::MAX - 1. Add boundary tests. Addresses PR torrust#2524 review finding F3 by
Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
The P1 noise was stated as about 3%, which is the largest deviation from the
mean; measured as (highest - lowest) / mean, like the load-test spread, it is
up to 5.1%. State the measure, and that attributing the P2 excesses rests on
the same-machine comparison. Addresses PR torrust#2524 review finding F1 by Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…atements

The inherent get_banned_ips_total had no doc comment, so the spec's
contracts-violated bullet, scope, and AC3 now say the fix adds one and
updates the reset_bans doc. Date the method from 1ce2e33 (torrust#1145), not the
package extraction, and note that the value was wrong since the metric was
introduced. Make the AC4 evidence say that no code reference remains.
Addresses late PR torrust#2506 review findings F7 and F9 and PR torrust#2524 review
finding F4 by Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
Add an identifiers glossary to the specification, rename the measurement
phases P1 and P2 (which also name the performance options) to baseline and
after in the current text, and qualify scenario, mutation, benchmark-task,
and task-review citations. Progress Log entries and recorded command output
keep their original identifiers. Addresses PR torrust#2524 review finding F2 by
Cameron and late PR torrust#2506 review finding F12.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
Record Copilot review 5515830780 (F1, F2) and Cameron's review 5516040147
(his F1-F4 as audit F3-F6), their fixes and reply URLs, and map the commit
IDs the reviews cite to commit subjects after the history split.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…ew findings

Add Cameron's post-merge review 5515068886 (F7-F14) to the PR torrust#2506 audit as
FOLLOW_UP/OPEN on PR torrust#2524, with the maintainer's approval URL in Ownership
and the follow-up reply URLs.

Co-authored-by: Copilot <[email protected]>
@josecelano
josecelano force-pushed the 2505-udp-banned-ips-metric branch from bd45c3f to 5bfd57a Compare October 14, 2026 10:55
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…lding the ban lock

The reset path added a second publisher of the banned-IPs gauge. Both it and
the banning event handler released the BanService lock before writing the
gauge, so a reset and a concurrent connection ID error could publish out of
order and leave the gauge inconsistent with the ban state until the next
error. Hold the ban lock until the gauge is written in both paths, and add
lock-ordering regression tests. Addresses PR torrust#2524 review finding F1.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…ication error

The shared helper that publishes the banned-IPs total, now also used by the
reset path, logged "Failed to increase the counter" although it sets a gauge.
Name the gauge so operators can diagnose a stale value. Addresses PR torrust#2524
review finding F2.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
… instead of wrapping

In release builds the per-IP count wrapped after u32::MAX errors, so an IP
already counted as banned would cross the limit again and be counted twice.
Stop the count at u32::MAX with checked_add and count the crossing only when
the count increased; saturating_add would double-count when the limit is
u32::MAX - 1. Add boundary tests. Addresses PR torrust#2524 review finding F3 by
Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
The P1 noise was stated as about 3%, which is the largest deviation from the
mean; measured as (highest - lowest) / mean, like the load-test spread, it is
up to 5.1%. State the measure, and that attributing the P2 excesses rests on
the same-machine comparison. Addresses PR torrust#2524 review finding F1 by Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…atements

The inherent get_banned_ips_total had no doc comment, so the spec's
contracts-violated bullet, scope, and AC3 now say the fix adds one and
updates the reset_bans doc. Date the method from 1ce2e33 (torrust#1145), not the
package extraction, and note that the value was wrong since the metric was
introduced. Make the AC4 evidence say that no code reference remains.
Addresses late PR torrust#2506 review findings F7 and F9 and PR torrust#2524 review
finding F4 by Cameron.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
Add an identifiers glossary to the specification, rename the measurement
phases P1 and P2 (which also name the performance options) to baseline and
after in the current text, and qualify scenario, mutation, benchmark-task,
and task-review citations. Progress Log entries and recorded command output
keep their original identifiers. Addresses PR torrust#2524 review finding F2 by
Cameron and late PR torrust#2506 review finding F12.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
Record Copilot review 5515830780 (F1, F2) and Cameron's review 5516040147
(his F1-F4 as audit F3-F6), their fixes and reply URLs, and map the commit
IDs the reviews cite to commit subjects after the history split.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 14, 2026
…ew findings

Add Cameron's post-merge review 5515068886 (F7-F14) to the PR torrust#2506 audit as
FOLLOW_UP/OPEN on PR torrust#2524, with the maintainer's approval URL in Ownership
and the follow-up reply URLs.

Co-authored-by: Copilot <[email protected]>
@josecelano
josecelano requested a review from da2ce7 October 14, 2026 10:58
josecelano and others added 9 commits October 14, 2026 14:09
Record Copilot review 5515830780 (F1, F2) and Cameron's review 5516040147
(his F1-F4 as audit F3-F6), their fixes and reply URLs, and map the commit
IDs the reviews cite to commit subjects after the history split.

Co-authored-by: Copilot <[email protected]>
…ew findings

Add Cameron's post-merge review 5515068886 (F7-F14) to the PR torrust#2506 audit as
FOLLOW_UP/OPEN on PR torrust#2524, with the maintainer's approval URL in Ownership
and the follow-up reply URLs.

Co-authored-by: Copilot <[email protected]>
… holding the ban lock

Both publishers of the banned-IPs total held the BanService write lock while
waiting for the statistics store, so in strict mode the receive loop's ban
check could wait behind the stats lock during an invalid connection ID flood.
Order the two publishers with a dedicated PublicationOrder mutex held across
the ban change and the gauge write, and release the ban lock before the gauge
write. The udp-server container owns the mutex; the banning listener and the
reset job receive it.

Replace the lock-ordering tests: one checks that the ban lock is free while a
publisher waits for the gauge store, the other that it still holds the
publication order. Add a test-only Repository::write_lock_for_test seam so
the tests no longer write through the stats field, which torrust#2517 plans to make
private. Addresses PR torrust#2524 review findings F10 and F11 by Cameron.

Co-authored-by: Copilot <[email protected]>
…t after a reset

Add the R2 case the specification describes as red on develop: an IP that
was banned, reset, and then sends errors up to the limit must not be counted.
With develop's map-length total it reads 1 instead of 0. Addresses PR torrust#2524
review finding F7 by Cameron.

Co-authored-by: Copilot <[email protected]>
…final after measurement

Record the publication-order and test-seam evidence (red, mutation, green),
the R2 below-limit case and the corrected R2 note, and the after measurement
redone on the final code with a second same-machine comparison and the
maintainer's acceptance of the updated cost; mark the earlier after run and
lock tests as superseded; and add the recurrence to the retrospective.
Addresses PR torrust#2524 review findings F7, F9 (in part), F10, and F11 by
Cameron.

Co-authored-by: Copilot <[email protected]>
…lution

The F10 detail repeated a false claim that R2's re-count leg is red on
develop. Describe the added below-limit case instead (PR torrust#2524 review
finding F7 by Cameron).

Co-authored-by: Copilot <[email protected]>
Repeat the like-for-like recheck (L-V1 to L-V4, including the one-hour reset)
on the final code, relabel the earlier recheck as the second one, correct
the remaining final-code claims, and point AC6 at the last recheck. Completes
PR torrust#2524 review finding F9 by Cameron.

Co-authored-by: Copilot <[email protected]>
 review

Add audit rows F7, F9, F10, and F11 for review 5517039831 with their
replies, and point the PR torrust#2506 F10 resolution at the correcting reply.

Co-authored-by: Copilot <[email protected]>
…nd PR torrust#2524 review

Rebasing onto develop gave every branch commit a new ID. Map the IDs that
Cameron's second review cites to their commit subjects and log the rebase.

Co-authored-by: Copilot <[email protected]>
@josecelano
josecelano force-pushed the 2505-udp-banned-ips-metric branch from 664f885 to f51bee8 Compare October 14, 2026 13:14
@josecelano
josecelano requested a review from da2ce7 October 14, 2026 13:21
@josecelano
josecelano dismissed stale reviews from da2ce7 and da2ce7 October 14, 2026 14:13

Dismissed by the maintainer to merge without waiting for a re-review. Every finding from this review is fixed, replied to, and resolved (audit: docs/pr-reviews/pr-2524-review/PR-REVIEW.md). Feedback after the merge is still welcome and will be processed.

@josecelano

Copy link
Copy Markdown
Member Author

ACK f51bee8

@da2ce7 da2ce7 left a comment

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.

Reviewed at f51bee826f3fe00a97a296fca819cdfd7bcf581d (post-merge). Recomputed from the bytes at the merged head, against the merge base c1874facb; the PR merged at 14:21:52Z as 8045bd252.

Label: POST_MERGE_FINDINGS — the round computed at the earlier head 040179b95 was superseded by the audit-row commit and the rebase before it posted, and the PR merged before this round ran. The findings below stand at the merged head and are for a follow-up; no ACK follows a merged PR.

Rebase purity. git range-diff 01bdb2c8b..664f88512 c1874facb..f51bee826 shows 33 = rows and one new commit. The patch text c1874facb..e2bc97436 is byte-identical to 01bdb2c8b..664f88512 (948,470 bytes). Excluding pr-2524-review/PR-REVIEW.md, the merged patch equals the pre-rebase one. The fix commits are now 0d92a26e5, b9afa9b96, ddf99a03b, 94e60f5ef and 4e69b8bfa, the audit rows e2bc97436, and the id map f51bee826, which touches only the audit (+28/−8).

Code, carried from 040179b95. The code blobs equal those reviewed at 040179b95, so the code verdict carries over unchanged:

  • the PublicationOrder mutex is held across the ban change and the gauge write, with the ban guard dropped before the stats wait and no lock inversion;
  • the R2 below-limit test is red on develop's map-length total;
  • the third recheck's log matches L-V1 to L-V4 with the one-hour reset;
  • the final after run recomputes (5 of 28 over the limit; load mean 162465.51).

Audit record and id map (F12). e2bc97436 adds rows F7, F9, F10 and F11 with the posted severities (Minor, Major, Suggestion, Suggestion). Their sources are the four round-3 comments and their replies are the 13:03 UTC ones. Their solution and current-tree sentences hold at this head. The id map's 18 pairs all match git log subjects, and every other id the two reviews cite is on develop or is explained beneath the map. Offline, the validator prints {"status": "ok", "rows": 10, "log_entries": 10, "failures": 0}. F1's detail still describes the superseded design, so F12 stands in part. The two REQUEST_CHANGES reviews were dismissed at 14:13Z, and all ten threads are resolved.

Findings

  • F12 [Minor] pr-2524-review/PR-REVIEW.md:95: stands in part. F1's Solution (:89) and current-tree verification (:95-97) describe the design F10 replaced.
  • F13 [Suggestion] handler.rs:228: stands. The test files are byte-identical across the rebase.
  • F14 [Nit] pr-2524-review/PR-REVIEW.md:284: "rewritten twice" omits the 10:55Z rebase onto 01bdb2c8b.

Checked, no finding: the code blobs against round 4; the merge relation (8045bd252's first parent is c1874facb, and its second is the merged head); git diff --check; the new rows against the capture; the thread states.

Checks

On the loop's compute hub at the merged head, merge base c1874facb (the first parent of the merge commit 8045bd252; receipt server-gates-krkavec-282): pre-commit profile gate exit 0 (80 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 19 errors / 4 warnings at this head and 19 / 4 at c1874facb re-measured, none in the files this PR touches; cargo test -p exit 0 for torrust-tracker-udp-core (57 passed), torrust-tracker-udp-server (241 passed) and torrust-tracker-rest-api-protocol (2 passed); cargo clippy --all-targets -- -D warnings exit 0 with no diagnostics and cargo fmt --check exit 0 for all three; the root crate's bootstrap::jobs::udp_tracker_server lib tests exit 0 (2 passed); cargo test -p torrust-tracker-udp-core --benches exit 0; cargo machete --with-metadata exit 0; validate-audit-record.py --pr-number 2524 exit 0 against this head's audit record (10 rows, 10 log entries, 0 failures). GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Test (Docker) (release): completed/success; Docker E2E: completed/skipped; Unit (stable): completed/success; Layer Boundary Bans: completed/success; Unit (nightly): completed/success; Documented Clippy Allows: completed/success; Package Coverage (torrust-tracker-udp-core): completed/success; Package Coverage (torrust-tracker-rest-api-protocol): completed/success; Package Coverage (torrust-tracker): completed/success; Package Coverage (torrust-tracker-udp-server): completed/success; Build on macos-latest (stable): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on ubuntu-latest (stable): completed/success; Docs Lint: completed/success; Discover Package Coverage: completed/success; Generate Coverage Report: completed/success". At posting, develop is 8045bd252.

tests hold the gauge store's lock, run the publishing task on a current-thread runtime until it
blocks, and assert that the ban service is still locked; they observe the lock ordering because
the out-of-order interleaving cannot be produced deterministically without an injection seam.
- Current-tree verification: `packages/udp-server/src/banning/mod.rs` and

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.

[Minor][F12] F1's detail still describes the design that F10 replaced, though the rows for this round's findings are now present.

e2bc97436 added rows F7, F9, F10 and F11, so the first half of round 4's F12 is fixed; the validator prints rows: 10, failures: 0.

This entry still says "both paths keep the ban service write guard until the gauge is written" (:89). Here (:95-97) it says both files "drop the guard after update_metric_for_banned_ips_total", and it cites the keep_the_ban_service_locked_until tests. At this head, handle_event and reset_bans drop the ban guard before that call and hold PublicationOrder instead, and those two tests no longer exist. F10's detail says "Four tests replace the two audit F1 tests", but a reader of F1 alone gets the old design.

Follow-up: append a note to F1 that F10's fix (fix(udp-server): [#2505] order banned-IPs publications without holding the ban lock) superseded its solution and tests, and log the correction.


// Assert
assert!(
context.ban_service.try_write().is_ok(),

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.

[Suggestion][F13] The "ban lock is free" tests would also pass if the publisher had not yet reached the ban change.

This is round 4's finding, re-anchored: the file and its twin at banning/mod.rs:161 are byte-identical across the rebase. try_write().is_ok() holds when the publisher released the ban lock before waiting for the gauge store, which is the guarantee. It also holds while the publisher is still parked before the ban lock. A publisher reordered to wait on the stats lock before mutating the bans passes both tests of each pair, because the publication order is held there too.

Follow-up: take the guard instead of only probing it. For example, let ban_service = context.ban_service.try_write().expect("…"); followed by assert_eq!(ban_service.get_count(&client_ip), Some(1)). For the reset pair, seed one error before spawning and check that get_count is None.


## Commit IDs Cited by Reviewers

The branch was rewritten twice after reviews. First, after Copilot's review and Cameron's first

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.

[Nit][F14] The branch was rewritten three times after the first reviews, not twice.

The timeline shows force pushes at 10:28:49Z (the split, head 4b2c0f3be), 10:55:17Z (the rebase onto 01bdb2c8b, head 5bfd57ac1), and 13:14:00Z (the rebase onto c1874facb). This paragraph's "First" covers only the split and its "Second" only the last rebase. The note under the table ("the branch head before the first rebase onto develop") implies the middle one. The map itself is right: the second review's ids are the post-10:55 ids.

Follow-up: say three, and name the rebase onto 01bdb2c8b.

josecelano added a commit that referenced this pull request Oct 14, 2026
…ics lock private

081f6e6 docs(issues): [#2517] link the spec to PR 2527 (Jose Celano)
1c36017 docs(issues): [#2517] record the rebase and cite branch commits by subject (Jose Celano)
04eed30 docs(issues): [#2517] record the second independent review (Jose Celano)
bf6fdf1 docs(issues): [#2517] address the first review and rerun M1 across all metric families (Jose Celano)
d9cdbd9 docs(statistics): [#2517] introduce the repository privacy doctests (Jose Celano)
0468372 docs(issues): [#2517] record the first independent review (Jose Celano)
5652bee docs(issues): [#2517] record implementation verification (Jose Celano)
5bdd4a8 refactor(swarm-coordination-registry): [#2517] make the statistics repository lock private (Jose Celano)
dc22e11 refactor(tracker-core): [#2517] make the statistics repository lock private (Jose Celano)
e0ae644 refactor(http-core): [#2517] make the statistics repository lock private (Jose Celano)
b215401 refactor(udp-server): [#2517] make the statistics repository lock private (Jose Celano)
76ed16a refactor(udp-core): [#2517] make the statistics repository lock private (Jose Celano)
03c2134 docs(issues): [#2517] record manual verification preference (Jose Celano)

Pull request description:

  ## Summary

  Makes the `stats: Arc<RwLock<Metrics>>` field private in the five statistics repositories, so every read and write goes through the repository's methods. This is a visibility-only change made before the first crates.io publish, so it breaks no published API. The public read accessors (`get_stats()` / `get_metrics()`) still return `RwLockReadGuard<'_, Metrics>`; replacing them is a possible follow-up and out of scope.

  Closes #2517. Part of EPIC #1669 (Overhaul: Packages).

  ## Changes

  One commit per package, each making the field private and adding a `rust,compile_fail,E0616` doctest that reads `repository.stats` from outside the crate, plus a companion doctest that compiles through the public accessor:

  - `packages/udp-core/src/statistics/repository.rs`
  - `packages/udp-server/src/statistics/repository.rs`
  - `packages/http-core/src/statistics/repository.rs`
  - `packages/tracker-core/src/statistics/repository.rs`
  - `packages/swarm-coordination-registry/src/statistics/repository.rs`

  No other code needed changes: no caller outside these files used the field or built a `Repository` with a struct literal.

  The issue folder `docs/issues/open/2517-1669-encapsulate-statistics-repository-state/` records the spec progress, the manual verification evidence (with artifacts under `evidence/`), and two independent review reports.

  ## Validation

  - Red/green for each package: the `compile_fail` doctest failed (it compiled) while the field was public and passed once the field became private; `cargo test -p <package>` passed for all five packages.
  - `cargo +nightly test --doc` on the five packages passes, so the pinned `E0616` error code is checked.
  - AC1: `grep -nE 'pub(\([^)]*\))? +stats *:' packages/*/src/statistics/repository.rs` prints nothing.
  - Pre-commit checks (`linter all`, `cargo machete`, `cargo deny check bans`, workspace doctests) and pre-push checks (nightly fmt, check, docs; stable `cargo test --tests --benches --examples --workspace --all-targets --all-features`) pass on the rebased branch.
  - Manual verification M1: the same HTTP and UDP `started` and `completed` announces were sent to `develop` and to this branch (both based on `c1874fac`) on fresh databases. The client responses, the normalized `/api/v1/stats`, and every `/api/v1/metrics` family (HTTP core, UDP core, UDP server, tracker core, swarm coordination registry) were identical, with only processing-time values masked.
  - Two independent task reviews: round 1 failed on incomplete M1 evidence and spec housekeeping, which was fixed; round 2 passed.

  ## Notes for reviewers

  - After the rebase onto `develop`, the `udp-server` repository also contains the `#[cfg(test)] pub(crate) write_lock_for_test()` method added by #2524. It lives inside the repository file, so it keeps compiling with the private field, and it is a repository method, not field access.
  - #2521 (removing the unused SI-30 statistics traits) touches the same `udp-core` and `udp-server` repository files; whichever PR lands second needs a rebase.
  - The tracker-core `Repository` doc comment still says "torrent repository metrics"; that wording predates this PR and is left unchanged.

ACKs for top commit:
  josecelano:
    ACK 081f6e6

Tree-SHA512: 869f5d6cf560e891f972d7f64af17c56ba06be2630bd2ec6da284142eb88000cfd5cbf1df4f8ef23b87c77713b3d0b6de0d4589044f709660caf4d466b838a68
josecelano added a commit that referenced this pull request Oct 14, 2026
PR #2524 implemented the fix and merged; record it in the spec frontmatter
and log the merge.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit that referenced this pull request Oct 14, 2026
Move the #2505 spec folder to docs/issues/closed, set its status to done,
tick the last workflow checkpoint, and update the frontmatter paths. Repair
the live references in the #2517 spec and the PR #2506 and PR #2524 review
audits; historical mentions of the old path stay as recorded.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit that referenced this pull request Oct 14, 2026
PR #2524 merged with the fixes for Cameron's late review of PR #2506.
Record F7-F14 as FIXED/RESOLVED, each citing its fix commit on develop and
the closing reply on its thread.

Co-authored-by: Copilot <[email protected]>
josecelano added a commit that referenced this pull request Oct 14, 2026
…ts late spec-review findings

620b2a6 docs(pr-reviews): add the PR #2528 review audit (Jose Celano)
8901bc5 docs(issues): [#2517] point the SI-30 traits out-of-scope note at #2521 (Jose Celano)
d056de4 docs(pr-reviews): [#2505] close the PR #2506 post-merge findings (Jose Celano)
5e4cef6 chore(issues): archive closed issue #2505 spec to docs/issues/closed (Jose Celano)
bde12a0 docs(issues): [#2505] set the spec's related pull request (Jose Celano)

Pull request description:

  Post-merge cleanup for issue #2505 after PR #2524 merged (`8045bd252`). Related to #2505, #2524, and #2506.

  ## Changes

  One signed commit per item:

  1. `docs(issues): [#2505] set the spec's related pull request`: sets `related-pr: 2524` and logs the merge, including that Cameron's two change requests were dismissed at the maintainer's decision before the merge.
  2. `chore(issues): archive closed issue #2505 spec to docs/issues/closed`: moves `docs/issues/open/2505-udp-banned-ips-metric/` to `docs/issues/closed/` (#2505 is `CLOSED` on GitHub), sets `status: done`, ticks the last workflow checkpoint, and updates the frontmatter paths in the folder. Live references are repaired in the #2517 spec and in the frontmatter of the PR #2506 and PR #2524 review audits. Three historical mentions of the old path (an old progress-log entry, a recorded task review, and the PR #2520 audit) stay as recorded.
  3. `docs(pr-reviews): [#2505] close the PR #2506 post-merge findings`: Cameron's late review of the spec PR #2506 (F7-F14) was fixed on the PR #2524 branch with maintainer approval and recorded as `FOLLOW_UP`/`OPEN`. Now that #2524 is merged, each finding is `FIXED`/`RESOLVED`, citing its fix commit on `develop` and a closing reply on its thread. The audit validator passes (14 rows, 0 failures).
  4. `docs(issues): [#2517] point the SI-30 traits out-of-scope note at #2521`: the #2517 spec said the draft for removing the unused SI-30 statistics traits was not committed yet; it is now issue #2521. This commit also restores the #2517 spec's `last-updated-utc`, which the archive commit had changed, so this PR does not conflict with PR #2527 on that line (`git merge-tree` with #2527's head is clean).

  ## Validation

  - Pre-commit hook passed for each commit (`linter all`); pre-push checks passed.
  - `rg 2505-udp-banned-ips-metric` leaves only the three historical mentions above.
  - The eight PR #2506 threads are replied to and resolved after this push.

ACKs for top commit:
  josecelano:
    ACK 620b2a6

Tree-SHA512: 6ec580121bee06f51fce64d944597c39d2aeda4868eddc81aed51d906afbdd2fc6be21dc65147792d123e883eae56f0172dbe01526cbfef6b775a319d2eaa7e0
josecelano added a commit that referenced this pull request Oct 14, 2026
… history with safeguards

b65cd96 docs(pr-reviews): add the PR #2531 review audit (Jose Celano)
12971bf docs(agents): replace rewritten commit ids with commit subjects (Jose Celano)
3bcb498 docs(agents): allow rewriting an unmerged pull request's history with safeguards (Jose Celano)

Pull request description:

  Aligns the root `AGENTS.md` history rule ("Commit history and PR scope") with the maintainer's policy.

  ## Why

  The rule said "the only allowed rewrite is a rebase onto `develop`". PR #2524 was rewritten at the maintainer's choice: an interactive rebase split the leftover removals out of the fix commit, a late review finding on the spec PR #2506. The maintainer's policy is that rewriting an unmerged pull request's history is acceptable but not ideal, and agents may do it on their own judgment, provided no superseded step is hidden and every reference to the old commit ids is updated.

  ## Change

  One signed docs commit to `AGENTS.md`:

  - Keeps "do not squash, fixup, or rewrite to hide superseded steps" and "never propose squashing".
  - Keeps the rebase guidance and its ADR link as its own bullet.
  - Adds the policy for other rewrites of an unmerged PR: allowed but not ideal, on the agent's judgment. Safeguards:
    - prefer a new commit on top, especially during a review round;
    - keep every step, including superseded steps and corrections;
    - confirm the final tree;
    - push with `--force-with-lease`;
    - update every reference to the old commit ids, linking the existing guidance in the `open-pull-request` skill;
    - map the ids cited in review comments to commit subjects in the review audit;
    - say in the PR body that the history was rewritten;
    - never rewrite `develop`, `main`, or merged history.

  No other file states this rule; the rebase ADR covers only rebases.

  ## Validation

  - Pre-commit hook passed (`linter all`); pre-push checks passed.

ACKs for top commit:
  josecelano:
    ACK b65cd96

Tree-SHA512: d78fcb2424eaf57fd1b2ec25a86fec5518c9fa89a0ecb4fc72a23765b47336cd6a95db6c96a9f99067dca2ddee5b22ba04e38edf32f1f763c1d57ba1db5a2921
josecelano added a commit that referenced this pull request Oct 14, 2026
…s and services

9af096d docs(pr-reviews): [#2521] add the PR #2529 review audit (Jose Celano)
73f6bb7 docs(issues): [#2521] record the rebase onto the #2505 merge and the combined test run (Jose Celano)
41cefc3 docs(issues): [#2521] state what the metrics endpoint comparison ignores (Jose Celano)
3148f20 test(udp-core, udp-server): [#2521] restore the described-metrics checks lost with the services tests (Jose Celano)
1a7d28b docs(issues): [#2521] link PR #2529 and record the review fixes (Jose Celano)
82ac315 docs(udp-core, udp-server): [#2521] highlight the statistics event examples as Rust (Jose Celano)
6501d5e test(udp-server): [#2521] read metrics snapshots instead of dropping read guards (Jose Celano)
7a4d22b docs(issues): [#2521] note that #2505 removed BanningStats (Jose Celano)
d93f028 docs(issues): [#2521] record verification evidence (Jose Celano)
f13b1db docs(issues): [#2521] note the SI-30 trait removal in EPIC #1669 (Jose Celano)
a03c97e refactor(udp-server): [#2521] remove unused statistics services (Jose Celano)
7ada4bf refactor(udp-core): [#2521] remove unused statistics services (Jose Celano)
36b55e1 refactor(udp-server): [#2521] remove unused UdpServerStatsRepository trait (Jose Celano)
046a285 refactor(udp-core): [#2521] remove unused UdpCoreStatsRepository trait (Jose Celano)
f32f704 docs(issues): [#2521] record maintainer decisions before implementation (Jose Celano)

Pull request description:

  Closes #2521

  Parent EPIC: #1669

  ## Summary

  Removes the unused public statistics API from `udp-core` and `udp-server`. Nothing outside each item's own definition and tests consumed it: the REST runtime adapter (`TrackerStatsAdapter`) reads the concrete statistics repositories directly.

  - `UdpCoreStatsRepository` and `UdpServerStatsRepository` (left over from SI-30, #1924), with their impls, their `clippy::double_must_use` allowances, the `MetricCollection` imports, and the `async-trait` dependency they alone required.
  - The `statistics::services` modules (`TrackerMetrics` and `get_metrics()`) in both packages.

  The still-accurate statistics event-flow documentation moves from each `services.rs` to its `statistics/mod.rs`. The stale `pub udp4_connections_handled: u64` field example is replaced by a link to the real accessor (`Metrics::udp4_connections_handled` in `udp-core`, `Metrics::udp4_connect_requests_accepted_total` in `udp-server`), and the `udp-core` example's stale `send_event` call now uses the sender's `send` method.

  `BanningStats` is out of scope; #2505 removed it (PR #2524).

  ## Tests

  - `udp-server`: `it_should_initialize_metrics_when_constructed_with_default` now reads through `get_stats()` and still checks that `Repository::default()` initializes the described metrics. `it_should_return_a_snapshot_of_the_initialized_metrics_collection`, which only exercised the removed trait method, is deleted.
  - The two service tests (`the_statistics_service_should_return_the_tracker_metrics` in `udp-core`, `it_should_return_aggregate_torrent_and_protocol_metrics` in `udp-server`) are deleted with the function they tested. They also carried the only check that a new repository starts with its described metrics, so a new `udp-core` repository test and an extra assertion in `udp-server`'s described-metrics test restore it (review finding F4); both were seen to fail on a mutation.
  - The `udp-server` repository tests that released the metrics read guard with an explicit `drop()` now read through a `metrics_snapshot()` test helper (review finding F3).

  ## Files and packages touched

  - `packages/udp-core`: `Cargo.toml`, `src/statistics/mod.rs`, `src/statistics/repository.rs`, `src/statistics/services.rs` (deleted)
  - `packages/udp-server`: `Cargo.toml`, `src/statistics/mod.rs`, `src/statistics/repository.rs`, `src/statistics/services.rs` (deleted)
  - `Cargo.lock`: `async-trait` edge removed from both packages
  - `docs/issues/open/1669-overhaul-packages/EPIC.md`: SI-30 row note
  - `docs/issues/open/2521-1669-remove-unused-udp-stats-traits/`: spec progress, `manual-verification-evidence.md`, and captured REST responses in `evidence/`

  ## Validation

  - `cargo +stable test -p torrust-tracker-udp-core -p torrust-tracker-udp-server -p torrust-tracker-rest-api-runtime-adapter --all-features`: passed
  - `cargo machete --with-metadata`: no unused dependencies
  - `RUSTDOCFLAGS="-D warnings" cargo +nightly doc --no-deps -p torrust-tracker-udp-core -p torrust-tracker-udp-server`: no warnings
  - `cargo tree -e normal --depth 1` for both packages: the only difference from the baseline is the removed `async-trait` line, so no workspace dependency edge changes
  - Pre-commit hook (`linter all`, doc tests, and the rest) on every commit; pre-push hook (nightly fmt, check, and docs plus the full stable test suite) passed on the branch rebased onto current `develop`
  - Manual M1 (`/api/v1/stats`) and M2 (`/api/v1/metrics`), in JSON and Prometheus formats, before and after the change with one UDP announce: same keys, series, labels, and HELP/TYPE lines. Apart from processing-time values, `/api/v1/stats` is identical; `/api/v1/metrics` also differs, run to run, in `recorded_at` and in the order of metrics and series, which the comparison ignores (review finding F5). See `manual-verification-evidence.md`. The manual runs used throwaway helpers in the git-ignored `.tmp/`; nothing temporary is included in the branch.

  ## Notes for reviewers

  - The maintainer waived the spec's mid-implementation stop for review of the test change; the prose-first Arrange-Act-Assert review is recorded in the spec's progress log.
  - PR #2527 (#2517) changed the same two repository files and merged first. A throwaway merge of this branch with current `develop` passes the `udp-core`, `udp-server`, and runtime-adapter tests and Clippy; see the spec's progress log.

ACKs for top commit:
  josecelano:
    ACK 9af096d

Tree-SHA512: b00837801175b61cef625b0b5783ee56a03347cf89ae36ede0bd93a9cb98f83e9cdb67521f05fc8a15eb4b401d5c01a70390f4de815dcf9ea834ef9b55b53c3f
@josecelano
josecelano deleted the 2505-udp-banned-ips-metric branch October 14, 2026 16:54

This branch was previously deployed

1 inactive deployment
coverage — f51bee82 Deployed Oct 14, 2026 by josecelano via Generate Coverage Report #2524
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.

The UDP banned-IPs metric counts clients that are not banned

3 participants