torrust-tracker
torrust-tracker copied to clipboard
Tracker Checker: Improve errors. More concrete errors
Parent issue: https://github.com/torrust/torrust-tracker/issues/669 Relates to:
- https://github.com/torrust/torrust-tracker/issues/682
- https://github.com/torrust/torrust-tracker/issues/679
- https://github.com/torrust/torrust-tracker/issues/678
- https://github.com/torrust/torrust-tracker/issues/683
Currently, you can run the Tracker Checker with this input:
TORRUST_CHECKER_CONFIG='{
"udp_trackers": ["144.126.245.19:6969"],
"http_trackers": ["https://tracker.torrust-demo.com"],
"health_checks": ["https://tracker.torrust-demo.com/health_check"]
}' cargo run --bin tracker_checker
When something is wrong you only get three types of errors or the application panics.
For example:
TORRUST_CHECKER_CONFIG='{
"udp_trackers": [],
"http_trackers": [],
"health_checks": ["https://localhost:1515"]
}' cargo run --bin tracker_checker
Output:
Running checks for trackers ...
UDP trackers ...
HTTP trackers ...
Health checks ...
✗ - Health API at https://localhost:1515/ is failing: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(1515), path: "/", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })) }
Errors are defined with this enum:
#[derive(Debug)]
pub enum CheckError {
UdpError { socket_addr: SocketAddr },
HttpError { url: Url },
HealthCheckError { url: Url },
}
But depending on the service there could be different reasons. For example:
For the Health Check:
- The connection can be refused.
- The response status code could not be 200.
- Etcetera.
For the UDP tracker:
- You could not bind the client to a local port.
- You could not send a packet to the remote server.
- Etcetera.
We should introduce a second level of types for errors. For example:
#[derive(Debug)]
pub enum CheckError {
Udp { error: UdpError },
Http { error: HttpError },
HealthCheck { error: HealthCheckError },
}
#[derive(Debug)]
pub enum HealthCheckError {
ConnectionRefused { url: Url },
NotOkResponse { url: Url, status: StatusCode },
HealthCheck { error: HealthCheckError },
}
// ...
This issue should be implemented after implementing other issues related to timeout errors. Because those issues might introduce new errors.