Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout to requests to nodes and add metric for iter cnts #883

Merged
merged 10 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chain-signatures/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use local_ip_address::local_ip;
use near_account_id::AccountId;
use near_crypto::{InMemorySigner, SecretKey};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{mpsc, RwLock};
use tracing_stackdriver::layer as stackdriver_layer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
Expand Down Expand Up @@ -135,6 +136,7 @@ fn is_running_on_gcp() -> bool {
let resp = reqwest::blocking::Client::new()
.get("http://metadata.google.internal/computeMetadata/v1/instance/id")
.header("Metadata-Flavor", "Google")
.timeout(Duration::from_secs(1))
.send();

match resp {
Expand Down
1 change: 1 addition & 0 deletions chain-signatures/node/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async fn send_encrypted<U: IntoUrl>(
.post(url.clone())
.header("content-type", "application/json")
.json(&message)
.timeout(Duration::from_secs(2))
.send()
.await
.map_err(SendError::ReqwestClientError)?;
Expand Down
16 changes: 14 additions & 2 deletions chain-signatures/node/src/mesh/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ impl Pool {
continue;
};

let Ok(resp) = self.http.get(url.clone()).send().await else {
let Ok(resp) = self
.http
.get(url.clone())
.timeout(Duration::from_secs(1))
.send()
.await
else {
tracing::warn!(
"Pool.ping resp err participant {:?} url {}",
participant,
Expand Down Expand Up @@ -93,7 +99,13 @@ impl Pool {
continue;
};

let Ok(resp) = self.http.get(url).send().await else {
let Ok(resp) = self
.http
.get(url)
.timeout(Duration::from_secs(1))
.send()
.await
else {
continue;
};

Expand Down
9 changes: 9 additions & 0 deletions chain-signatures/node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ pub(crate) static SIGNATURE_PUBLISH_RESPONSE_ERRORS: Lazy<CounterVec> = Lazy::ne
.unwrap()
});

pub(crate) static PROTOCOL_ITER_CNT: Lazy<CounterVec> = Lazy::new(|| {
try_create_counter_vec(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to measure latency or count iterations? Let's rename this accordingly and use counter if it's the later one.

"multichain_protocol_iter_count",
"Count of multichain protocol iter",
&["node_account_id"],
)
.unwrap()
});

pub fn try_create_int_gauge_vec(name: &str, help: &str, labels: &[&str]) -> Result<IntGaugeVec> {
check_metric_multichain_prefix(name)?;
let opts = Opts::new(name, help);
Expand Down
4 changes: 4 additions & 0 deletions chain-signatures/node/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ impl MpcSignProtocol {
loop {
let protocol_time = Instant::now();
tracing::debug!("trying to advance chain signatures protocol");
crate::metrics::PROTOCOL_ITER_CNT
.with_label_values(&[my_account_id.as_str()])
.inc();

loop {
let msg_result = self.receiver.try_recv();
match msg_result {
Expand Down
Loading