From 7a367d0835618b63ff31281e1cc499f6e71166a2 Mon Sep 17 00:00:00 2001 From: Galileo Daras Date: Tue, 26 Nov 2024 18:11:50 -0300 Subject: [PATCH] feat(update-verifier): remove teleport from checks --- ...verifier.worldcoin-update-verifier.service | 1 - update-verifier/src/checks/mod.rs | 1 - update-verifier/src/checks/teleport.rs | 122 ------------------ update-verifier/src/lib.rs | 4 - 4 files changed, 128 deletions(-) delete mode 100644 update-verifier/src/checks/teleport.rs diff --git a/update-verifier/debian/orb-update-verifier.worldcoin-update-verifier.service b/update-verifier/debian/orb-update-verifier.worldcoin-update-verifier.service index c4ab0599..cb1df771 100644 --- a/update-verifier/debian/orb-update-verifier.worldcoin-update-verifier.service +++ b/update-verifier/debian/orb-update-verifier.worldcoin-update-verifier.service @@ -1,6 +1,5 @@ [Unit] Description=Worldcoin Update Verifier Service. -After=teleport.service StartLimitInterval=0 [Service] diff --git a/update-verifier/src/checks/mod.rs b/update-verifier/src/checks/mod.rs index 8fdcb0c3..45de5a44 100644 --- a/update-verifier/src/checks/mod.rs +++ b/update-verifier/src/checks/mod.rs @@ -1,7 +1,6 @@ //! A common health check module. pub mod mcu; -pub mod teleport; use tracing::{info, instrument}; diff --git a/update-verifier/src/checks/teleport.rs b/update-verifier/src/checks/teleport.rs deleted file mode 100644 index 57edbb85..00000000 --- a/update-verifier/src/checks/teleport.rs +++ /dev/null @@ -1,122 +0,0 @@ -/// Teleport general health metrics URL. -/// `/readyz` is similar but includes more information about the process state. -const TELEPORT_DEFAULT_METRICS_URL: &str = "http://127.0.0.1:3000/healthz"; - -/// Error definition for teleport health check. -#[derive(thiserror::Error, Debug)] -pub enum Error { - /// Teleport status query failed. - #[error("status query failed")] - StatusQuery(#[source] reqwest::Error), - /// Teleport server failure. - #[error("server failure")] - ServerFailure { - status_code: reqwest::StatusCode, - body: String, - }, -} - -pub struct Teleport { - metrics_url: String, -} - -impl Teleport { - /// Use Teleport default metrics URL. - #[must_use] - pub fn default() -> Self { - Self { - metrics_url: TELEPORT_DEFAULT_METRICS_URL.to_string(), - } - } - - /// Use a custom url for the metrics endpoint. - /// Only used for testing purposes. - #[cfg(test)] - #[must_use] - pub fn custom(url: String) -> Self { - Self { metrics_url: url } - } -} - -impl super::Check for Teleport { - type Error = Error; - const NAME: &'static str = "teleport"; - - /// The health check for teleport service. - /// - /// It checks the `TELEPORT_METRICS_URL` response and throws an error if the status code is anything other than OK. - /// Also throws an error if the request to the endpoint fails. - fn check(&self) -> Result<(), Self::Error> { - let response = reqwest::blocking::get(self.metrics_url.as_str()) - .map_err(Error::StatusQuery)?; - if !response.status().is_success() { - return Err(Error::ServerFailure { - status_code: response.status(), - body: response - .text() - .unwrap_or("could not parse response body".to_string()), - }); - } - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use httpmock::prelude::*; - use serde_json::{json, Value}; - - use crate::{ - checks::{teleport, Check}, - Teleport, - }; - // use super::super::run_check; - - // runs a local server which returns `status` and `body` and returns the server address url - fn run_server(status: u16, json_body: Value, path: &str) -> String { - let server = MockServer::start(); - server.mock(|when, then| { - when.path(path); - then.status(status) - .header("content-type", "application/json") - .json_body(json_body); - }); - server.url(path) - } - - #[test] - fn test_teleport_check_normal() { - let body = json!({ "status": "ok" }); - let url = run_server(200, body, "/test_normal"); - Teleport::custom(url).run_check().unwrap(); - } - - #[test] - fn test_teleport_check_server_error() { - let body = json!({ "status": "internal server error" }); - let url = run_server(503, body, "/test_error"); - match Teleport::custom(url).run_check() { - Ok(()) => panic!("expected error result but got Ok"), - Err(error) => match error { - teleport::Error::StatusQuery(_) => { - panic!("expected Error::ServerFailure but got Error::StatusQuery") - } - teleport::Error::ServerFailure { status_code, body } => { - assert_eq!(status_code, reqwest::StatusCode::SERVICE_UNAVAILABLE); - assert_eq!(body, body.to_string()); - } - }, - } - } - - #[test] - fn test_teleport_check_query_error() { - match Teleport::default().run_check() { - Ok(()) => panic!("expected error result but got Ok"), - Err(error) => assert!( - matches!(error, teleport::Error::StatusQuery(_)), - "got unexpected error variant {error}" - ), - } - } -} diff --git a/update-verifier/src/lib.rs b/update-verifier/src/lib.rs index 910da023..438ec465 100644 --- a/update-verifier/src/lib.rs +++ b/update-verifier/src/lib.rs @@ -2,7 +2,6 @@ #![warn(clippy::pedantic, missing_docs)] use crate::checks::mcu::{Error, Mcu}; -use crate::checks::teleport::Teleport; use crate::checks::Check; use orb_build_info::{make_build_info, BuildInfo}; use orb_slot_ctrl::OrbSlotCtrl; @@ -69,9 +68,6 @@ pub fn run_health_check(orb_slot_ctrl: OrbSlotCtrl) -> eyre::Result<()> { warn!("Could not get retry count or max retry count, skipping main MCU version check"); } - // check the teleport service health - Teleport::default().run_check()?; - info!("system health is OK"); info!("setting rootfs status to Normal");