Skip to content

Enrich UDP core Event::UdpAnnounce event - #1473

Merged
josecelano merged 5 commits into
torrust:developfrom
josecelano:1384-overhaul-stats-add-announced-peer-to-udp-core-announce-event
Apr 22, 2025
Merged

josecelano merged 5 commits into
torrust:developfrom
josecelano:1384-overhaul-stats-add-announced-peer-to-udp-core-announce-event

Conversation

@josecelano

Copy link
Copy Markdown
Member

Enrich UDP core Event::UdpAnnounce event.

pub enum Event {
    UdpConnect {
        connection: ConnectionContext,
    },
    UdpAnnounce {
        connection: ConnectionContext,
        info_hash: InfoHash,               // New field
        announcement: PeerAnnouncement,    // New field
    },
    UdpScrape {
        connection: ConnectionContext,
    },
}

…::UdpAnnounce

Added:

- info-hash
- peer announcement info

Following the same chage as in the HTTP tracker core.
In order to be able to compare full events.
@codecov

codecov Bot commented Apr 22, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 97.19626% with 3 lines in your changes missing coverage. Please review.

Project coverage is 84.55%. Comparing base (c4dc5e3) to head (e9ec15a).
Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
packages/udp-tracker-core/src/services/announce.rs 94.73% 0 Missing and 1 partial ⚠️
packages/udp-tracker-core/src/services/scrape.rs 83.33% 0 Missing and 1 partial ⚠️
packages/udp-tracker-server/src/lib.rs 96.96% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1473      +/-   ##
===========================================
+ Coverage    84.50%   84.55%   +0.04%     
===========================================
  Files          255      257       +2     
  Lines        19437    19510      +73     
  Branches     19437    19510      +73     
===========================================
+ Hits         16426    16496      +70     
- Misses        2726     2727       +1     
- Partials       285      287       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano
josecelano force-pushed the 1384-overhaul-stats-add-announced-peer-to-udp-core-announce-event branch from d741707 to e9ec15a Compare April 22, 2025 18:49
@josecelano josecelano self-assigned this Apr 22, 2025
@josecelano josecelano added Enhancement / Feature Request Something New - Developer - Torrust Improvement Experience labels Apr 22, 2025
@josecelano

Copy link
Copy Markdown
Member Author

ACK e9ec15a

@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.

Post-merge review of the change from #1473 as it stands at e170b9620 on the default branch.

What still runs: Event::UdpAnnounce (packages/udp-core/src/event.rs:31-35) carries connection, info_hash and announcement, and AnnounceService::send_event (packages/udp-core/src/services/announce.rs:163-182) fills them with the request's info hash and the peer as it stands after handle_announcement, so announcement.peer_addr is the resolved address (the configured external IP for a loopback client) while connection keeps the client socket address. The connection field name on all three variants, the debug lines in the announce and scrape services, sample_info_hash (packages/udp-core/src/lib.rs:41-54) and the sample_peer and announce_events_match test helpers (packages/udp-server/src/lib.rs:679-731) are live. The unconditional println! of every announce event that this change added to the announce service was removed in 57b4822. No production consumer reads the two new fields yet: the statistics handler and listener match UdpAnnounce { connection, .. }.

[Minor] packages/udp-core/src/services/announce.rs:178 and packages/udp-core/src/services/scrape.rs:140 call tracing::debug!(target = crate::UDP_TRACKER_LOG_TARGET, ...). In tracing 0.1 a record's target is set with target:; target = ... declares an ordinary field that happens to be named target. Both records therefore keep the module path (torrust_tracker_udp_core::services::announce, ...::scrape) as their target and carry an extra field target="UDP TRACKER", unlike the crate's other targeted log lines, which use target: UDP_TRACKER_LOG_TARGET (for example packages/udp-core/src/statistics/event/listener.rs:48). With the threshold at debug, anything that selects lines by the UDP TRACKER target, including the top-level target key of the JSON style, misses every announce and scrape event line. Fix: replace target = with target: on both lines.

[Nit] packages/udp-server/src/lib.rs:719-720: the comment explaining why announce_events_match skips a field says "announcement.uploaded contains the current time", but the skipped field is updated (line 722) and uploaded is compared on line 723. In this crate's tests updated comes from the working clock of the udp-core dependency (packages/udp-core/src/peer_builder.rs:36), so the partial comparison is still needed; only the field name in the comment is wrong. Fix: name announcement.updated in the comment.

Checked and found sound: the tree of merge 0485a86 equals head e9ec15a; the enum and the event construction match the description; the event is published only after a successful announce; the .. patterns in packages/udp-core/src/statistics/event/handler.rs:29 and packages/udp-core/src/statistics/event/listener.rs:153 leave the metrics unchanged; sample_peer agrees with the request builder's defaults, so the_peer_ip_should_be_changed_to_the_external_ip_in_the_tracker_configuration checks the external address in the event; the core test at packages/udp-core/src/services/announce.rs:654 compares the whole event under the stopped clock; the new debug lines log, in parsed form, the client address, info hash and peer id that the request debug line at packages/udp-server/src/handlers/mod.rs:92 already logs at the same level; the changed code adds no panic on request input.

This branch was previously deployed

1 inactive deployment
coverage — e9ec15a4 Deployed Apr 22, 2025 by josecelano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- Developer - Torrust Improvement Experience Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul stats: Add announced Peer to UDP core announce event

2 participants