-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
b27f002 remove unused dependencies (ngthhu) 7de4fbc format fix (ngthhu) b301596 chore:[#674] Tracker Checker: Ouput in JSON (ngthhu) Pull request description: ACKs for top commit: josecelano: ACK b27f002 Tree-SHA512: 571125c6204f98e49d7003ab16549dc98f258f4c183e029dcddb53f5af5a72c8fa8cb564d2afef075ea5ee35edad72a593467b551c43dca18430d79f229b0eb6
- Loading branch information
Showing
8 changed files
with
92 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,49 @@ | ||
use std::time::Duration; | ||
|
||
use colored::Colorize; | ||
use reqwest::{Client as HttpClient, Url, Url as ServiceUrl}; | ||
|
||
use crate::console::clients::checker::console::Console; | ||
use crate::console::clients::checker::printer::Printer; | ||
use super::structs::{CheckerOutput, Status}; | ||
use crate::console::clients::checker::service::{CheckError, CheckResult}; | ||
|
||
pub async fn run(health_checks: &Vec<ServiceUrl>, console: &Console, check_results: &mut Vec<CheckResult>) { | ||
console.println("Health checks ..."); | ||
#[allow(clippy::missing_panics_doc)] | ||
pub async fn run(health_checks: &Vec<ServiceUrl>, check_results: &mut Vec<CheckResult>) -> Vec<CheckerOutput> { | ||
let mut health_checkers: Vec<CheckerOutput> = Vec::new(); | ||
|
||
for health_check_url in health_checks { | ||
match run_health_check(health_check_url.clone(), console).await { | ||
Ok(()) => check_results.push(Ok(())), | ||
Err(err) => check_results.push(Err(err)), | ||
let mut health_checker = CheckerOutput { | ||
url: health_check_url.to_string(), | ||
status: Status { | ||
code: String::new(), | ||
message: String::new(), | ||
}, | ||
}; | ||
match run_health_check(health_check_url.clone()).await { | ||
Ok(()) => { | ||
check_results.push(Ok(())); | ||
health_checker.status.code = "ok".to_string(); | ||
} | ||
Err(err) => { | ||
check_results.push(Err(err)); | ||
health_checker.status.code = "error".to_string(); | ||
health_checker.status.message = "Health API is failing.".to_string(); | ||
} | ||
} | ||
health_checkers.push(health_checker); | ||
} | ||
health_checkers | ||
} | ||
|
||
async fn run_health_check(url: Url, console: &Console) -> Result<(), CheckError> { | ||
async fn run_health_check(url: Url) -> Result<(), CheckError> { | ||
let client = HttpClient::builder().timeout(Duration::from_secs(5)).build().unwrap(); | ||
|
||
let colored_url = url.to_string().yellow(); | ||
|
||
match client.get(url.clone()).send().await { | ||
Ok(response) => { | ||
if response.status().is_success() { | ||
console.println(&format!("{} - Health API at {} is OK", "✓".green(), colored_url)); | ||
Ok(()) | ||
} else { | ||
console.eprintln(&format!( | ||
"{} - Health API at {} is failing: {:?}", | ||
"✗".red(), | ||
colored_url, | ||
response | ||
)); | ||
Err(CheckError::HealthCheckError { url }) | ||
} | ||
} | ||
Err(err) => { | ||
console.eprintln(&format!( | ||
"{} - Health API at {} is failing: {:?}", | ||
"✗".red(), | ||
colored_url, | ||
err | ||
)); | ||
Err(CheckError::HealthCheckError { url }) | ||
} | ||
Err(_) => Err(CheckError::HealthCheckError { url }), | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod health; | ||
pub mod http; | ||
pub mod structs; | ||
pub mod udp; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Status { | ||
pub code: String, | ||
pub message: String, | ||
} | ||
#[derive(Serialize, Deserialize)] | ||
pub struct CheckerOutput { | ||
pub url: String, | ||
pub status: Status, | ||
} |
This file contains 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
This file contains 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