Skip to content

Commit

Permalink
feat: Add logging to agents (#5167)
Browse files Browse the repository at this point in the history
### Description

Add logging to agents
* When an agent start
* When cursor indexing task is exiting
* When cursor sync method is exiting

### Related issues

- Contributes into
#5098

### Backward compatibility

Yes

### Testing

E2E tests

---------

Co-authored-by: Danil Nemirovsky <[email protected]>
  • Loading branch information
ameten and ameten authored Jan 15, 2025
1 parent 28becff commit d781310
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 24 deletions.
12 changes: 6 additions & 6 deletions rust/main/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust/main/agents/relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ mod memory_profiler;

#[tokio::main(flavor = "multi_thread", worker_threads = 20)]
async fn main() -> Result<()> {
// Logging is not initialised at this point, so, using `println!`
println!("Relayer starting up...");

let agent_main_fut = agent_main::<Relayer>();

#[cfg(feature = "memory-profiling")]
Expand Down
28 changes: 14 additions & 14 deletions rust/main/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ impl Relayer {
return tokio::spawn(async {}).instrument(info_span!("MessageSync"));
}
};
let origin_name = origin.name().to_string();
tokio::spawn(TaskMonitor::instrument(&task_monitor, async move {
contract_sync
.clone()
.sync("dispatched_messages", cursor.into())
.await
let label = "dispatched_messages";
contract_sync.clone().sync(label, cursor.into()).await;
info!(chain = origin_name, label, "contract sync task exit");
}))
.instrument(info_span!("MessageSync"))
}
Expand All @@ -496,14 +496,14 @@ impl Relayer {
return tokio::spawn(async {}).instrument(info_span!("IgpSync"));
}
};
let origin_name = origin.name().to_string();
tokio::spawn(TaskMonitor::instrument(&task_monitor, async move {
let label = "gas_payments";
contract_sync
.clone()
.sync(
"gas_payments",
SyncOptions::new(Some(cursor), tx_id_receiver),
)
.await
.sync(label, SyncOptions::new(Some(cursor), tx_id_receiver))
.await;
info!(chain = origin_name, label, "contract sync task exit");
}))
.instrument(info_span!("IgpSync"))
}
Expand All @@ -526,14 +526,14 @@ impl Relayer {
return tokio::spawn(async {}).instrument(info_span!("MerkleTreeHookSync"));
}
};
let origin_name = origin.name().to_string();
tokio::spawn(TaskMonitor::instrument(&task_monitor, async move {
let label = "merkle_tree_hook";
contract_sync
.clone()
.sync(
"merkle_tree_hook",
SyncOptions::new(Some(cursor), tx_id_receiver),
)
.await
.sync(label, SyncOptions::new(Some(cursor), tx_id_receiver))
.await;
info!(chain = origin_name, label, "contract sync task exit");
}))
.instrument(info_span!("MerkleTreeHookSync"))
}
Expand Down
3 changes: 3 additions & 0 deletions rust/main/agents/scraper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ mod store;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
// Logging is not initialised at this point, so, using `println!`
println!("Scraper agent starting up...");

agent_main::<Scraper>().await
}
3 changes: 3 additions & 0 deletions rust/main/agents/validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ mod validator;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
// Logging is not initialised at this point, so, using `println!`
println!("Validator starting up...");

agent_main::<Validator>().await
}
8 changes: 4 additions & 4 deletions rust/main/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ impl Validator {
self.origin_chain
)
});
let origin = self.origin_chain.name().to_string();
tokio::spawn(async move {
contract_sync
.clone()
.sync("merkle_tree_hook", cursor.into())
.await;
let label = "merkle_tree_hook";
contract_sync.clone().sync(label, cursor.into()).await;
info!(chain = origin, label, "contract sync task exit");
})
.instrument(info_span!("MerkleTreeHookSyncer"))
}
Expand Down
3 changes: 3 additions & 0 deletions rust/main/hyperlane-base/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub async fn agent_main<A: BaseAgent>() -> Result<()> {
// the variable defaults to "VERGEN_IDEMPOTENT_OUTPUT".
let git_sha = env!("VERGEN_GIT_SHA").to_owned();

// Logging is not initialised at this point, so, using `println!`
println!("Agent {} starting up with version {git_sha}", A::AGENT_NAME);

let agent_metadata = AgentMetadata::new(git_sha);

let settings = A::Settings::load()?;
Expand Down
10 changes: 10 additions & 0 deletions rust/main/hyperlane-base/src/contract_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ where
self.fetch_logs_with_cursor(cursor, &stored_logs_metric, &indexed_height_metric)
.await;
}

// Added so that we confuse compiler that it is an infinite loop
if false {
break;
}
}

// Although the above loop should never end (unless by panicking),
// we put log here to make sure that we see when this method returns normally.
// Hopefully, compiler will not optimise this code out.
info!(chain = chain_name, label, "contract sync loop exit");
}

#[instrument(fields(domain=self.domain().name()), skip(self, recv, stored_logs_metric))]
Expand Down

0 comments on commit d781310

Please sign in to comment.