Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
858 changes: 829 additions & 29 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ thiserror = "1.0"
tracing = "0.1"
futures = "0.3"
async-trait = "0.1"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }

[dev-dependencies]
tokio-test = "0.4"
Expand Down
3 changes: 3 additions & 0 deletions client/crates/client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub enum ClientError {
#[error("RPC error: {0}")]
Rpc(#[from] tonic::Status),

#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),

#[error("Connection error: {0}")]
Connection(String),

Expand Down
55 changes: 39 additions & 16 deletions client/crates/client/src/health.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
use crate::{client::Client, error::Result};
use ev_types::v1::{health_service_client::HealthServiceClient, GetHealthResponse, HealthStatus};
use tonic::Request;

/// Health status of the node
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HealthStatus {
/// Node is operating normally
Pass,
/// Node is degraded but still serving
Warn,
/// Node has failed health checks
Fail,
/// Unknown health status
Unknown,
}

pub struct HealthClient {
inner: HealthServiceClient<tonic::transport::Channel>,
base_url: String,
http_client: reqwest::Client,
}

impl HealthClient {
/// Create a new HealthClient from a Client
pub fn new(client: &Client) -> Self {
let inner = HealthServiceClient::new(client.channel().clone());
Self { inner }
///
/// Note: The base_url should be the HTTP endpoint (e.g., "http://localhost:9090")
pub fn new(_client: &Client) -> Self {
// For now, we'll need to construct the base URL from the client
// This is a workaround since we're mixing gRPC and HTTP endpoints
// TODO: Consider adding a method to Client to get the base URL
Self::with_base_url("http://localhost:9090".to_string())
}

/// Create a new HealthClient with an explicit base URL
pub fn with_base_url(base_url: String) -> Self {
Self {
base_url: base_url.trim_end_matches('/').to_string(),
http_client: reqwest::Client::new(),
}
}

/// Check if the node is alive and get its health status
pub async fn livez(&self) -> Result<HealthStatus> {
let request = Request::new(());
let response = self.inner.clone().livez(request).await?;

Ok(response.into_inner().status())
}
let url = format!("{}/health/live", self.base_url);
let response = self.http_client.get(&url).send().await?;

/// Get the full health response
pub async fn get_health(&self) -> Result<GetHealthResponse> {
let request = Request::new(());
let response = self.inner.clone().livez(request).await?;
let status_text = response.text().await?.trim().to_string();

Ok(response.into_inner())
match status_text.as_str() {
"OK" => Ok(HealthStatus::Pass),
"WARN" => Ok(HealthStatus::Warn),
"FAIL" => Ok(HealthStatus::Fail),
_ => Ok(HealthStatus::Unknown),
}
}

/// Check if the node is healthy (status is PASS)
Expand Down
47 changes: 2 additions & 45 deletions client/crates/types/src/proto/evnode.v1.messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ pub struct State {
pub da_height: u64,
#[prost(bytes = "vec", tag = "8")]
pub app_hash: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes = "vec", tag = "9")]
pub last_header_hash: ::prost::alloc::vec::Vec<u8>,
}
/// GetPeerInfoResponse defines the response for retrieving peer information
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down Expand Up @@ -218,51 +220,6 @@ pub struct Batch {
#[prost(bytes = "vec", repeated, tag = "1")]
pub txs: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
/// GetHealthResponse defines the response for retrieving health status
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetHealthResponse {
/// Health status
#[prost(enumeration = "HealthStatus", tag = "1")]
pub status: i32,
}
/// HealthStatus defines the health status of the node
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum HealthStatus {
/// Unknown health status
Unknown = 0,
/// Healthy status (Healthy)
Pass = 1,
/// Degraded but still serving
Warn = 2,
/// Hard fail
Fail = 3,
}
impl HealthStatus {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
HealthStatus::Unknown => "UNKNOWN",
HealthStatus::Pass => "PASS",
HealthStatus::Warn => "WARN",
HealthStatus::Fail => "FAIL",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"PASS" => Some(Self::Pass),
"WARN" => Some(Self::Warn),
"FAIL" => Some(Self::Fail),
_ => None,
}
}
}
/// InitChainRequest contains the genesis parameters for chain initialization
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
Loading
Loading