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

fix: add missing prometheus timers to stacks_client #5188

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
44 changes: 22 additions & 22 deletions stacks-signer/src/client/stacks_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,16 @@ impl StacksClient {
chosen_parent: &ConsensusHash,
last_sortition: &ConsensusHash,
) -> Result<VecDeque<TenureForkingInfo>, ClientError> {
let path = self.tenure_forking_info_path(chosen_parent, last_sortition);
let timer = crate::monitoring::new_rpc_call_timer(&path, &self.http_origin);
let send_request = || {
self.stacks_node_client
.get(self.tenure_forking_info_path(chosen_parent, last_sortition))
.get(&path)
.send()
.map_err(backoff::Error::transient)
};
let response = retry_with_exponential_backoff(send_request)?;
timer.stop_and_record();
if !response.status().is_success() {
return Err(ClientError::RequestFailure(response.status()));
}
Expand All @@ -456,16 +459,16 @@ impl StacksClient {

/// Get the sortition information for the latest sortition
pub fn get_latest_sortition(&self) -> Result<SortitionInfo, ClientError> {
let path = self.sortition_info_path();
let timer = crate::monitoring::new_rpc_call_timer(&path, &self.http_origin);
let send_request = || {
self.stacks_node_client
.get(self.sortition_info_path())
.send()
.map_err(|e| {
warn!("Signer failed to request latest sortition"; "err" => ?e);
e
})
self.stacks_node_client.get(&path).send().map_err(|e| {
warn!("Signer failed to request latest sortition"; "err" => ?e);
e
})
};
let response = send_request()?;
timer.stop_and_record();
if !response.status().is_success() {
return Err(ClientError::RequestFailure(response.status()));
}
Expand All @@ -475,16 +478,16 @@ impl StacksClient {

/// Get the sortition information for a given sortition
pub fn get_sortition(&self, ch: &ConsensusHash) -> Result<SortitionInfo, ClientError> {
let path = format!("{}/consensus/{}", self.sortition_info_path(), ch.to_hex());
let timer = crate::monitoring::new_rpc_call_timer(&path, &self.http_origin);
let send_request = || {
self.stacks_node_client
.get(format!("{}/consensus/{}", self.sortition_info_path(), ch.to_hex()))
.send()
.map_err(|e| {
warn!("Signer failed to request sortition"; "consensus_hash" => %ch, "err" => ?e);
e
})
self.stacks_node_client.get(&path).send().map_err(|e| {
warn!("Signer failed to request sortition"; "consensus_hash" => %ch, "err" => ?e);
e
})
};
let response = send_request()?;
timer.stop_and_record();
if !response.status().is_success() {
return Err(ClientError::RequestFailure(response.status()));
}
Expand Down Expand Up @@ -582,7 +585,6 @@ impl StacksClient {
/// Retrieve the current pox data from the stacks node
pub fn get_pox_data(&self) -> Result<RPCPoxInfoData, ClientError> {
debug!("Getting pox data...");
#[cfg(feature = "monitoring_prom")]
let timer = crate::monitoring::new_rpc_call_timer(&self.pox_path(), &self.http_origin);
let send_request = || {
self.stacks_node_client
Expand All @@ -591,7 +593,6 @@ impl StacksClient {
.map_err(backoff::Error::transient)
};
let response = retry_with_exponential_backoff(send_request)?;
#[cfg(feature = "monitoring_prom")]
timer.stop_and_record();
if !response.status().is_success() {
return Err(ClientError::RequestFailure(response.status()));
Expand Down Expand Up @@ -706,13 +707,11 @@ impl StacksClient {
/// Returns `true` if the block was accepted or `false` if the block
/// was rejected.
pub fn post_block(&self, block: &NakamotoBlock) -> Result<bool, ClientError> {
let path = format!("{}{}?broadcast=1", self.http_origin, postblock_v3::PATH);
let timer = crate::monitoring::new_rpc_call_timer(&path, &self.http_origin);
let send_request = || {
self.stacks_node_client
.post(format!(
"{}{}?broadcast=1",
self.http_origin,
postblock_v3::PATH
))
.post(&path)
.header("Content-Type", "application/octet-stream")
.header(AUTHORIZATION, self.auth_password.clone())
.body(block.serialize_to_vec())
Expand All @@ -723,6 +722,7 @@ impl StacksClient {
})
};
let response = retry_with_exponential_backoff(send_request)?;
timer.stop_and_record();
if !response.status().is_success() {
return Err(ClientError::RequestFailure(response.status()));
}
Expand Down