Skip to content

Refactor UDP error event logic before adding new metrics - #1552

Merged
josecelano merged 11 commits into
torrust:developfrom
josecelano:1551-overhaul-stats-refactor-logic-related-to-udp-errors
Jun 2, 2025
Merged

josecelano merged 11 commits into
torrust:developfrom
josecelano:1551-overhaul-stats-refactor-logic-related-to-udp-errors

Conversation

@josecelano

@josecelano josecelano commented Jun 2, 2025 •

Copy link
Copy Markdown
Member

I will add a new metric to count which client's software is used when a UDP error is produced (only for connection ID errors, for now).

This PR make some changes before adding the new metric.

Subtasks

  • Wrapper for aquatic parse error. It's not sendable.
  • Add the error to the Event::UdpError event.
  • Move logic to increase the number of wrong connection IDs per IP to the event listener.
  • Rename errors.
  • Refactor event handler.

@josecelano
josecelano requested a review from da2ce7 June 2, 2025 16:42
@josecelano josecelano linked an issue Jun 2, 2025 that may be closed by this pull request
@josecelano josecelano self-assigned this Jun 2, 2025
@josecelano josecelano added the Code Cleanup / Refactoring Tidying and Making Neat label Jun 2, 2025
@codecov

codecov Bot commented Jun 2, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.80969% with 30 lines in your changes missing coverage. Please review.

Project coverage is 83.35%. Comparing base (059d2b6) to head (a8f3a97).
Report is 12 commits behind head on develop.

Files with missing lines Patch % Lines
packages/udp-tracker-server/src/event.rs 35.29% 11 Missing ⚠️
packages/udp-tracker-server/src/error.rs 78.26% 5 Missing ⚠️
...rver/src/statistics/event/handler/response_sent.rs 96.69% 4 Missing ⚠️
packages/udp-tracker-server/src/handlers/error.rs 92.30% 0 Missing and 2 partials ⚠️
...acker-server/src/statistics/event/handler/error.rs 95.91% 2 Missing ⚠️
...r/src/statistics/event/handler/request_received.rs 94.28% 2 Missing ⚠️
...tracker-server/src/statistics/event/handler/mod.rs 95.65% 0 Missing and 1 partial ⚠️
...er/src/statistics/event/handler/request_aborted.rs 98.18% 1 Missing ⚠️
...r/src/statistics/event/handler/request_accepted.rs 99.38% 1 Missing ⚠️
...ver/src/statistics/event/handler/request_banned.rs 98.18% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #1552    +/-   ##
=========================================
  Coverage    83.35%   83.35%            
=========================================
  Files          275      282     +7     
  Lines        19601    19728   +127     
  Branches     19601    19728   +127     
=========================================
+ Hits         16339    16445   +106     
- Misses        2962     2981    +19     
- Partials       300      302     +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 marked this pull request as ready for review June 2, 2025 18:07
@josecelano

Copy link
Copy Markdown
Member Author

ACK a8f3a97

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

This is a post-merge review of #1552 as it stands at a94c3ced8 on the default branch.

What still runs: the parse-error wrapper SendableRequestParseError and the renamed Error variants (packages/udp-server/src/error.rs); the ErrorKind payload of Event::UdpError (packages/udp-server/src/event.rs:113-155); handle_error publishing one error event for every error it handles, including errors without a transaction id (packages/udp-server/src/handlers/error.rs:24-61); the transaction id taken from the parse error (packages/udp-server/src/handlers/mod.rs:132-156); and the split of the statistics event handler into one module per event. The ban counting that this change moved into the event listener now runs in a listener of its own, which counts ErrorKind::ConnectionCookie from announce and scrape (packages/udp-server/src/banning/event/handler.rs:21-39) and starts whatever the statistics setting. Two defects of the merged form are already fixed: with tracker_usage_statistics = false no UDP server event was published and no ban was counted (fixed by d81e59e), and the authentication-required event text carried a source path (fixed by 9d1f144).

[Nit] packages/udp-server/src/handlers/mod.rs:135: match e.clone() copies the whole error, including its message String, each time a request fails to parse, only to read a Copy field, and the _ => None arm cannot be reached, because map_err(Error::from) at :96 only yields Error::InvalidRequest. Smallest fix: match &e { Error::InvalidRequest { request_parse_error } => request_parse_error.opt_transaction_id, _ => None }.

[Nit] packages/udp-server/src/error.rs:68: the name SendableRequestParseError reads as the protocol's RequestParseError::Sendable (an error a response can be sent for), but the wrapper also holds Unsendable errors, so the event text of an unsendable parse error, ErrorKind::RequestParse built by the Display at error.rs:74-82 and used at event.rs:127, starts with SendableRequestParseError. The protocol error is already Send, which the description gives as the reason for the wrapper; what it lacks is Clone, because it holds an io::Error, and the event channel needs Clone. Smallest fix: rename it, for example to RequestParseFailure.

Checked and found sound: the conversion of both parse-error variants, which keeps the connection and transaction ids only when the parser returned them; the transaction id handed to handle_error for parse errors and for handler errors; ErrorKind::from covering every current Error variant, with the unknown nested arms falling back to InternalServer; one UdpError event per handled error, counted once in the general error metric and again only for announce cookie errors in the client-software metric; and ban counting from announce and scrape cookie errors, including the ban listener's handling of a lagged receiver and its start independent of the statistics setting. Because ban counting now runs through the event channel after the request is handled, the per-IP limit can be passed by the requests already in flight before the listener records them; that follows from the event-based approach and is not a defect.

This branch was previously deployed

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

Labels

Code Cleanup / Refactoring Tidying and Making Neat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul stats: Refactor logic related to UDP errors

2 participants