Skip to content

Commit

Permalink
chore(utils/probe): add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-melnychuk committed Nov 30, 2023
1 parent 3d26089 commit db177e0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
23 changes: 21 additions & 2 deletions utils/pathfinder-probe/Cargo.lock

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

2 changes: 1 addition & 1 deletion utils/pathfinder-probe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rust-version = "1.73"

[dependencies]
anyhow = "1.0.71"
axum = { workspace = true }
axum = { version = "0.6.19", features = ["macros"] }
futures = "0.3.28"
metrics = "0.21.1"
metrics-exporter-prometheus = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion utils/pathfinder-probe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Environment="RUST_LOG=info"
ExecStart=/var/lib/pathfinder/pathfinder-probe \
0.0.0.0:19999 \
https://alpha-mainnet.starknet.io \
http://127.0.0.1:9545 \
http://127.0.0.1:9545/rpc/v0.5 \
5
SyslogIdentifier=pathfinder-probe
Restart=always
Expand Down
23 changes: 20 additions & 3 deletions utils/pathfinder-probe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ async fn main() -> anyhow::Result<()> {
setup.poll_delay,
))
.for_each(|(gw, pf)| {
tracing::info!(
block = gw.block_number,
time = gw.block_timestamp,
"gateway"
);
tracing::info!(
block = pf.block_number,
time = pf.block_timestamp,
"pathfinder"
);

let blocks_missing = gw.block_number - pf.block_number;
metrics::gauge!("blocks_missing", blocks_missing as f64);

Expand Down Expand Up @@ -97,7 +108,13 @@ where
T: Clone + Debug + Default + 'a,
{
futures::stream::unfold(T::default(), move |old| async move {
let new = f(url).await.unwrap_or(old);
let new = match f(url).await {
Ok(new) => new,
Err(e) => {
tracing::error!(tag, "error: {e}");
old
}
};
tracing::debug!(%tag, ?new, "stream");
tokio::time::sleep(delay).await;
Some((new.clone(), new))
Expand Down Expand Up @@ -129,10 +146,10 @@ async fn get_gateway_latest(gateway_url: &Url) -> anyhow::Result<Head> {
})
}

// curl -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}' http://127.0.0.1:9000/rpc/v0.3
// curl -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}' http://127.0.0.1:9000/rpc/v0.5
async fn get_pathfinder_head(pathfinder_url: &Url) -> anyhow::Result<Head> {
let json: serde_json::Value = reqwest::ClientBuilder::new().build()?
.post(pathfinder_url.join("rpc/v0.3")?)
.post(pathfinder_url.to_owned())
.header("Content-type", "application/json")
.json(&serde_json::json!({"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}))
.timeout(REQUEST_TIMEOUT)
Expand Down

0 comments on commit db177e0

Please sign in to comment.