Skip to content

Commit

Permalink
Clarify function naming
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Oct 10, 2023
1 parent 456444d commit 3bdb278
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/cli/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand All @@ -130,8 +130,8 @@ impl Admin {
) -> Response<Body> {
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)
Expand Down Expand Up @@ -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));
}
}
6 changes: 3 additions & 3 deletions src/cli/admin/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Health {
}

/// returns a HTTP 200 response if the proxy is healthy.
pub fn check_healthy(&self) -> Response<Body> {
pub fn check_liveness(&self) -> Response<Body> {
if self.healthy.load(Relaxed) {
return Response::new("ok".into());
};
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/cli/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/cli/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/cli/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 3bdb278

Please sign in to comment.