Skip to content

Commit

Permalink
Initial implementation logic for the health-check command (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
andynog committed Sep 10, 2021
1 parent 6ecd818 commit 263bc60
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
11 changes: 8 additions & 3 deletions relayer-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ use crate::DEFAULT_CONFIG_PATH;
use ibc_relayer::config::Config;

use self::{
config::ConfigCmd, create::CreateCmds, keys::KeysCmd, listen::ListenCmd,
misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd, update::UpdateCmds,
upgrade::UpgradeCmds, version::VersionCmd,
config::ConfigCmd, create::CreateCmds, health::HealthCheckCmd, keys::KeysCmd,
listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd,
update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd,
};

mod config;
mod create;
mod health;
mod keys;
mod listen;
mod misbehaviour;
Expand Down Expand Up @@ -89,6 +90,10 @@ pub enum CliCmd {
/// The `version` subcommand
#[options(help = "Display version information")]
Version(VersionCmd),

/// The `health` subcommand
#[options(help = "Performs a health check of all chains in the the config")]
HealthCheck(HealthCheckCmd),
}

/// This trait allows you to define how application configuration is loaded.
Expand Down
38 changes: 38 additions & 0 deletions relayer-cli/src/commands/health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::sync::Arc;

use abscissa_core::{Command, Options, Runnable};

use crate::conclude::Output;
use crate::prelude::*;
use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain};
use tokio::runtime::Runtime as TokioRuntime;

#[derive(Clone, Command, Debug, Options)]
pub struct HealthCheckCmd {}

impl Runnable for HealthCheckCmd {
fn run(&self) {
let config = (*app_config()).clone();

for ch in config.clone().chains {
let rt = Arc::new(TokioRuntime::new().unwrap());
info!("Performing health check on chain {:?}...", ch.id);
let chain_config = match config.find_chain(&ch.id) {
None => {
return Output::error(format!(
"chain '{}' not found in configuration file",
ch.id
))
.exit()
}
Some(chain_config) => chain_config,
};
let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap();
chain.health_checkup();
chain.validate_params();
info!("Performed health check on chain {:?}", ch.id);
}
info!("Hermes executed a health check for all chains in the config");
Output::success_msg("done").exit()
}
}
6 changes: 3 additions & 3 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl CosmosSdkChain {
/// Emits a log warning in case anything is amiss.
/// Exits early if any health check fails, without doing any
/// further checks.
fn health_checkup(&self) {
pub fn health_checkup(&self) {
async fn do_health_checkup(chain: &CosmosSdkChain) -> Result<(), Error> {
let chain_id = chain.id();
let grpc_address = chain.grpc_addr.to_string();
Expand Down Expand Up @@ -737,8 +737,8 @@ impl ChainEndpoint for CosmosSdkChain {
account: None,
};

chain.health_checkup();
chain.validate_params();
//chain.health_checkup();
//chain.validate_params();

Ok(chain)
}
Expand Down

0 comments on commit 263bc60

Please sign in to comment.