Skip to content

Commit

Permalink
Add SetupObservability subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz committed Aug 1, 2024
1 parent cf47aea commit 5ae9986
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
33 changes: 7 additions & 26 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ use config::{
FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
SaveConfigWithBasePath,
},
ChainConfig, ContractsConfig, EcosystemConfig, GenesisConfig, ERA_OBSERBAVILITY_DIR,
ERA_OBSERBAVILITY_GIT_REPO,
ChainConfig, ContractsConfig, EcosystemConfig, GenesisConfig,
};
use types::{L1Network, ProverMode, WalletCreation};
use xshell::{cmd, Shell};

use super::args::init::{EcosystemArgsFinal, EcosystemInitArgs, EcosystemInitArgsFinal};
use super::{
args::init::{EcosystemArgsFinal, EcosystemInitArgs, EcosystemInitArgsFinal},
setup_observability,
};
use crate::{
accept_ownership::accept_owner,
commands::{
Expand All @@ -46,8 +48,7 @@ use crate::{
msg_ecosystem_initialized, msg_initializing_chain, MSG_CHAIN_NOT_INITIALIZED,
MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_DEPLOYING_ERC20,
MSG_DEPLOYING_ERC20_SPINNER, MSG_DISTRIBUTING_ETH_SPINNER,
MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR,
MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_ERA_OBSERVABILITY_ALREADY_SETUP,
MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT,
MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER,
},
utils::forge::{check_the_balance, fill_forge_private_key},
Expand All @@ -72,7 +73,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> {
logger::info(MSG_INITIALIZING_ECOSYSTEM);

if final_ecosystem_args.observability {
download_observability(shell)?;
setup_observability::run(shell)?;
}

let contracts_config = init(
Expand Down Expand Up @@ -386,23 +387,3 @@ fn build_system_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<
let _dir_guard = shell.push_dir(link_to_code.join("contracts"));
Ok(Cmd::new(cmd!(shell, "yarn sc build")).run()?)
}

/// Downloads Grafana dashboards from the era-observability repo
fn download_observability(shell: &Shell) -> anyhow::Result<()> {
let path_to_era_observability = shell.current_dir().join(ERA_OBSERBAVILITY_DIR);
if shell.path_exists(path_to_era_observability.clone()) {
logger::info(MSG_ERA_OBSERVABILITY_ALREADY_SETUP);
return Ok(());
}

let spinner = Spinner::new(MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER);
git::clone(
shell,
shell.current_dir(),
ERA_OBSERBAVILITY_GIT_REPO,
ERA_OBSERBAVILITY_DIR,
)?;
spinner.finish();

Ok(())
}
6 changes: 6 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod change_default;
mod create;
pub mod create_configs;
pub(crate) mod init;
mod setup_observability;

#[derive(Subcommand, Debug)]
#[allow(clippy::large_enum_variant)]
Expand All @@ -23,12 +24,17 @@ pub enum EcosystemCommands {
/// Change the default chain
#[command(alias = "cd")]
ChangeDefaultChain(ChangeDefaultChain),
/// Setup observability for the ecosystem,
/// downloading Grafana dashboards from the era-observability repo
#[command(alias = "obs")]
SetupObservability,
}

pub(crate) async fn run(shell: &Shell, args: EcosystemCommands) -> anyhow::Result<()> {
match args {
EcosystemCommands::Create(args) => create::run(args, shell),
EcosystemCommands::Init(args) => init::run(args, shell).await,
EcosystemCommands::ChangeDefaultChain(args) => change_default::run(args, shell),
EcosystemCommands::SetupObservability => setup_observability::run(shell),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use common::{git, logger, spinner::Spinner};
use config::{ERA_OBSERBAVILITY_DIR, ERA_OBSERBAVILITY_GIT_REPO};
use xshell::Shell;

use crate::messages::{
MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER, MSG_ERA_OBSERVABILITY_ALREADY_SETUP,
};

pub fn run(shell: &Shell) -> anyhow::Result<()> {
let path_to_era_observability = shell.current_dir().join(ERA_OBSERBAVILITY_DIR);
if shell.path_exists(path_to_era_observability.clone()) {
logger::info(MSG_ERA_OBSERVABILITY_ALREADY_SETUP);
return Ok(());
}

let spinner = Spinner::new(MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER);
git::clone(
shell,
shell.current_dir(),
ERA_OBSERBAVILITY_GIT_REPO,
ERA_OBSERBAVILITY_DIR,
)?;
spinner.finish();

Ok(())
}

0 comments on commit 5ae9986

Please sign in to comment.