Skip to content

Commit

Permalink
parameterize metrics port
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Nov 26, 2023
1 parent 1f95de3 commit d3e30b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 18 additions & 13 deletions rust/utils/run-locally/src/cosmos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub struct CosmosNetwork {
pub launch_resp: CosmosResp,
pub deployments: Deployments,
pub chain_id: String,
pub metrics: u32,
pub domain: u32,
}

Expand All @@ -182,17 +183,17 @@ impl Drop for CosmosNetwork {
}
}

impl From<(CosmosResp, Deployments, String, u32)> for CosmosNetwork {
fn from(v: (CosmosResp, Deployments, String, u32)) -> Self {
impl From<(CosmosResp, Deployments, String, u32, u32)> for CosmosNetwork {
fn from(v: (CosmosResp, Deployments, String, u32, u32)) -> Self {
Self {
launch_resp: v.0,
deployments: v.1,
chain_id: v.2,
domain: v.3,
metrics: v.3,
domain: v.4,
}
}
}

pub struct CosmosHyperlaneStack {
pub validators: Vec<AgentHandles>,
pub relayer: AgentHandles,
Expand Down Expand Up @@ -258,7 +259,7 @@ fn launch_cosmos_validator(
.hyp_env("ORIGINCHAINNAME", agent_config.name)
.hyp_env("REORGPERIOD", "100")
.hyp_env("DB", validator_base_db.to_str().unwrap())
.hyp_env("METRICSPORT", agent_config.domain_id.to_string())
.hyp_env("METRICSPORT", agent_config.metrics_port.to_string())
.hyp_env("VALIDATOR_SIGNER_TYPE", agent_config.signer.typ)
.hyp_env("VALIDATOR_KEY", agent_config.signer.key.clone())
.hyp_env("VALIDATOR_PREFIX", "osmo")
Expand All @@ -274,6 +275,7 @@ fn launch_cosmos_validator(
fn launch_cosmos_relayer(
agent_config_path: PathBuf,
relay_chains: Vec<String>,
metrics: u32,
debug: bool,
) -> AgentHandles {
let relayer_bin = concat_path(format!("../../{AGENT_BIN_PATH}"), "relayer");
Expand All @@ -290,7 +292,7 @@ fn launch_cosmos_relayer(
.hyp_env("ALLOWLOCALCHECKPOINTSYNCERS", "true")
.hyp_env("TRACING_LEVEL", if debug { "debug" } else { "info" })
.hyp_env("GASPAYMENTENFORCEMENT", "[{\"type\": \"none\"}]")
.hyp_env("METRICSPORT", 9093.to_string())
.hyp_env("METRICSPORT", metrics.to_string())
.spawn("RLY");

relayer
Expand Down Expand Up @@ -347,10 +349,10 @@ fn run_locally() {
};

let port_start = 26600u32;
let metrics_start = 9090u32;
let domain_start = 99990u32;
let node_count = 2;


let nodes = (0..node_count)
.map(|i| {
(
Expand All @@ -360,6 +362,7 @@ fn run_locally() {
..default_config.clone()
}),
format!("cosmos-test-{}", i + domain_start),
metrics_start + i,
domain_start + i,
)
})
Expand All @@ -372,8 +375,8 @@ fn run_locally() {

let nodes = nodes
.into_iter()
.map(|v| (v.0.join(), v.1, v.2))
.map(|(launch_resp, chain_id, domain)| {
.map(|v| (v.0.join(), v.1, v.2, v.3))
.map(|(launch_resp, chain_id, metrics, domain)| {
let deployments = deploy_cw_hyperlane(
launch_resp.cli(&osmosisd),
launch_resp.endpoint.clone(),
Expand All @@ -382,14 +385,14 @@ fn run_locally() {
domain,
);

(launch_resp, deployments, chain_id, domain)
(launch_resp, deployments, chain_id, metrics, domain)
})
.collect::<Vec<_>>();

// nodes with base deployments
let nodes = nodes
.into_iter()
.map(|v| (v.0, v.1.join(), v.2, v.3))
.map(|v| (v.0, v.1.join(), v.2, v.3, v.4))
.map(|v| v.into())
.collect::<Vec<CosmosNetwork>>();

Expand Down Expand Up @@ -449,9 +452,11 @@ fn run_locally() {
.into_values()
.map(|agent_config| launch_cosmos_validator(agent_config, agent_config_path.clone(), debug))
.collect::<Vec<_>>();
let hpl_rly_metrics = metrics_start + node_count + 1u32;
let hpl_rly = launch_cosmos_relayer(
agent_config_path,
agent_config_out.chains.into_keys().collect::<Vec<_>>(),
hpl_rly_metrics,
debug,
);

Expand Down Expand Up @@ -517,7 +522,7 @@ fn run_locally() {
let mut failure_occurred = false;
loop {
// look for the end condition.
if termination_invariants_met(dispatched_messages).unwrap_or(false) {
if termination_invariants_met(hpl_rly_metrics, dispatched_messages).unwrap_or(false) {
// end condition reached successfully
break;
} else if (Instant::now() - loop_start).as_secs() > TIMEOUT_SECS {
Expand All @@ -537,7 +542,7 @@ fn run_locally() {
}
}

fn termination_invariants_met(_messages_expected: u32) -> eyre::Result<bool> {
fn termination_invariants_met(_metrics: u32, _messages_expected: u32) -> eyre::Result<bool> {
Ok(true)
// TODO: uncomment once CI passes consistently on Ubuntu
// let gas_payments_scraped = fetch_metric(
Expand Down
2 changes: 2 additions & 0 deletions rust/utils/run-locally/src/cosmos/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub struct AgentUrl {
pub struct AgentConfig {
pub name: String,
pub domain_id: u32,
pub metrics_port: u32,
pub mailbox: String,
pub interchain_gas_paymaster: String,
pub validator_announce: String,
Expand Down Expand Up @@ -144,6 +145,7 @@ impl AgentConfig {
AgentConfig {
name: format!("cosmostest{}", network.domain),
domain_id: network.domain,
metrics_port: network.metrics,
mailbox: to_hex_addr(&network.deployments.mailbox),
interchain_gas_paymaster: to_hex_addr(&network.deployments.igp),
validator_announce: to_hex_addr(&network.deployments.va),
Expand Down

0 comments on commit d3e30b3

Please sign in to comment.