From 3bdb278ca33a7f68dae8393b0bc7a81b0d56ac97 Mon Sep 17 00:00:00 2001 From: Erin Power Date: Mon, 9 Oct 2023 10:33:07 +0200 Subject: [PATCH] Clarify function naming --- src/cli/admin.rs | 18 +++++++++--------- src/cli/admin/health.rs | 6 +++--- src/cli/agent.rs | 2 +- src/cli/manage.rs | 2 +- src/cli/proxy.rs | 2 +- src/cli/relay.rs | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cli/admin.rs b/src/cli/admin.rs index 96285402cf..1d743b93a4 100644 --- a/src/cli/admin.rs +++ b/src/cli/admin.rs @@ -113,12 +113,12 @@ impl Admin { tokio::spawn(HyperServer::bind(&address).serve(make_svc)) } - fn is_healthy(&self, config: &Config) -> bool { + fn is_ready(&self, config: &Config) -> bool { match &self { - Self::Proxy(proxy) => proxy.is_healthy(config), - Self::Agent(agent) => agent.is_healthy(), - Self::Manage(manage) => manage.is_healthy(), - Self::Relay(relay) => relay.is_healthy(), + Self::Proxy(proxy) => proxy.is_ready(config), + Self::Agent(agent) => agent.is_ready(), + Self::Manage(manage) => manage.is_ready(), + Self::Relay(relay) => relay.is_ready(), } } @@ -130,8 +130,8 @@ impl Admin { ) -> Response { match (request.method(), request.uri().path()) { (&Method::GET, "/metrics") => collect_metrics(), - (&Method::GET, "/live" | "/livez") => health.check_healthy(), - (&Method::GET, "/ready" | "/readyz") => check_readiness(|| self.is_healthy(&config)), + (&Method::GET, "/live" | "/livez") => health.check_liveness(), + (&Method::GET, "/ready" | "/readyz") => check_readiness(|| self.is_ready(&config)), (&Method::GET, "/config") => match serde_json::to_string(&config) { Ok(body) => Response::builder() .status(StatusCode::OK) @@ -207,13 +207,13 @@ mod tests { assert_eq!(config.clusters.read().endpoints().count(), 0); let admin = Admin::Proxy(<_>::default()); - assert!(!admin.is_healthy(&config)); + assert!(!admin.is_ready(&config)); config .clusters .write() .insert_default([Endpoint::new((std::net::Ipv4Addr::LOCALHOST, 25999).into())].into()); - assert!(admin.is_healthy(&config)); + assert!(admin.is_ready(&config)); } } diff --git a/src/cli/admin/health.rs b/src/cli/admin/health.rs index 20282c5273..a685ff8490 100644 --- a/src/cli/admin/health.rs +++ b/src/cli/admin/health.rs @@ -44,7 +44,7 @@ impl Health { } /// returns a HTTP 200 response if the proxy is healthy. - pub fn check_healthy(&self) -> Response { + pub fn check_liveness(&self) -> Response { if self.healthy.load(Relaxed) { return Response::new("ok".into()); }; @@ -65,14 +65,14 @@ mod tests { fn panic_hook() { let health = Health::new(); - let response = health.check_healthy(); + let response = health.check_liveness(); assert_eq!(response.status(), StatusCode::OK); let _ = std::panic::catch_unwind(|| { panic!("oh no!"); }); - let response = health.check_healthy(); + let response = health.check_liveness(); assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR); } } diff --git a/src/cli/agent.rs b/src/cli/agent.rs index ea75b31dc8..c66f1fd0df 100644 --- a/src/cli/agent.rs +++ b/src/cli/agent.rs @@ -125,7 +125,7 @@ pub struct RuntimeConfig { } impl RuntimeConfig { - pub fn is_healthy(&self) -> bool { + pub fn is_ready(&self) -> bool { self.provider_is_healthy.load(Ordering::SeqCst) && self.relay_is_healthy.load(Ordering::SeqCst) } diff --git a/src/cli/manage.rs b/src/cli/manage.rs index ebc1c60c1d..34e9f9703b 100644 --- a/src/cli/manage.rs +++ b/src/cli/manage.rs @@ -110,7 +110,7 @@ pub struct RuntimeConfig { } impl RuntimeConfig { - pub fn is_healthy(&self) -> bool { + pub fn is_ready(&self) -> bool { self.provider_is_healthy.load(Ordering::SeqCst) } } diff --git a/src/cli/proxy.rs b/src/cli/proxy.rs index c4cdca4498..4dfe702e8f 100644 --- a/src/cli/proxy.rs +++ b/src/cli/proxy.rs @@ -427,7 +427,7 @@ pub struct RuntimeConfig { } impl RuntimeConfig { - pub fn is_healthy(&self, config: &Config) -> bool { + pub fn is_ready(&self, config: &Config) -> bool { self.xds_is_healthy .read() .as_ref() diff --git a/src/cli/relay.rs b/src/cli/relay.rs index 72e1f020a0..e150b9bdb6 100644 --- a/src/cli/relay.rs +++ b/src/cli/relay.rs @@ -159,7 +159,7 @@ pub struct RuntimeConfig { } impl RuntimeConfig { - pub fn is_healthy(&self) -> bool { + pub fn is_ready(&self) -> bool { self.provider_is_healthy.load(Ordering::SeqCst) } }